• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 package com.airbnb.lottie.model;
2 
3 import static androidx.annotation.RestrictTo.Scope.LIBRARY;
4 
5 import android.annotation.SuppressLint;
6 import android.graphics.PointF;
7 
8 import androidx.annotation.NonNull;
9 import androidx.annotation.RestrictTo;
10 
11 /**
12  * One cubic path operation. CubicCurveData is structured such that it is easy to iterate through
13  * it and build a path. However, it is modeled differently than most path operations.
14  *
15  * CubicCurveData
16  * |                     - vertex
17  * |                   /
18  * |    cp1          cp2
19  * |   /
20  * |  |
21  * | /
22  * --------------------------
23  *
24  * When incrementally building a path, it will already have a "current point" so that is
25  * not captured in this data structure.
26  * The control points here represent {@link android.graphics.Path#cubicTo(float, float, float, float, float, float)}.
27  *
28  * Most path operations are centered around a vertex and its in control point and out control point like this:
29  * |           outCp
30  * |          /
31  * |         |
32  * |         v
33  * |        /
34  * |      inCp
35  * --------------------------
36  */
37 @RestrictTo(LIBRARY)
38 public class CubicCurveData {
39   private final PointF controlPoint1;
40   private final PointF controlPoint2;
41   private final PointF vertex;
42 
CubicCurveData()43   public CubicCurveData() {
44     controlPoint1 = new PointF();
45     controlPoint2 = new PointF();
46     vertex = new PointF();
47   }
48 
CubicCurveData(PointF controlPoint1, PointF controlPoint2, PointF vertex)49   public CubicCurveData(PointF controlPoint1, PointF controlPoint2, PointF vertex) {
50     this.controlPoint1 = controlPoint1;
51     this.controlPoint2 = controlPoint2;
52     this.vertex = vertex;
53   }
54 
setControlPoint1(float x, float y)55   public void setControlPoint1(float x, float y) {
56     controlPoint1.set(x, y);
57   }
58 
getControlPoint1()59   public PointF getControlPoint1() {
60     return controlPoint1;
61   }
62 
setControlPoint2(float x, float y)63   public void setControlPoint2(float x, float y) {
64     controlPoint2.set(x, y);
65   }
66 
getControlPoint2()67   public PointF getControlPoint2() {
68     return controlPoint2;
69   }
70 
setVertex(float x, float y)71   public void setVertex(float x, float y) {
72     vertex.set(x, y);
73   }
74 
setFrom(CubicCurveData curveData)75   public void setFrom(CubicCurveData curveData) {
76     setVertex(curveData.vertex.x, curveData.vertex.y);
77     setControlPoint1(curveData.controlPoint1.x, curveData.controlPoint1.y);
78     setControlPoint2(curveData.controlPoint2.x, curveData.controlPoint2.y);
79   }
80 
getVertex()81   public PointF getVertex() {
82     return vertex;
83   }
84 
85   @SuppressLint("DefaultLocale")
86   @NonNull
toString()87   @Override public String toString() {
88     return String.format("v=%.2f,%.2f cp1=%.2f,%.2f cp2=%.2f,%.2f",
89         vertex.x, vertex.y, controlPoint1.x, controlPoint1.y, controlPoint2.x, controlPoint2.y);
90   }
91 }
92