+
+void BezierRenderer::RenderBezierOnCPU(const Bezier & relative, const Rect & bounds, const View & view, const CPURenderTarget & target, const Colour & c)
+{
+ //const Rect & bounds = objects.bounds[i];
+ PixelBounds pix_bounds(CPURenderBounds(bounds,view,target));
+ //Bezier control(objects.beziers[objects.data_indices[i]].ToAbsolute(bounds),CPURenderBounds(Rect(0,0,1,1), view, target));
+ Bezier control(relative.ToAbsolute(bounds), Rect(0,0,target.w, target.h));
+
+ if (view.ShowingBezierBounds())
+ {
+ ObjectRenderer::RenderLineOnCPU(pix_bounds.x, pix_bounds.y, pix_bounds.x+pix_bounds.w, pix_bounds.y, target, Colour(255,0,0,0));
+ ObjectRenderer::RenderLineOnCPU(pix_bounds.x, pix_bounds.y+pix_bounds.h, pix_bounds.x+pix_bounds.w, pix_bounds.y+pix_bounds.h, target, Colour(0,255,0,0));
+ ObjectRenderer::RenderLineOnCPU(pix_bounds.x, pix_bounds.y, pix_bounds.x, pix_bounds.y+pix_bounds.h, target, Colour(255,0,0,0));
+ ObjectRenderer::RenderLineOnCPU(pix_bounds.x+pix_bounds.w, pix_bounds.y, pix_bounds.x+pix_bounds.w, pix_bounds.y+pix_bounds.h, target, Colour(0,255,0,0));
+ }
+
+ int64_t blen = min((int64_t)50,pix_bounds.w);//min(max(2U, (unsigned)Int64(Real(target.w)/view.GetBounds().w)),
+ //min((unsigned)(pix_bounds.w+pix_bounds.h)/4 + 1, 100U));
+
+ // DeCasteljau Divide the Bezier
+ #ifdef BEZIER_CPU_DECASTELJAU
+ queue<Bezier> divisions;
+ divisions.push(control);
+ while(divisions.size() < (uint64_t)(blen))
+ {
+ Bezier & current = divisions.front();
+ //if (current.GetType() == Bezier::LINE)
+ //{
+ // --blen;
+ // continue;
+ //}
+ divisions.push(current.DeCasteljauSubdivideRight(Real(1)/Real(2)));
+ divisions.push(current.DeCasteljauSubdivideLeft(Real(1)/Real(2)));
+ divisions.pop();
+ }
+ while (divisions.size() > 0)
+ {
+ Bezier & current = divisions.front();
+ RenderLineOnCPU(Int64(current.x0), Int64(current.y0), Int64(current.x3), Int64(current.y3), target, c);
+ divisions.pop();
+ }
+ #else
+ Real invblen(1); invblen /= Real(blen);
+
+ Real t(invblen);
+ Vec2 v0;
+ Vec2 v1;
+ control.Evaluate(v0.x, v0.y, 0);
+ for (int64_t j = 1; j <= blen; ++j)
+ {
+ control.Evaluate(v1.x, v1.y, t);
+ RenderLineOnCPU(v0.x, v0.y, v1.x, v1.y, target);
+ t += invblen;
+ v0 = v1;
+ }
+ #endif //BEZIER_CPU_DECASTELJAU
+}