362
362
Inkscape::SnappedPoint const s = m.freeSnap(Inkscape::SnapPreferences::SNAPPOINT_NODE, p);
363
363
if (s.getSnapped()) {
365
pc->pencil_has_snapped_before = true;
365
pc->prev_snap_was_succesful = true;
367
pc->prev_snap_was_succesful = false;
368
370
if ( pc->npoints != 0) { // buttonpress may have happened before we entered draw context!
369
if (!(pc->pencil_has_snapped_before && m.snapprefs.getSnapPostponedGlobally())) {
371
if (!(pc->prev_snap_was_succesful && m.snapprefs.getSnapPostponedGlobally())) {
370
372
// When snapping is enabled but temporarily on hold because the mouse is moving
371
373
// fast, then we don't want to add nodes off-grid
372
374
spdc_add_freehand_point(pc, from_2geom(p), mevent.state);
653
interpolate(SPPencilContext *pc)
656
g_assert( pc->ps.size() > 1 );
658
Inkscape::Preferences *prefs = Inkscape::Preferences::get();
659
double const tol = prefs->getDoubleLimited("/tools/freehand/pencil/tolerance", 10.0, 1.0, 100.0) * 0.4;
660
double const tolerance_sq = 0.02 * square( pc->desktop->w2d().descrim() *
661
tol) * exp(0.2*tol - 2);
663
g_assert(is_zero(pc->req_tangent)
664
|| is_unit_vector(pc->req_tangent));
665
Geom::Point const tHatEnd(0, 0);
667
guint n_points = pc->ps.size();
668
pc->green_curve->reset();
669
pc->red_curve->reset();
671
Geom::Point * b = g_new(Geom::Point, 4*n_points);
672
Geom::Point * points = g_new(Geom::Point, 4*n_points);
673
for (int i = 0; i < pc->ps.size(); i++) {
674
points[i] = pc->ps[i];
677
// worst case gives us a segment per point
678
int max_segs = 4*n_points;
680
int const n_segs = sp_bezier_fit_cubic_r(b, points, n_points,
681
tolerance_sq, max_segs);
685
/* Fit and draw and reset state */
686
pc->red_curve->reset();
687
pc->red_curve->moveto(b[0]);
688
for (int c = 0; c < n_segs; c++) {
689
pc->red_curve->curveto(b[4*c+1], b[4*c+2], b[4*c+3]);
691
sp_canvas_bpath_set_bpath(SP_CANVAS_BPATH(pc->red_bpath), pc->red_curve);
692
pc->red_curve_is_valid = true;
694
/* Fit and draw and copy last point */
695
g_assert(!pc->red_curve->is_empty());
697
/* Set up direction of next curve. */
699
Geom::CubicBezier const * last_seg = dynamic_cast<Geom::CubicBezier const *>(pc->red_curve->last_segment());
700
g_assert( last_seg ); // Relevance: validity of (*last_seg)[2]
701
pc->p[0] = last_seg->finalPoint();
703
Geom::Point const req_vec( pc->p[0] - (*last_seg)[2] );
704
pc->req_tangent = ( ( Geom::is_zero(req_vec) || !in_svg_plane(req_vec) )
706
: Geom::unit_vector(req_vec) );
709
pc->green_curve->append_continuous(pc->red_curve, 0.0625);
710
SPCurve *curve = pc->red_curve->copy();
713
SPCanvasItem *cshape = sp_canvas_bpath_new(sp_desktop_sketch(pc->desktop), curve);
715
sp_canvas_bpath_set_stroke(SP_CANVAS_BPATH(cshape), pc->green_color, 1.0, SP_STROKE_LINEJOIN_MITER, SP_STROKE_LINECAP_BUTT);
717
pc->green_bpaths = g_slist_prepend(pc->green_bpaths, cshape);
719
pc->red_curve_is_valid = false;
648
728
fit_and_split(SPPencilContext *pc)
650
730
g_assert( pc->npoints > 1 );
652
Inkscape::Preferences *prefs = Inkscape::Preferences::get();
653
double const tol = prefs->getDoubleLimited("/tools/freehand/pencil/tolerance", 10.0, 1.0, 100.0);
654
double const tolerance_sq = 0.02 * square( pc->desktop->w2d().descrim() * tol)
732
double const tolerance_sq = 0;
657
734
Geom::Point b[4];
658
735
g_assert(is_zero(pc->req_tangent)
659
736
|| is_unit_vector(pc->req_tangent));
660
737
Geom::Point const tHatEnd(0, 0);
661
738
int const n_segs = sp_bezier_fit_cubic_full(b, NULL, pc->p, pc->npoints,
662
pc->req_tangent, tHatEnd, tolerance_sq, 1);
739
pc->req_tangent, tHatEnd,
664
742
&& unsigned(pc->npoints) < G_N_ELEMENTS(pc->p) )