Logo Search packages:      
Sourcecode: inkscape version File versions

static double compute_hook ( NR::Point const &  a,
NR::Point const &  b,
double const   u,
BezierCurve const   bezCurve,
double const   tolerance 
) [static]

Whereas compute_max_error_ratio checks for itself that each data point is near some point on the curve, compute_hook checks that each point on the curve is near some data point (or near some point on the polyline defined by the data points, or something like that: we allow for a "reasonable curviness" from such a polyline). "Reasonable curviness" means we draw a circle centred at the midpoint of a..b, of radius proportional to the length |a - b|, and require that each point on the segment of bezCurve between the parameters of a and b be within that circle. If any point P on the bezCurve segment is outside of that allowable region (circle), then we return some metric that increases with the distance from P to the circle.

Given that this is a fairly arbitrary criterion for finding appropriate places for sharp corners, we test only one point on bezCurve, namely the point on bezCurve with parameter half way between our estimated parameters for a and b. (Alternatives are taking the farthest of a few parameters between those of a and b, or even using a variant of NewtonRaphsonFindRoot for finding the maximum rather than minimum distance.)

Definition at line 919 of file bezier-utils.cpp.

References bezier_pt(), and NR::L2().

Referenced by compute_max_error_ratio().

    NR::Point const P = bezier_pt(3, bezCurve, u);
    NR::Point const diff = .5 * (a + b) - P;
    double const dist = NR::L2(diff);
    if (dist < tolerance) {
        return 0;
    double const allowed = NR::L2(b - a) + tolerance;
    return dist / allowed;
    /* effic: Hooks are very rare.  We could start by comparing distsq, only resorting to the more
       expensive L2 in cases of uncertainty. */

Generated by  Doxygen 1.6.0   Back to index