QPolygonF bezier_fit_cubic_single( const QPolygonF& data, double error ) { QPolygonF out(4); const int retn = sp_bezier_fit_cubic(out.data(), data.data(), data.count(), error); if( retn >= 0 ) return out; else return QPolygonF(); }
static void fit_and_split (SPDrawContext * dc) { NRPointF b[4]; gdouble tolerance; g_assert (dc->npoints > 1); tolerance = SP_EVENT_CONTEXT (dc)->desktop->w2d[0] * TOLERANCE; tolerance = tolerance * tolerance; if (sp_bezier_fit_cubic (b, dc->p, dc->npoints, tolerance) > 0 && dc->npoints < SP_DRAW_POINTS_MAX) { /* Fit and draw and reset state */ sp_curve_reset (dc->red_curve); sp_curve_moveto (dc->red_curve, b[0].x, b[0].y); sp_curve_curveto (dc->red_curve, b[1].x, b[1].y, b[2].x, b[2].y, b[3].x, b[3].y); sp_canvas_bpath_set_bpath (SP_CANVAS_BPATH (dc->red_bpath), dc->red_curve); } else { SPCurve *curve; SPCanvasItem *cshape; /* Fit and draw and copy last point */ g_assert (!sp_curve_empty (dc->red_curve)); sp_curve_append_continuous (dc->green_curve, dc->red_curve, 0.0625); curve = sp_curve_copy (dc->red_curve); /* fixme: */ cshape = sp_canvas_bpath_new (SP_DT_SKETCH (SP_EVENT_CONTEXT (dc)->desktop), curve); sp_curve_unref (curve); sp_canvas_bpath_set_stroke (SP_CANVAS_BPATH (cshape), dc->green_color, 1.0, SP_STROKE_LINEJOIN_MITER, SP_STROKE_LINECAP_BUTT); dc->green_bpaths = g_slist_prepend (dc->green_bpaths, cshape); dc->p[0] = dc->p[dc->npoints - 2]; dc->p[1] = dc->p[dc->npoints - 1]; dc->npoints = 2; } }