compactImplicitPoints method
void
compactImplicitPoints()
Compacts implicit points of quadratic curves (midpoints and end points)
Implementation
void compactImplicitPoints() {
if (!hasQuadCurves) {
throw UnsupportedError('Only quadratic curves supported');
}
if (hasCompactCurves) {
return;
}
// Starting with 2, because first point can't be a CP and we need 2 of them
for (var i = 2; i < pointList.length; i++) {
// Two control points in a row
if (!isOnCurveList[i - 1] &&
i + 1 < pointList.length &&
!isOnCurveList[i + 1]) {
final c0 = pointList[i - 1];
final p0 = pointList[i];
final c1 = pointList[i + 1];
// Calculating midpoint
final midpoint = (c0 + c1) * .5;
// Point on curve equals calculated midpoint
if (midpoint.toIntPoint() == p0.toIntPoint()) {
pointList.removeAt(i);
isOnCurveList.removeAt(i);
}
}
}
// Last point and end point are same
if (pointList.length > 1 &&
pointList.first.toIntPoint() == pointList.last.toIntPoint()) {
pointList.removeLast();
isOnCurveList.removeLast();
}
_hasCompactCurves = true;
}