Class XY
java.lang.Object
com.geodesk.geom.XY
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.-
Method Summary
Modifier and TypeMethodDescriptionstatic intcastRay(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.static booleancontains(int[] coords, int x, int y) static booleanisClosed(int[] coords) Checks whether a given set of coordinates represents a linear ring.static longof(int x, int y) Creates a `long` coordinate based on the given X and Y.static int[]of(long[] coords) Returns an array oflongcoordinates as an array of x/y coordinate pairs.static longof(Coordinate c) Creates alongcoordinate based on the given JTSCoordinate.static CoordinatetoCoordinate(long xy) Turns alongcoordinate into a JTSCoordinate.static Coordinate[]toCoordinates(long[] xy) static intx(long coord) Returns the X coordinate of the givenlongcoordinate.static inty(long coord) Returns the Y coordinate of the givenlongcoordinate.
-
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
Creates alongcoordinate based on the given JTSCoordinate. Coordinates must be within the numeric range of a signed 32-bit integer and are rounded.- Parameters:
c- theCoordinate- Returns:
-
toCoordinate
Turns alongcoordinate into a JTSCoordinate.- Parameters:
xy-- Returns:
-
toCoordinates
-
x
public static int x(long coord) Returns the X coordinate of the givenlongcoordinate.- Parameters:
coord-- Returns:
-
y
public static int y(long coord) Returns the Y coordinate of the givenlongcoordinate.- Parameters:
coord-- Returns:
-
of
public static int[] of(long[] coords) Returns an array oflongcoordinates 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. 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 thereofcx- the X-coordinate to testcy- 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")
-