point getBezierPoint( span<const point> points, float t ) {
vector<point> tmp = as_vector(points);
while (tmp.size()>1) {
for (auto k:indexes_of(tmp).except_last())
tmp[k] = tmp[k] + t * ( tmp[k+1] - tmp[k] );
tmp.resize(tmp.size()-1);
}
return tmp[0];
}
span, as_vector and point should be obvious.
Here is indexes_of
:
template<class It>
struct range_t{
It b,e;
It begin()const{return b;}
It end()const{return e;}
range_t except_last(std::size_t i=1)const{
auto r = *this;
r.e-=i;
return r;
}
};
template<class It>
range_t<It> range(It be, It e){ return {std::move(b),std::move(e)}; }
template<class X>
struct indexer_t {
X x;
X operator*()const{return x;}
void operator++(){ ++x; }
void operator--(){ --x; }
void operator+=(std::ptrdiff_t i){ x+=i; }
void operator-=(std::ptrdiff_t i){ x-=i; }
friend bool operator==(indexer_t const&lhs, indexer_t const& rhs){return lhs.x==rhs.x;}
friend bool operator!=(indexer_t const&lhs, indexer_t const& rhs){return lhs.x!=rhs.x;}
};
range_t<indexer_t<std::size_t>> count( std::size_t start, std::size_t finish ){
return {{start}, {finish}};
}
template<class C>
auto indexes_of(C&&c) { return count(0, c.size()); }
or somesuch.
" kind of question (which is off topic), but I know it's not. If this were a link to code on a non-StackExchange site it would be downvoted and possibly closed.
– Steve Nov 09 '18 at 06:30