Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 5de23c5e authored by Ben Weiss's avatar Ben Weiss
Browse files

Make ArcMotion material spec compliant

Upwards and downwards paths are
now curved in the same direction,
applying "gravity" to objects as they move around.

Test: CTS I40a5df051711fd719806cd88d87eeed68565d73d

Change-Id: I9e5323655dc7901393f90bb1ea2f393ca64b77ff
parent 7f6136ae
Loading
Loading
Loading
Loading
+60 −66
Original line number Diff line number Diff line
@@ -199,15 +199,9 @@ public class ArcMotion extends PathMotion {

        float ex;
        float ey;
        if (startY == endY) {
            ex = (startX + endX) / 2;
            ey = startY + mMinimumHorizontalTangent * Math.abs(endX - startX) / 2;
        } else if (startX == endX) {
            ex = startX + mMinimumVerticalTangent * Math.abs(endY - startY) / 2;
            ey = (startY + endY) / 2;
        } else {
        float deltaX = endX - startX;
        float deltaY = endY - startY;

        // hypotenuse squared.
        float h2 = deltaX * deltaX + deltaY * deltaY;

@@ -219,7 +213,8 @@ public class ArcMotion extends PathMotion {
        float midDist2 = h2 * 0.25f;

        float minimumArcDist2 = 0;
            boolean isQuadrant1Or3 = (deltaX * deltaY) > 0;

        boolean isMovingUpwards = startY > endY;

        if ((Math.abs(deltaX) < Math.abs(deltaY))) {
            // Similar triangles bfa and bde mean that (ab/fb = eb/bd)
@@ -227,26 +222,26 @@ public class ArcMotion extends PathMotion {
            // ab = hypotenuse
            // bd = hypotenuse/2
            // fb = deltaY
                float eDistY = h2 / (2 * deltaY);
                if (isQuadrant1Or3) {
            float eDistY = Math.abs(h2 / (2 * deltaY));
            if (isMovingUpwards) {
                ey = endY + eDistY;
                ex = endX;
            } else {
                ey = startY + eDistY;
                ex = startX;
                } else {
                    ey = endY - eDistY;
                    ex = endX;
            }

            minimumArcDist2 = midDist2 * mMinimumVerticalTangent
                    * mMinimumVerticalTangent;
        } else {
                // Same as above, but flip X & Y
            // Same as above, but flip X & Y and account for negative eDist
            float eDistX = h2 / (2 * deltaX);
                if (isQuadrant1Or3) {
                    ex = endX - eDistX;
                    ey = endY;
                } else {
            if (isMovingUpwards) {
                ex = startX + eDistX;
                ey = startY;
            } else {
                ex = endX - eDistX;
                ey = endY;
            }

            minimumArcDist2 = midDist2 * mMinimumHorizontalTangent
@@ -270,12 +265,11 @@ public class ArcMotion extends PathMotion {
            ex = dx + (ratio * (ex - dx));
            ey = dy + (ratio * (ey - dy));
        }
        }
        float controlX1 = (startX + ex) / 2;
        float controlY1 = (startY + ey) / 2;
        float controlX2 = (ex + endX) / 2;
        float controlY2 = (ey + endY) / 2;
        path.cubicTo(controlX1, controlY1, controlX2, controlY2, endX, endY);
        float control1X = (startX + ex) / 2;
        float control1Y = (startY + ey) / 2;
        float control2X = (ex + endX) / 2;
        float control2Y = (ey + endY) / 2;
        path.cubicTo(control1X, control1Y, control2X, control2Y, endX, endY);
        return path;
    }
}