Use a safer way of avoiding artifacts
#275
diff --git a/lottie/src/main/java/com/airbnb/lottie/MiscUtils.java b/lottie/src/main/java/com/airbnb/lottie/MiscUtils.java
index 760cfc6..6fa5672 100644
--- a/lottie/src/main/java/com/airbnb/lottie/MiscUtils.java
+++ b/lottie/src/main/java/com/airbnb/lottie/MiscUtils.java
@@ -15,9 +15,21 @@
outPath.moveTo(initialPoint.x, initialPoint.y);
for (int i = 0; i < shapeData.getCurves().size(); i++) {
CubicCurveData curveData = shapeData.getCurves().get(i);
- outPath.cubicTo(curveData.getControlPoint1().x, curveData.getControlPoint1().y,
- curveData.getControlPoint2().x, curveData.getControlPoint2().y,
- curveData.getVertex().x, curveData.getVertex().y);
+ PointF cp1 = curveData.getControlPoint1();
+ PointF cp2 = curveData.getControlPoint2();
+ PointF vertex = curveData.getVertex();
+
+ if (cp2.equals(vertex)) {
+ // On some phones like Samsung phones, zero valued control points can cause artifacting.
+ // https://github.com/airbnb/lottie-android/issues/275
+ //
+ // This does its best to add a tiny value to the vertex without affecting the final
+ // animation as much as possible.
+ outPath.cubicTo(cp1.x, cp1.y, cp2.x, cp2.y, vertex.x + 0.01f, vertex.y + 0.01f);
+ } else {
+ outPath.cubicTo(cp1.x, cp1.y, cp2.x, cp2.y, vertex.x, vertex.y);
+ }
+
}
if (shapeData.isClosed()) {
outPath.close();
diff --git a/lottie/src/main/java/com/airbnb/lottie/ShapeData.java b/lottie/src/main/java/com/airbnb/lottie/ShapeData.java
index fe33f51..c3a6429 100644
--- a/lottie/src/main/java/com/airbnb/lottie/ShapeData.java
+++ b/lottie/src/main/java/com/airbnb/lottie/ShapeData.java
@@ -145,8 +145,6 @@
PointF previousVertex = vertexAtIndex(i - 1, pointsArray);
PointF cp1 = vertexAtIndex(i - 1, outTangents);
PointF cp2 = vertexAtIndex(i, inTangents);
- ensureNonZeroControlPoint(previousVertex, vertex, cp1);
- ensureNonZeroControlPoint(previousVertex, vertex, cp2);
PointF shapeCp1 = MiscUtils.addPoints(previousVertex, cp1);
PointF shapeCp2 = MiscUtils.addPoints(vertex, cp2);
@@ -183,23 +181,6 @@
return new ShapeData(initialPoint, closed, curves);
}
- /**
- * On some phones like Samsung phones, zero valued control points can cause artifacting.
- * https://github.com/airbnb/lottie-android/issues/275
- *
- * This does its best to add a tiny value to the control point without affecting the final
- * animation as much as possible.
- */
- private void ensureNonZeroControlPoint(PointF previousVertex, PointF vertex, PointF cp) {
- if (!cp.equals(0f, 0f)) {
- return;
- }
- float dx = vertex.x - previousVertex.x;
- float dy = vertex.y - previousVertex.y;
- float length = (float) Math.sqrt(dx * dx + dy * dy);
- cp.set(dx / length * 0.001f, dy / length * 0.001f);
- }
-
private static PointF vertexAtIndex(int idx, JSONArray points) {
if (idx >= points.length()) {
throw new IllegalArgumentException(