Logo Search packages:      
Sourcecode: qt4-x11 version File versions

qreal QPainterPath::slopeAtPercent ( qreal  t  )  const

Returns the slope of the path at the percentage t. The argument t has to be between 0 and 1.

Note that similarly to other percent methods, the percentage measurment is not linear with regards to the length, if curves are present in the path. When curves are present the percentage argument is mapped to the t parameter of the Bezier equations.

Definition at line 2784 of file qpainterpath.cpp.

References length().

{
    if (t < 0 || t > 1) {
        qWarning("QPainterPath::slopeAtPercent accepts only values between 0 and 1");
        return 0;
    }

    qreal totalLength = length();
    qreal curLen = 0;
    qreal bezierLen = 0;
    QBezier bez = bezierAtT(*this, t, &curLen, &bezierLen);
    qreal realT = (totalLength * t - curLen) / bezierLen;

    qreal m1 = slopeAt(realT, bez.x1, bez.x2, bez.x3, bez.x4);
    qreal m2 = slopeAt(realT, bez.y1, bez.y2, bez.y3, bez.y4);
    //tangent line
    qreal slope = 0;

#define SIGN(x) ((x < 0)?-1:1)
    if (m1)
        slope = m2/m1;
    else {
        //windows doesn't define INFINITY :(
#ifdef INFINITY
        slope = INFINITY*SIGN(m2);
#else
        if (sizeof(qreal) == sizeof(double)) {
            return 1.79769313486231570e+308;
        } else {
            return ((qreal)3.40282346638528860e+38);
        }
#endif
    }

    return slope;
}


Generated by  Doxygen 1.6.0   Back to index