Bug 1167026 - Avoid division by zero when flattening a bezier curve segment with equal control points. r=bas

This commit is contained in:
Lee Salzman 2015-06-02 10:47:15 -04:00
parent b61d9f116d
commit b3bd817c7e

View File

@ -250,12 +250,19 @@ FlattenBezierCurveSegment(const BezierControlPoints &aControlPoints,
Point cp21 = currentCP.mCP2 - currentCP.mCP3;
Point cp31 = currentCP.mCP3 - currentCP.mCP1;
Float s3 = (cp31.x * cp21.y - cp31.y * cp21.x) / hypotf(cp21.x, cp21.y);
t = 2 * Float(sqrt(aTolerance / (3. * std::abs(s3))));
/* To remove divisions and check for divide-by-zero, this is optimized from:
* Float s3 = (cp31.x * cp21.y - cp31.y * cp21.x) / hypotf(cp21.x, cp21.y);
* t = 2 * Float(sqrt(aTolerance / (3. * std::abs(s3))));
*/
Float cp21x31 = cp31.x * cp21.y - cp31.y * cp21.x;
Float h = hypotf(cp21.x, cp21.y);
if (cp21x31 * h == 0) {
break;
}
Float s3inv = h / cp21x31;
t = 2 * Float(sqrt(aTolerance * std::abs(s3inv) / 3.));
if (t >= 1.0f) {
aSink->LineTo(aControlPoints.mCP4);
break;
}
@ -264,6 +271,8 @@ FlattenBezierCurveSegment(const BezierControlPoints &aControlPoints,
aSink->LineTo(currentCP.mCP1);
}
aSink->LineTo(currentCP.mCP4);
}
static inline void