+
+void BezierRenderer::RenderBezierOnCPU(unsigned i, Objects & objects, 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));
+
+ 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));
+ }
+
+ unsigned blen = 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
+ queue<Bezier> divisions;
+ divisions.push(control);
+ while(divisions.size() < 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();
+ }
+}