Package com.geodesk.core
Class XY
java.lang.Object
com.geodesk.core.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.
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic 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
of
(Coordinate c) Creates a long coordinate based on the given JTSCoordinate
.static Coordinate
toCoordinate
(long xy) Turns a long coordinate into a JTSCoordinate
.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.
-
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
Creates a long coordinate based on the given JTSCoordinate
. Coordinates must be within the numeric range of a signed 32-bit integer and are rounded.- Parameters:
c
-- Returns:
-
toCoordinate
Turns a long coordinate into a JTSCoordinate
.- Parameters:
xy
-- Returns:
-
toCoordinates
-
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 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")
-