Logo Search packages:      
Sourcecode: inkscape version File versions

static void fit_and_split ( SPPencilContext pc  )  [static]

Todo:
fixme:

Definition at line 605 of file pencil-context.cpp.

References NArtBpath::c(), NArtBpath::code, SPEventContext::desktop, NR::is_zero(), SPPencilContext::npoints, NR_CURVETO, SPPencilContext::p, SPPencilContext::req_tangent, sp_bezier_fit_cubic_full(), sp_curve_append_continuous(), sp_curve_copy(), sp_curve_curveto(), sp_curve_empty(), sp_curve_last_bpath(), sp_curve_moveto(), sp_curve_reset(), sp_curve_unref(), NR::unit_vector(), and SPDesktop::w2d().

{
    g_assert( pc->npoints > 1 );

    double const tolerance_sq = square( NR::expansion(pc->desktop->w2d())
                                        * prefs_get_double_attribute_limited("tools.freehand.pencil",
                                                                             "tolerance", 10.0, 1.0, 100.0) );

    NR::Point b[4];
    g_assert(is_zero(pc->req_tangent)
             || is_unit_vector(pc->req_tangent));
    NR::Point const tHatEnd(0, 0);
    int const n_segs = sp_bezier_fit_cubic_full(b, NULL, pc->p, pc->npoints,
                                                pc->req_tangent, tHatEnd, tolerance_sq, 1);
    if ( n_segs > 0
         && unsigned(pc->npoints) < G_N_ELEMENTS(pc->p) )
    {
        /* Fit and draw and reset state */
        sp_curve_reset(pc->red_curve);
        sp_curve_moveto(pc->red_curve, b[0]);
        sp_curve_curveto(pc->red_curve, b[1], b[2], b[3]);
        sp_canvas_bpath_set_bpath(SP_CANVAS_BPATH(pc->red_bpath), pc->red_curve);
        pc->red_curve_is_valid = true;
    } else {
        /* Fit and draw and copy last point */

        g_assert(!sp_curve_empty(pc->red_curve));

        /* Set up direction of next curve. */
        {
            NArtBpath const &last_seg = *sp_curve_last_bpath(pc->red_curve);
            pc->p[0] = last_seg.c(3);
            pc->npoints = 1;
            g_assert( last_seg.code == NR_CURVETO );
            /* Relevance: validity of last_seg.c(2). */
            NR::Point const req_vec( pc->p[0] - last_seg.c(2) );
            pc->req_tangent = ( ( NR::is_zero(req_vec) || !in_svg_plane(req_vec) )
                                ? NR::Point(0, 0)
                                : NR::unit_vector(req_vec) );
        }

        sp_curve_append_continuous(pc->green_curve, pc->red_curve, 0.0625);
        SPCurve *curve = sp_curve_copy(pc->red_curve);

        /// \todo fixme:
        SPCanvasItem *cshape = sp_canvas_bpath_new(sp_desktop_sketch(pc->desktop), curve);
        sp_curve_unref(curve);
        sp_canvas_bpath_set_stroke(SP_CANVAS_BPATH(cshape), pc->green_color, 1.0, SP_STROKE_LINEJOIN_MITER, SP_STROKE_LINECAP_BUTT);

        pc->green_bpaths = g_slist_prepend(pc->green_bpaths, cshape);

        pc->red_curve_is_valid = false;
    }
}


Generated by  Doxygen 1.6.0   Back to index