diff options
author | Matsuda, Akihit <matsuda104@gmail.com> | 2019-12-01 03:55:44 +0900 |
---|---|---|
committer | Gabriel Peal <gpeal@users.noreply.github.com> | 2019-11-30 10:55:44 -0800 |
commit | c302150c8ccb52595a6c3bf68a9d3068af766a19 (patch) | |
tree | ddb7d59a90b7e7eea8a9dde0a337d2e8cc08720a | |
parent | a27c48bcec35dab7619673905fa578f957e325d3 (diff) | |
download | lottie-c302150c8ccb52595a6c3bf68a9d3068af766a19.tar.gz |
Solved TODO of Utils.getScale() (#1446)
-rw-r--r-- | lottie/src/main/java/com/airbnb/lottie/utils/Utils.java | 16 |
1 files changed, 5 insertions, 11 deletions
diff --git a/lottie/src/main/java/com/airbnb/lottie/utils/Utils.java b/lottie/src/main/java/com/airbnb/lottie/utils/Utils.java index 6f300f94..0ad4b89b 100644 --- a/lottie/src/main/java/com/airbnb/lottie/utils/Utils.java +++ b/lottie/src/main/java/com/airbnb/lottie/utils/Utils.java @@ -23,13 +23,8 @@ import com.airbnb.lottie.animation.keyframe.FloatKeyframeAnimation; import java.io.Closeable; import java.io.InterruptedIOException; -import java.net.BindException; -import java.net.ConnectException; -import java.net.NoRouteToHostException; -import java.net.PortUnreachableException; import java.net.ProtocolException; import java.net.SocketException; -import java.net.SocketTimeoutException; import java.net.UnknownHostException; import java.net.UnknownServiceException; import java.nio.channels.ClosedChannelException; @@ -43,7 +38,7 @@ public final class Utils { private static final Path tempPath = new Path(); private static final Path tempPath2 = new Path(); private static final float[] points = new float[4]; - private static final float SQRT_2 = (float) Math.sqrt(2); + private static final float INV_SQRT_2 = (float) (Math.sqrt(2) / 2.0); private static float dpScale = -1; private Utils() { @@ -78,15 +73,14 @@ public final class Utils { public static float getScale(Matrix matrix) { points[0] = 0; points[1] = 0; - // Use sqrt(2) so that the hypotenuse is of length 1. - points[2] = SQRT_2; - points[3] = SQRT_2; + // Use 1/sqrt(2) so that the hypotenuse is of length 1. + points[2] = INV_SQRT_2; + points[3] = INV_SQRT_2; matrix.mapPoints(points); float dx = points[2] - points[0]; float dy = points[3] - points[1]; - // TODO: figure out why the result needs to be divided by 2. - return (float) Math.hypot(dx, dy) / 2f; + return (float) Math.hypot(dx, dy); } public static boolean hasZeroScaleAxis(Matrix matrix) { |