Home | History | Annotate | Download | only in curvedmotion
      1 /*
      2  * Copyright (C) 2013 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 package com.example.android.curvedmotion;
     17 
     18 /**
     19  * A class that holds information about a location and how the path should get to that
     20  * location from the previous path location (if any). Any PathPoint holds the information for
     21  * its location as well as the instructions on how to traverse the preceding interval from the
     22  * previous location.
     23  */
     24 public class PathPoint {
     25 
     26     /**
     27      * The possible path operations that describe how to move from a preceding PathPoint to the
     28      * location described by this PathPoint.
     29      */
     30     public static final int MOVE = 0;
     31     public static final int LINE = 1;
     32     public static final int CURVE = 2;
     33 
     34     /**
     35      * The location of this PathPoint
     36      */
     37     float mX, mY;
     38 
     39     /**
     40      * The first control point, if any, for a PathPoint of type CURVE
     41      */
     42     float mControl0X, mControl0Y;
     43 
     44     /**
     45      * The second control point, if any, for a PathPoint of type CURVE
     46      */
     47     float mControl1X, mControl1Y;
     48 
     49     /**
     50      * The motion described by the path to get from the previous PathPoint in an AnimatorPath
     51      * to the location of this PathPoint. This can be one of MOVE, LINE, or CURVE.
     52      */
     53     int mOperation;
     54 
     55 
     56 
     57     /**
     58      * Line/Move constructor
     59      */
     60     private PathPoint(int operation, float x, float y) {
     61         mOperation = operation;
     62         mX = x;
     63         mY = y;
     64     }
     65 
     66     /**
     67      * Curve constructor
     68      */
     69     private PathPoint(float c0X, float c0Y, float c1X, float c1Y, float x, float y) {
     70         mControl0X = c0X;
     71         mControl0Y = c0Y;
     72         mControl1X = c1X;
     73         mControl1Y = c1Y;
     74         mX = x;
     75         mY = y;
     76         mOperation = CURVE;
     77     }
     78 
     79     /**
     80      * Constructs and returns a PathPoint object that describes a line to the given xy location.
     81      */
     82     public static PathPoint lineTo(float x, float y) {
     83         return new PathPoint(LINE, x, y);
     84     }
     85 
     86     /**
     87      * Constructs and returns a PathPoint object that describes a curve to the given xy location
     88      * with the control points at c0 and c1.
     89      */
     90     public static PathPoint curveTo(float c0X, float c0Y, float c1X, float c1Y, float x, float y) {
     91         return new PathPoint(c0X,  c0Y, c1X, c1Y, x, y);
     92     }
     93 
     94     /**
     95      * Constructs and returns a PathPoint object that describes a discontinuous move to the given
     96      * xy location.
     97      */
     98     public static PathPoint moveTo(float x, float y) {
     99         return new PathPoint(MOVE, x, y);
    100     }
    101 }
    102