Class Point

  • All Implemented Interfaces:
    android.os.Parcelable

    public class Point
    extends java.lang.Object
    implements android.os.Parcelable
    • Nested Class Summary

      • Nested classes/interfaces inherited from interface android.os.Parcelable

        android.os.Parcelable.ClassLoaderCreator<T extends java.lang.Object>, android.os.Parcelable.Creator<T extends java.lang.Object>
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static android.os.Parcelable.Creator<Point> CREATOR  
      • Fields inherited from interface android.os.Parcelable

        CONTENTS_FILE_DESCRIPTOR, PARCELABLE_WRITE_RETURN_VALUE
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
        Point()
      Constructor that creates default point at position (0,0).
        Point​(float x, float y)
      Constructor that creates point at position (x,y).
      protected Point​(android.os.Parcel in)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      Point clamp​(float length)
      Calculate and return point clamped to given norm (length).
      Point clamp​(float minLength, float maxLength)
      Calculate and return point clamped to given norm (lengths).
      int describeContents()  
      float distance​(Point other)
      Calculates and returns the distance to given point.
      void draw​(android.graphics.Canvas canvas, android.graphics.Paint paint, int pointRadius)
      Draws the point to given canvas with given paint.
      boolean equals​(java.lang.Object o)  
      float getX()  
      float getY()  
      boolean isZero()
      Returns true if point has coordinates (0,0).
      void log()
      Logs the point coordinates to LOG_DEBUG log.
      Point makeCopy()  
      Point mirrorX​(float maxXDimension)
      Return point mirrored around X axis.
      void mirrorXInPlace​(float maxXDimension)
      Mirrors point around X axis.
      Point mirrorXY​(float maxXDimension, float maxYDimension)
      Return point mirrored around both X and Y axis
      void mirrorXYInPlace​(float maxXDimension, float maxYDimension)
      Mirrors point around both X and Y axis
      Point mirrorY​(float maxYDimension)
      Return point mirrored around Y axis.
      void mirrorYInPlace​(float maxYDimension)
      Mirrors point around Y axis.
      Point negative()  
      Point negativeClone()
      Calculate and return negative of current point.
      float norm()
      Calculate and return norm of the point.
      Point normalize()
      Calculate and return point that has same direction as this point, but norm 1.
      Point normalize​(float length)
      Calculate and return point that has same direction as this point, but norm as given.
      Point operatorMinus​(Point other)
      - operator on the point.
      Point operatorMinusEquals​(Point other)  
      Point operatorMultiply​(float factor)
      Multiplication of the point with scalar.
      Point operatorMultiplyEquals​(float factor)  
      Point operatorPlus​(Point other)
      + operator on the point.
      void operatorPlusEquals​(Point other)
      += operator on the point.
      void setX​(float x)
      Sets the x coordinate of the point.
      void setY​(float y)
      Sets the y coordinate of the point.
      java.lang.String toString()  
      void writeToParcel​(android.os.Parcel dest, int flags)  
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Field Detail

      • CREATOR

        @NonNull
        public static final android.os.Parcelable.Creator<Point> CREATOR
    • Constructor Detail

      • Point

        public Point()
        Constructor that creates default point at position (0,0).
      • Point

        public Point​(float x,
                     float y)
        Constructor that creates point at position (x,y).
        Parameters:
        x - x-coordinate of the point
        y - y-coordinate of the poing
      • Point

        protected Point​(@NonNull
                        android.os.Parcel in)
    • Method Detail

      • toString

        @NonNull
        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • isZero

        public boolean isZero()
        Returns true if point has coordinates (0,0).
        Returns:
        true if point has coordinates (0,0).
      • operatorPlus

        @NonNull
        public Point operatorPlus​(@NonNull
                                  Point other)
        + operator on the point. Returned point is a new point. For example: c = a + b <==> c = a.operatorPlus(b);
        Parameters:
        other - Point to be added to current point
        Returns:
        new point that is the result of addition
      • operatorPlusEquals

        public void operatorPlusEquals​(@NonNull
                                       Point other)
        += operator on the point. For example: b+=a <==> b.operatorPlusEquals(a);
        Parameters:
        other - Point to be added to current point
      • operatorMinus

        @NonNull
        public Point operatorMinus​(@NonNull
                                   Point other)
        - operator on the point. Returned point is a new point. For example: c = a - b <==> c = a.operatorMinus(b);
        Parameters:
        other - Point to be substracted from current point
        Returns:
        new point that is the result of substraction
      • operatorMinusEquals

        @NonNull
        public Point operatorMinusEquals​(@NonNull
                                         Point other)
      • operatorMultiply

        @NonNull
        public Point operatorMultiply​(float factor)
        Multiplication of the point with scalar. Returned point is a new point. For example: pointC = pointA * scalarB <==> c = a.operatorMultiply(b)
        Parameters:
        factor - Scalar with which point should be multiplied
        Returns:
        new point that is the result of multiplication
      • operatorMultiplyEquals

        @NonNull
        public Point operatorMultiplyEquals​(float factor)
      • negativeClone

        @NonNull
        public Point negativeClone()
        Calculate and return negative of current point. Negative point is point mirrored to current point over (0,0) pivot.
        Returns:
        Negative point.
      • negative

        @NonNull
        public Point negative()
      • norm

        public float norm()
        Calculate and return norm of the point. Norm is the distance of the point and point (0,0).
        Returns:
        Norm of the point.
      • normalize

        @NonNull
        public Point normalize()
        Calculate and return point that has same direction as this point, but norm 1.
        Returns:
        Unit point.
      • normalize

        @NonNull
        public Point normalize​(float length)
        Calculate and return point that has same direction as this point, but norm as given.
        Parameters:
        length - Desired norm of the point.
        Returns:
        Point with norm "length".
      • clamp

        @NonNull
        public Point clamp​(float length)
        Calculate and return point clamped to given norm (length). If norm of the point is larger than desired length, returns the point that has the same direction as this point, but norm "length". If norm of the point is smaller or equal to desired length, returns the clone of this point.
        Parameters:
        length - Desired norm to which point should be clamped.
        Returns:
        Clamped point.
      • clamp

        @NonNull
        public Point clamp​(float minLength,
                           float maxLength)
        Calculate and return point clamped to given norm (lengths). If norm of the point is larger than maxLength, returns the point that has the same direction as this point, but norm "maxLength". If norm of the point is smaller than minLength, returns the point that has the same direction as this point, but norm "minLength". If norm of the point is smaller than maxLength and larger than minLength, returns the clone of this point.
        Parameters:
        minLength - Minimum desired norm of the point.
        maxLength - Maximum desired norm of the point.
        Returns:
        Clamped point.
      • mirrorX

        @NonNull
        public Point mirrorX​(float maxXDimension)
        Return point mirrored around X axis.
        Parameters:
        maxXDimension - Maximum dimension of X axis.
        Returns:
        Mirrored point
      • mirrorXInPlace

        public void mirrorXInPlace​(float maxXDimension)
        Mirrors point around X axis.
        Parameters:
        maxXDimension - Maximum dimension of X axis.
      • mirrorY

        @NonNull
        public Point mirrorY​(float maxYDimension)
        Return point mirrored around Y axis.
        Parameters:
        maxYDimension - Maximum dimension of Y axis.
        Returns:
        Mirrored point
      • mirrorYInPlace

        public void mirrorYInPlace​(float maxYDimension)
        Mirrors point around Y axis.
        Parameters:
        maxYDimension - Maximum dimension of Y axis.
      • mirrorXY

        @NonNull
        public Point mirrorXY​(float maxXDimension,
                              float maxYDimension)
        Return point mirrored around both X and Y axis
        Parameters:
        maxXDimension - Maximum dimension of X axis.
        maxYDimension - Maximum dimension of Y axis.
        Returns:
        Mirrored point.
      • mirrorXYInPlace

        public void mirrorXYInPlace​(float maxXDimension,
                                    float maxYDimension)
        Mirrors point around both X and Y axis
        Parameters:
        maxXDimension - Maximum dimension of X axis.
        maxYDimension - Maximum dimension of Y axis.
      • makeCopy

        @NonNull
        public Point makeCopy()
      • equals

        public boolean equals​(@Nullable
                              java.lang.Object o)
        Overrides:
        equals in class java.lang.Object
      • distance

        public float distance​(@NonNull
                              Point other)
        Calculates and returns the distance to given point.
        Parameters:
        other - Point to which distance is calculated.
        Returns:
        distance to given point
      • log

        public void log()
        Logs the point coordinates to LOG_DEBUG log.
      • draw

        public void draw​(@NonNull
                         android.graphics.Canvas canvas,
                         @NonNull
                         android.graphics.Paint paint,
                         int pointRadius)
        Draws the point to given canvas with given paint. Point is drawn as circle of given radius.
        Parameters:
        canvas - Canvas to which point should be drawn.
        paint - Paint used to draw point.
        pointRadius - Radius of the circle that represents the point.
      • getX

        public float getX()
        Returns:
        the x coordinate of the point
      • setX

        public void setX​(float x)
        Sets the x coordinate of the point.
        Parameters:
        x - x coordinate of the point
      • getY

        public float getY()
        Returns:
        the y coordinate of the point
      • setY

        public void setY​(float y)
        Sets the y coordinate of the point.
        Parameters:
        y - y coordinate of the point
      • describeContents

        public int describeContents()
        Specified by:
        describeContents in interface android.os.Parcelable
      • writeToParcel

        public void writeToParcel​(@NonNull
                                  android.os.Parcel dest,
                                  int flags)
        Specified by:
        writeToParcel in interface android.os.Parcelable