Package arc.math.geom

Class Point2

java.lang.Object
arc.math.geom.Point2

public class Point2 extends Object
A point in a 2D grid, with integer x and y coordinates
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    int
     
    int
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    Constructs a new 2D grid point.
    Point2(int x, int y)
    Constructs a new 2D grid point.
    Point2(Point2 point)
    Copy constructor
  • Method Summary

    Modifier and Type
    Method
    Description
    add(int x, int y)
    Adds another 2D grid point to this point.
    add(Point2 other)
    Adds another 2D grid point to this point.
    cpy()
     
    float
    dst(int x, int y)
     
    float
    dst(Point2 other)
     
    float
    dst2(int x, int y)
     
    float
    dst2(Point2 other)
     
    boolean
    equals(int x, int y)
     
    static boolean
    equals(int x, int y, int ox, int oy)
     
    boolean
     
    int
     
    int
     
    static int
    pack(int x, int y)
     
    rotate(int steps)
    Rotates this point in 90-degree increments several times.
    set(int x, int y)
    Sets the coordinates of this 2D grid point.
    set(Point2 point)
    Sets the coordinates of this 2D grid point to that of another.
    sub(int x, int y)
    Subtracts another 2D grid point from this point.
    sub(Point2 other)
    Subtracts another 2D grid point from this point.
     
    static Point2
    unpack(int pos)
     
    static short
    x(int pos)
     
    static short
    y(int pos)
     

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Field Details

    • x

      public int x
    • y

      public int y
  • Constructor Details

    • Point2

      public Point2()
      Constructs a new 2D grid point.
    • Point2

      public Point2(int x, int y)
      Constructs a new 2D grid point.
      Parameters:
      x - X coordinate
      y - Y coordinate
    • Point2

      public Point2(Point2 point)
      Copy constructor
      Parameters:
      point - The 2D grid point to make a copy of.
  • Method Details

    • unpack

      public static Point2 unpack(int pos)
      Returns:
      a point unpacked from an integer.
    • pack

      public static int pack(int x, int y)
      Returns:
      this point packed into a single int by casting its components to shorts.
    • x

      public static short x(int pos)
      Returns:
      the x component of a packed position.
    • y

      public static short y(int pos)
      Returns:
      the y component of a packed position.
    • pack

      public int pack()
      Returns:
      this point packed into a single int by casting its components to shorts.
    • set

      public Point2 set(Point2 point)
      Sets the coordinates of this 2D grid point to that of another.
      Parameters:
      point - The 2D grid point to copy the coordinates of.
      Returns:
      this 2D grid point for chaining.
    • set

      public Point2 set(int x, int y)
      Sets the coordinates of this 2D grid point.
      Parameters:
      x - X coordinate
      y - Y coordinate
      Returns:
      this 2D grid point for chaining.
    • dst2

      public float dst2(Point2 other)
      Parameters:
      other - The other point
      Returns:
      the squared distance between this point and the other point.
    • dst2

      public float dst2(int x, int y)
      Parameters:
      x - The x-coordinate of the other point
      y - The y-coordinate of the other point
      Returns:
      the squared distance between this point and the other point.
    • dst

      public float dst(Point2 other)
      Parameters:
      other - The other point
      Returns:
      the distance between this point and the other vector.
    • dst

      public float dst(int x, int y)
      Parameters:
      x - The x-coordinate of the other point
      y - The y-coordinate of the other point
      Returns:
      the distance between this point and the other point.
    • add

      public Point2 add(Point2 other)
      Adds another 2D grid point to this point.
      Parameters:
      other - The other point
      Returns:
      this 2d grid point for chaining.
    • add

      public Point2 add(int x, int y)
      Adds another 2D grid point to this point.
      Parameters:
      x - The x-coordinate of the other point
      y - The y-coordinate of the other point
      Returns:
      this 2d grid point for chaining.
    • sub

      public Point2 sub(Point2 other)
      Subtracts another 2D grid point from this point.
      Parameters:
      other - The other point
      Returns:
      this 2d grid point for chaining.
    • sub

      public Point2 sub(int x, int y)
      Subtracts another 2D grid point from this point.
      Parameters:
      x - The x-coordinate of the other point
      y - The y-coordinate of the other point
      Returns:
      this 2d grid point for chaining.
    • cpy

      public Point2 cpy()
      Returns:
      a copy of this grid point
    • rotate

      public Point2 rotate(int steps)
      Rotates this point in 90-degree increments several times.
    • equals

      public boolean equals(int x, int y)
    • equals

      public static boolean equals(int x, int y, int ox, int oy)
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object