Class XY

java.lang.Object
com.geodesk.geom.XY

public class XY extends Object
Methods for working with coordinates that are represented as a single long value. Y coordinate is stored in the upper 32 bits, X in the lower.
  • Constructor Summary

    Constructors
    Constructor
    Description
    XY()
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static int
    castRay(int[] coords, double cx, double cy)
    Fast but non-robust method to check how many times a line from a point intersects the given segments, using the ray-casting algorithm (https://en.wikipedia.org/wiki/Point_in_polygon#Ray_casting_algorithm).
    static boolean
    contains(int[] coords, int x, int y)
     
    static boolean
    isClosed(int[] coords)
    Checks whether a given set of coordinates represents a linear ring.
    static long
    of(int x, int y)
    Creates a long coordinate based on the given X and Y.
    static int[]
    of(long[] coords)
    Returns an array of LatLongs as an array of x/y coordinate pairs.
    static long
    Creates a long coordinate based on the given JTS Coordinate.
    static Coordinate
    toCoordinate(long xy)
    Turns a long coordinate into a JTS Coordinate.
    static Coordinate[]
    toCoordinates(long[] xy)
     
    static int
    x(long coord)
    Returns the X coordinate of the given long coordinate.
    static int
    y(long coord)
    Returns the Y coordinate of the given long coordinate.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • XY

      public XY()
  • Method Details

    • of

      public static long of(int x, int y)
      Creates a long coordinate based on the given X and Y.
      Parameters:
      x -
      y -
      Returns:
    • of

      public static long of(Coordinate c)
      Creates a long coordinate based on the given JTS Coordinate. Coordinates must be within the numeric range of a signed 32-bit integer and are rounded.
      Parameters:
      c -
      Returns:
    • toCoordinate

      public static Coordinate toCoordinate(long xy)
      Turns a long coordinate into a JTS Coordinate.
      Parameters:
      xy -
      Returns:
    • toCoordinates

      public static Coordinate[] toCoordinates(long[] xy)
    • x

      public static int x(long coord)
      Returns the X coordinate of the given long coordinate.
      Parameters:
      coord -
      Returns:
    • y

      public static int y(long coord)
      Returns the Y coordinate of the given long coordinate.
      Parameters:
      coord -
      Returns:
    • of

      public static int[] of(long[] coords)
      Returns an array of LatLongs as an array of x/y coordinate pairs.
      Parameters:
      coords -
      Returns:
    • isClosed

      public static boolean isClosed(int[] coords)
      Checks whether a given set of coordinates represents a linear ring.
      Parameters:
      coords - array of X/Y coordinates
      Returns:
    • contains

      public static boolean contains(int[] coords, int x, int y)
    • castRay

      public static int castRay(int[] coords, double cx, double cy)
      Fast but non-robust method to check how many times a line from a point intersects the given segments, using the ray-casting algorithm (https://en.wikipedia.org/wiki/Point_in_polygon#Ray_casting_algorithm). This is suitable for a point-in-polygon test, but be aware that points that are vertexes or are located on the edge (or very close to it) may or may not be considered "inside." This test can be applied to multiple line strings of the polygon in succession. In that case, the result of each test must be XOR'd with the previous results. The winding order is irrelevant, but the result is undefined if the segments are self-intersecting.
      Parameters:
      coords - pairs of x/y coordinates that form a polygon or segment thereof
      cx - the X-coordinate to test
      cy - the Y-coordinate to test
      Returns:
      0 if even number of edges are crossed ("not inside") 1 if odd number of edges are crossed ("inside")