From: johanengelen Date: Mon, 7 Jul 2008 13:44:03 +0000 (+0000) Subject: remove dead code X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=b0552f63c579059654f73a81f10b9e945af06b04;p=inkscape.git remove dead code --- diff --git a/src/sp-shape.cpp b/src/sp-shape.cpp index 39c1f87a4..e38dba48f 100644 --- a/src/sp-shape.cpp +++ b/src/sp-shape.cpp @@ -315,273 +315,6 @@ sp_shape_update (SPObject *object, SPCtx *ctx, unsigned int flags) } } - -/** -* Works out whether a marker of a given type is required at a particular -* point on a shape. -* -* \param shape Shape of interest. -* \param m Marker type (e.g. SP_MARKER_LOC_START) -* \param bp Path segment. -* \return 1 if a marker is required here, otherwise 0. -*/ -bool -sp_shape_marker_required(SPShape const *shape, int const m, NArtBpath const *bp) -{ - if (shape->marker[m] == NULL) { - return false; - } - - if (bp == SP_CURVE_BPATH(shape->curve)) - return m == SP_MARKER_LOC_START; - else if (bp[1].code == NR_END) - return m == SP_MARKER_LOC_END; - else - return m == SP_MARKER_LOC_MID; -} - -static bool -is_moveto(NRPathcode const c) -{ - return c == NR_MOVETO || c == NR_MOVETO_OPEN; -} - -/** - * Helper function that advances a subpath's bpath to the first subpath - * by checking for moveto segments. - * - * \pre The bpath[] containing bp begins with a moveto. - */ -static NArtBpath const * -first_seg_in_subpath(NArtBpath const *bp) -{ - while (!is_moveto(bp->code)) { - --bp; - } - return bp; -} - -/** - * Advances the bpath to the last segment in the subpath. - */ -static NArtBpath const * -last_seg_in_subpath(NArtBpath const *bp) -{ - for(;;) { - ++bp; - switch (bp->code) { - case NR_MOVETO: - case NR_MOVETO_OPEN: - case NR_END: - --bp; - return bp; - - default: continue; - } - } -} - - -/* A subpath begins with a moveto and ends immediately before the next moveto or NR_END. - * (`moveto' here means either NR_MOVETO or NR_MOVETO_OPEN.) I'm assuming that non-empty - * paths always begin with a moveto. - * - * The control points of the subpath are the control points of the path elements of the subpath. - * - * As usual, the control points of a moveto or NR_LINETO are {c(3)}, and - * the control points of a NR_CURVETO are {c(1), c(2), c(3)}. - * (It follows from the definition that NR_END isn't part of a subpath.) - * - * The initial control point is bpath[bi0].c(3). - * - * Reference: http://www.w3.org/TR/SVG11/painting.html#MarkerElement, the `orient' attribute. - * Reference for behaviour of zero-length segments: - * http://www.w3.org/TR/SVG11/implnote.html#PathElementImplementationNotes - */ - -static double const no_tangent = 128.0; /* arbitrarily-chosen value outside the range of atan2, - * i.e. outside of [-pi, pi]. This value is incremented by - * 1 and checked using > to be safe from floating-point - * equality comparison madness.*/ - -/** - * Helper function to calculate the outgoing tangent of a path - * ( atan2(other - p0) ) - * \pre The bpath[] containing bp0 begins with a moveto. - */ -static double -outgoing_tangent(NArtBpath const *bp0) -{ - /* See notes in comment block above. */ - - g_assert(bp0->code != NR_END); - NR::Point const &p0 = bp0->c(3); - NR::Point other; - for (NArtBpath const *bp = bp0;;) { - ++bp; - switch (bp->code) { - case NR_LINETO: - other = bp->c(3); - if (other != p0) { - goto found; - } - break; - - case NR_CURVETO: - for (unsigned ci = 1; ci <= 3; ++ci) { - other = bp->c(ci); - if (other != p0) { - goto found; - } - } - break; - - case NR_MOVETO_OPEN: - case NR_END: - case NR_MOVETO: - bp = first_seg_in_subpath(bp0); - if (bp == bp0) { - /* Gone right around the subpath without finding any different point since the - * initial moveto. */ - return no_tangent + 1; - } - if (bp->code != NR_MOVETO) { - /* Open subpath. */ - return no_tangent + 1; - } - other = bp->c(3); - if (other != p0) { - goto found; - } - break; - } - - if (bp == bp0) { - /* Back where we started, so zero-length subpath. */ - return no_tangent + 1; - - /* Note: this test must come after we've looked at element bp, in case bp0 is a curve: - * we must look at c(1) and c(2). (E.g. single-curve subpath.) - */ - } - } - -found: - return atan2( other - p0 ); -} - -/** - * Helper function to calculate the incoming tangent of a path - * ( atan2(p0 - other) ) - * - * \pre The bpath[] containing bp0 begins with a moveto. - */ -static double -incoming_tangent(NArtBpath const *bp0) -{ - /* See notes in comment block before outgoing_tangent. */ - - g_assert(bp0->code != NR_END); - NR::Point const &p0 = bp0->c(3); - NR::Point other; - for (NArtBpath const *bp = bp0;;) { - switch (bp->code) { - case NR_LINETO: - other = bp->c(3); - if (other != p0) { - goto found; - } - --bp; - break; - - case NR_CURVETO: - for (unsigned ci = 3; ci != 0; --ci) { - other = bp->c(ci); - if (other != p0) { - goto found; - } - } - --bp; - break; - - case NR_MOVETO: - case NR_MOVETO_OPEN: - other = bp->c(3); - if (other != p0) { - goto found; - } - if (bp->code != NR_MOVETO) { - /* Open subpath. */ - return no_tangent + 1; - } - bp = last_seg_in_subpath(bp0); - break; - - default: /* includes NR_END */ - g_error("Found invalid path code %u in middle of path.", bp->code); - return no_tangent + 1; - } - - if (bp == bp0) { - /* Back where we started from: zero-length subpath. */ - return no_tangent + 1; - } - } - -found: - return atan2( p0 - other ); -} - - -/** - * Calculate the transform required to get a marker's path object in the - * right place for particular path segment on a shape. You should - * call sp_shape_marker_required first to see if a marker is required - * at this point. - * - * \see sp_shape_marker_required. - * - * \param shape Shape which the marker is for. - * \param m Marker type (e.g. SP_MARKER_LOC_START) - * \param bp Path segment which the arrow is for. - * \return Transform matrix. - */ -NR::Matrix -sp_shape_marker_get_transform(SPShape const *shape, NArtBpath const *bp) -{ - g_return_val_if_fail(( is_moveto(SP_CURVE_BPATH(shape->curve)[0].code) - && ( 0 < shape->curve->get_length() ) - && ( SP_CURVE_BPATH(shape->curve)[shape->curve->get_length()].code == NR_END ) ), - NR::Matrix(NR::translate(bp->c(3)))); - double const angle1 = incoming_tangent(bp); - double const angle2 = outgoing_tangent(bp); - - double ret_angle; - if (angle1 > no_tangent) { - /* First vertex of an open subpath. */ - ret_angle = ( angle2 > no_tangent - ? 0. - : angle2 ); - } else if (angle2 > no_tangent) { - /* Last vertex of an open subpath. */ - ret_angle = angle1; - } else { - ret_angle = .5 * (angle1 + angle2); - - if ( fabs( angle2 - angle1 ) > M_PI ) { - /* ret_angle is in the middle of the larger of the two sectors between angle1 and - * angle2, so flip it by 180degrees to force it to the middle of the smaller sector. - * - * (Imagine a circle with rays drawn at angle1 and angle2 from the centre of the - * circle. Those two rays divide the circle into two sectors.) - */ - ret_angle += M_PI; - } - } - - return NR::Matrix(NR::rotate(ret_angle)) * NR::translate(bp->c(3)); -} - /** * Calculate the transform required to get a marker's path object in the * right place for particular path segment on a shape. @@ -593,6 +326,10 @@ sp_shape_marker_get_transform(SPShape const *shape, NArtBpath const *bp) * element and the slope of the curve at the given vertex. (Note: if there is a discontinuity at a vertex, the slope * is the average of the slopes of the two segments of the curve that join at the given vertex. If a slope cannot be * determined, the slope is assumed to be zero.) + * + * Reference: http://www.w3.org/TR/SVG11/painting.html#MarkerElement, the `orient' attribute. + * Reference for behaviour of zero-length segments: + * http://www.w3.org/TR/SVG11/implnote.html#PathElementImplementationNotes */ Geom::Matrix sp_shape_marker_get_transform(Geom::Curve const & c1, Geom::Curve const & c2) diff --git a/src/sp-shape.h b/src/sp-shape.h index aa78fcc33..4b1ded236 100644 --- a/src/sp-shape.h +++ b/src/sp-shape.h @@ -63,8 +63,6 @@ void sp_shape_set_curve_insync (SPShape *shape, SPCurve *curve, unsigned int own void sp_shape_set_marker (SPObject *object, unsigned int key, const gchar *value); int sp_shape_has_markers (SPShape const *shape); int sp_shape_number_of_markers (SPShape* Shape, int type); -NR::Matrix sp_shape_marker_get_transform(SPShape const *shape, NArtBpath const *bp); -bool sp_shape_marker_required(SPShape const *shape, int const m, NArtBpath const *bp); Geom::Matrix sp_shape_marker_get_transform(Geom::Curve const & c1, Geom::Curve const & c2); Geom::Matrix sp_shape_marker_get_transform_at_start(Geom::Curve const & c);