Updated docs
diff --git a/lottie/src/main/java/com/airbnb/lottie/animation/content/RoundedCornersContent.java b/lottie/src/main/java/com/airbnb/lottie/animation/content/RoundedCornersContent.java
index 4656764..06a3bb1 100644
--- a/lottie/src/main/java/com/airbnb/lottie/animation/content/RoundedCornersContent.java
+++ b/lottie/src/main/java/com/airbnb/lottie/animation/content/RoundedCornersContent.java
@@ -17,7 +17,7 @@
public class RoundedCornersContent implements ShapeModifierContent, BaseKeyframeAnimation.AnimationListener {
/**
- * Copied fromL:
+ * Copied from:
* https://github.com/airbnb/lottie-web/blob/bb71072a26e03f1ca993da60915860f39aae890b/player/js/utils/common.js#L47
*/
private static final float ROUNDED_CORNER_MAGIC_NUMBER = 0.5519f;
@@ -87,6 +87,20 @@
int modifiedCurvesIndex = 0;
boolean isClosed = startingShapeData.isClosed();
+ // i represents which vertex we are currently on. Refer to the docs of CubicCurveData prior to working with
+ // this code.
+ // When i == 0
+ // vertex=ShapeData.initialPoint
+ // inCp=if closed vertex else curves[size - 1].cp2
+ // outCp=curves[0].cp1
+ // When i == 1
+ // vertex=curves[0].vertex
+ // inCp=curves[0].cp2
+ // outCp=curves[1].cp1.
+ // When i == size - 1
+ // vertex=curves[size - 1].vertex
+ // inCp=curves[size - 1].cp2
+ // outCp=if closed vertex else curves[0].cp1
for (int i = 0; i < startingCurves.size(); i++) {
CubicCurveData startingCurve = startingCurves.get(i);
CubicCurveData previousCurve = startingCurves.get(floorMod(i - 1, startingCurves.size()));
@@ -97,6 +111,7 @@
PointF previousVertex = previousPreviousCurve.getVertex();
PointF nextVertex = startingCurve.getVertex();
+ // We can't round the corner of the end of a non-closed curve.
boolean isEndOfCurve = !startingShapeData.isClosed() && (i == 0 && i == startingCurves.size() - 1);
if (inPoint.equals(vertex) && outPoint.equals(vertex) && !isEndOfCurve) {
// This vertex is a point. Round its corners
@@ -111,21 +126,12 @@
float previousVertexPercent = Math.min(roundedness / dToPreviousVertex, 0.5f);
float nextVertexPercent = Math.min(roundedness / dToNextVertex, 0.5f);
- // Move each vertex towards the previous/next vertex.
+ // Split the vertex into two and move each vertex towards the previous/next vertex.
float newVertex1X = vertex.x + (previousVertex.x - vertex.x) * previousVertexPercent;
float newVertex1Y = vertex.y + (previousVertex.y - vertex.y) * previousVertexPercent;
float newVertex2X = vertex.x + (nextVertex.x - vertex.x) * nextVertexPercent;
float newVertex2Y = vertex.y + (nextVertex.y - vertex.y) * nextVertexPercent;
- //noinspection UnnecessaryLocalVariable
- float newVertex1InPointX = newVertex1X;
- //noinspection UnnecessaryLocalVariable
- float newVertex1InPointY = newVertex1Y;
- //noinspection UnnecessaryLocalVariable
- float newVertex2OutPointX = newVertex2X;
- //noinspection UnnecessaryLocalVariable
- float newVertex2OutPointY = newVertex2Y;
-
// Extend the new vertex control point towards the original vertex.
float newVertex1OutPointX = newVertex1X - (newVertex1X - vertex.x) * ROUNDED_CORNER_MAGIC_NUMBER;
float newVertex1OutPointY = newVertex1Y - (newVertex1Y - vertex.y) * ROUNDED_CORNER_MAGIC_NUMBER;
@@ -136,7 +142,7 @@
// Refer to the docs for CubicCurveData for more info on the difference.
CubicCurveData previousCurveData = modifiedCurves.get(floorMod(modifiedCurvesIndex - 1, modifiedCurves.size()));
CubicCurveData currentCurveData = modifiedCurves.get(modifiedCurvesIndex);
- previousCurveData.setControlPoint2(newVertex1InPointX, newVertex1InPointY);
+ previousCurveData.setControlPoint2(newVertex1X, newVertex1Y);
previousCurveData.setVertex(newVertex1X, newVertex1Y);
if (i == 0) {
modifiedShapeData.setInitialPoint(newVertex1X, newVertex1Y);
@@ -148,10 +154,11 @@
currentCurveData = modifiedCurves.get(modifiedCurvesIndex);
previousCurveData.setControlPoint2(newVertex2InPointX, newVertex2InPointY);
previousCurveData.setVertex(newVertex2X, newVertex2Y);
- currentCurveData.setControlPoint1(newVertex2OutPointX, newVertex2OutPointY);
+ currentCurveData.setControlPoint1(newVertex2X, newVertex2Y);
modifiedCurvesIndex++;
} else {
- // This vertex is not a point. Don't modify it.
+ // This vertex is not a point. Don't modify it. Refer to the documentation above and for CubicCurveData for mapping a vertex
+ // oriented point to CubicCurveData (path segments).
CubicCurveData previousCurveData = modifiedCurves.get(floorMod(modifiedCurvesIndex - 1, modifiedCurves.size()));
CubicCurveData currentCurveData = modifiedCurves.get(modifiedCurvesIndex);
previousCurveData.setControlPoint2(previousCurve.getVertex().x, previousCurve.getVertex().y);