Package com.treasure.hunt.utils
Class JTSUtils
- java.lang.Object
-
- com.treasure.hunt.utils.JTSUtils
-
public final class JTSUtils extends java.lang.Object
A utility class for the work withorg.locationtech.jts
.
-
-
Field Summary
Fields Modifier and Type Field Description static org.locationtech.jts.geom.PrecisionModel
APPROXIMATELY_PRECISION
static org.locationtech.jts.geom.GeometryFactory
GEOMETRY_FACTORY
A static final sharedGeometryFactory
we use, such that every usage uses the same settings of the geometry factory.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static java.util.List<org.locationtech.jts.geom.Point>
circleLineIntersectionPoints(org.locationtech.jts.geom.Point pointA, org.locationtech.jts.geom.Point pointB, org.locationtech.jts.geom.Point center, double radius)
Calculates the intersectionPoint
s, from a line and a circle.static java.util.ArrayList<org.locationtech.jts.geom.Coordinate>
convexPolygonLineIntersection(org.locationtech.jts.geom.Polygon polygon, org.locationtech.jts.geom.LineSegment line)
Tests whether the convex polygon polygon intersects with the line line and returns the intersecting coordinates if it does.static boolean
coordinateEqual(org.locationtech.jts.geom.Coordinate a, org.locationtech.jts.geom.Coordinate b)
static org.locationtech.jts.geom.Coordinate
coordinateInDistance(org.locationtech.jts.geom.Coordinate fixed, org.locationtech.jts.geom.Coordinate floating, double scale)
Get the coordinate a given length-unit away from fixedCoordinate
in vector (fixed to floating) direction.static org.locationtech.jts.algorithm.ConvexHull
createConvexHull(java.util.List<org.locationtech.jts.geom.Coordinate> coordinates)
Get theConvexHull
for a list ofCoordinate
s.static org.locationtech.jts.geom.LineString
createLineString(org.locationtech.jts.geom.Point a, org.locationtech.jts.geom.Point b)
static org.locationtech.jts.geom.Point
createPoint(double x, double y)
static org.locationtech.jts.geom.Point
createPoint(org.locationtech.jts.geom.Coordinate coordinate)
static boolean
doubleEqual(double a, double b)
static boolean
doubleEqualApproximately(double a, double b)
static java.util.List<org.locationtech.jts.geom.Coordinate>
getBoundaryIntersections(CanvasBoundary boundary, org.locationtech.jts.geom.LineSegment infinite)
Get the intersections between the infinite line and the visual boundary.static java.util.List<org.locationtech.jts.geom.Coordinate>
getCoordinateList(java.util.List<? extends org.locationtech.jts.geom.Geometry> geometries)
static javafx.util.Pair<java.lang.Double,java.lang.Double>
getLinearEquation(org.locationtech.jts.geom.Point pointA, org.locationtech.jts.geom.Point pointB)
Works only for 2-dimensionalPoint
s.static org.locationtech.jts.geom.Point
getLineIntersection(javafx.util.Pair<java.lang.Double,java.lang.Double> function1, javafx.util.Pair<java.lang.Double,java.lang.Double> function2)
static javafx.util.Pair<java.lang.Double,java.lang.Double>
getOrthogonal(double gradient, org.locationtech.jts.geom.Point point)
static boolean
isApproximatelyOnLine(org.locationtech.jts.geom.Coordinate point, org.locationtech.jts.geom.LineSegment line)
static boolean
isBadHint(org.locationtech.jts.geom.Polygon rectangle, AngleHint hint)
this function can be called to determine if the specified hint is a bad Hint defined be the paper in the context of the specified rectanglestatic org.locationtech.jts.geom.Coordinate
lineWayIntersection(org.locationtech.jts.geom.LineSegment line, org.locationtech.jts.geom.LineSegment segment)
Tests whether the line line intersects with the linesegment segment and returns the intersecting Coordinate (if one exists).static org.locationtech.jts.geom.Coordinate
middleOfAngleHint(AngleHint angleHint)
static org.locationtech.jts.geom.Coordinate
middleOfAngleHint(org.locationtech.jts.geom.Coordinate right, org.locationtech.jts.geom.Coordinate center, org.locationtech.jts.geom.Coordinate left)
static org.locationtech.jts.geom.Coordinate
middleOfGeometryAngle(GeometryAngle angle)
static org.locationtech.jts.math.Vector2D
negateX(org.locationtech.jts.math.Vector2D vector)
static org.locationtech.jts.math.Vector2D
negateY(org.locationtech.jts.math.Vector2D vector)
static org.locationtech.jts.geom.Coordinate
normalizedCoordinate(org.locationtech.jts.geom.Coordinate fixed, org.locationtech.jts.geom.Coordinate floating)
Get the coordinate 1 length-unit away from fixedCoordinate
in vector (fixed to floating) direction.static org.locationtech.jts.math.Vector2D
normalizedVector(org.locationtech.jts.geom.Coordinate from, org.locationtech.jts.geom.Coordinate to)
static boolean
pointInAngle(GeometryAngle geometryAngle, org.locationtech.jts.geom.Coordinate coordinate)
static boolean
pointInAngle(org.locationtech.jts.geom.Coordinate right, org.locationtech.jts.geom.Coordinate center, org.locationtech.jts.geom.Coordinate left, org.locationtech.jts.geom.Coordinate coordinate)
Tests, whether a givenCoordinate
lies inside the given angle, which is defined byright
,center
andleft
.static Circle
randomContainedCircle(Circle boundary, org.locationtech.jts.geom.Coordinate pivot, double radius)
Shuffles a new circle covered by the boundary circle, containing the pivot coordinate and obtaining the given radius;static org.locationtech.jts.geom.Coordinate
randomInCircle(Circle circle)
Generate a random coordinate in the given circle.static org.locationtech.jts.geom.Point
shuffleTreasure()
static boolean
signsEqual(org.locationtech.jts.math.Vector2D v0, org.locationtech.jts.math.Vector2D v1)
static org.locationtech.jts.geom.Polygon
toPolygon(org.locationtech.jts.geom.Envelope envelope)
static GeometryAngle
validRandomAngle(org.locationtech.jts.geom.Coordinate searcher, org.locationtech.jts.geom.Coordinate treasure, double maxExtend)
static GeometryAngle
validRandomAngle(org.locationtech.jts.geom.Coordinate searcher, org.locationtech.jts.geom.Coordinate treasure, double maxExtend, double minExtend)
-
-
-
Field Detail
-
GEOMETRY_FACTORY
public static final org.locationtech.jts.geom.GeometryFactory GEOMETRY_FACTORY
A static final sharedGeometryFactory
we use, such that every usage uses the same settings of the geometry factory.
-
APPROXIMATELY_PRECISION
public static final org.locationtech.jts.geom.PrecisionModel APPROXIMATELY_PRECISION
-
-
Method Detail
-
createPoint
public static org.locationtech.jts.geom.Point createPoint(double x, double y)
- Parameters:
x
- x-coordinatey
- y-coordinate- Returns:
Point
lying on(x,y)
.
-
createPoint
public static org.locationtech.jts.geom.Point createPoint(org.locationtech.jts.geom.Coordinate coordinate)
- Parameters:
coordinate
- TheCoordinate
, which should be converted to aPoint
.- Returns:
Point
lying oncoordinate.
.
-
createLineString
public static org.locationtech.jts.geom.LineString createLineString(org.locationtech.jts.geom.Point a, org.locationtech.jts.geom.Point b)
- Parameters:
a
- the begin of theLineString
.b
- the end of theLineString
.- Returns:
- A
LineString
containing onlya
andb
.
-
lineWayIntersection
public static org.locationtech.jts.geom.Coordinate lineWayIntersection(org.locationtech.jts.geom.LineSegment line, org.locationtech.jts.geom.LineSegment segment)
Tests whether the line line intersects with the linesegment segment and returns the intersecting Coordinate (if one exists).- Parameters:
line
- aLineSegment
segment
- aLineSegment
- Returns:
- an intersection
Point
of theLineSegment
objectsline
andlineSegment
-
convexPolygonLineIntersection
public static java.util.ArrayList<org.locationtech.jts.geom.Coordinate> convexPolygonLineIntersection(org.locationtech.jts.geom.Polygon polygon, org.locationtech.jts.geom.LineSegment line)
Tests whether the convex polygon polygon intersects with the line line and returns the intersecting coordinates if it does.- Parameters:
polygon
- aPolygon
line
- aLineSegment
- Returns:
- an ArrayList of the intersecting coordinates if they exist, a empty ArrayList otherwise
-
doubleEqual
public static boolean doubleEqual(double a, double b)
-
coordinateEqual
public static boolean coordinateEqual(org.locationtech.jts.geom.Coordinate a, org.locationtech.jts.geom.Coordinate b)
-
doubleEqualApproximately
public static boolean doubleEqualApproximately(double a, double b)
-
middleOfAngleHint
public static org.locationtech.jts.geom.Coordinate middleOfAngleHint(AngleHint angleHint)
- Parameters:
angleHint
- where we want the middle point to go, from.- Returns:
Coordinate
going through the middle of theAngleHint
-
middleOfGeometryAngle
public static org.locationtech.jts.geom.Coordinate middleOfGeometryAngle(GeometryAngle angle)
-
middleOfAngleHint
public static org.locationtech.jts.geom.Coordinate middleOfAngleHint(org.locationtech.jts.geom.Coordinate right, org.locationtech.jts.geom.Coordinate center, org.locationtech.jts.geom.Coordinate left)
- Parameters:
right
- opening line of the anglecenter
- of the angleleft
- closing line of the angle- Returns:
Coordinate
going through the middle of the angle
-
normalizedVector
public static org.locationtech.jts.math.Vector2D normalizedVector(org.locationtech.jts.geom.Coordinate from, org.locationtech.jts.geom.Coordinate to)
- Parameters:
from
- vector startto
- vector end- Returns:
- normalized
Vector2D
given by twoCoordinate
sfrom
andto
.
-
coordinateInDistance
public static org.locationtech.jts.geom.Coordinate coordinateInDistance(org.locationtech.jts.geom.Coordinate fixed, org.locationtech.jts.geom.Coordinate floating, double scale)
Get the coordinate a given length-unit away from fixedCoordinate
in vector (fixed to floating) direction.- Parameters:
fixed
- fixed relative coordinatefloating
- coordinate to provide direction vectorscale
- length between fixed and asked coordinate- Returns:
- the
Coordinate
a given length-unit away from fixedCoordinate
in vector direction
-
normalizedCoordinate
public static org.locationtech.jts.geom.Coordinate normalizedCoordinate(org.locationtech.jts.geom.Coordinate fixed, org.locationtech.jts.geom.Coordinate floating)
Get the coordinate 1 length-unit away from fixedCoordinate
in vector (fixed to floating) direction.- Parameters:
fixed
- fixed relative coordinatefloating
- coordinate to provide direction vector- Returns:
- coordinate 1 length-unit away from fixed
Coordinate
in vector direction
-
signsEqual
public static boolean signsEqual(org.locationtech.jts.math.Vector2D v0, org.locationtech.jts.math.Vector2D v1)
- Parameters:
v0
- first vector to checkv1
- second vector to check- Returns:
true
, if both vectorsv0
andv1
have coordinate-wise the same sign.false
, otherwise.
-
negateX
public static org.locationtech.jts.math.Vector2D negateX(org.locationtech.jts.math.Vector2D vector)
- Parameters:
vector
- vector to transform- Returns:
- new
Vector2D
with negated x-Coordinate of avector
.
-
negateY
public static org.locationtech.jts.math.Vector2D negateY(org.locationtech.jts.math.Vector2D vector)
- Parameters:
vector
- vector to transform- Returns:
- new
Vector2D
with negated y-Coordinate of avector
.
-
pointInAngle
public static boolean pointInAngle(GeometryAngle geometryAngle, org.locationtech.jts.geom.Coordinate coordinate)
- Parameters:
geometryAngle
- the viewGeometryAngle
the method looks upon searching the given pointcoordinate
- theCoordinate
, we want to know, whether it lies in thegeometryAngle
.- Returns:
true
, ifcoordinate
lies inside the givengeometryAngle
.false
, otherwise.
-
pointInAngle
public static boolean pointInAngle(org.locationtech.jts.geom.Coordinate right, org.locationtech.jts.geom.Coordinate center, org.locationtech.jts.geom.Coordinate left, org.locationtech.jts.geom.Coordinate coordinate)
Tests, whether a givenCoordinate
lies inside the given angle, which is defined byright
,center
andleft
.- Parameters:
right
- counter-clockwise, opening line of the angle.center
- center of the angle.left
- counter-clockwise, closing line of the angle.coordinate
- theCoordinate
, we want to know, whether it lies in the given angle.- Returns:
true
, ifcoordinate
lies in the given angle.false
, otherwise.
-
validRandomAngle
public static GeometryAngle validRandomAngle(org.locationtech.jts.geom.Coordinate searcher, org.locationtech.jts.geom.Coordinate treasure, double maxExtend)
- Parameters:
searcher
- theCoordinate
of theSearcher
.treasure
- theCoordinate
of the treasure.maxExtend
- number of[0, 2 * Math.PI)
defining, how wide the angle is opened.- Returns:
- a valid
GeometryAngle
, randomly generated.
-
validRandomAngle
public static GeometryAngle validRandomAngle(org.locationtech.jts.geom.Coordinate searcher, org.locationtech.jts.geom.Coordinate treasure, double maxExtend, double minExtend)
- Parameters:
searcher
- theCoordinate
of theSearcher
.treasure
- theCoordinate
of the treasure.maxExtend
- number of[0, 2 * Math.PI)
defining, how wide the angle is opened.minExtend
- number of[0, maxExtend)
- Returns:
- a valid
GeometryAngle
, randomly generated.
-
getCoordinateList
public static java.util.List<org.locationtech.jts.geom.Coordinate> getCoordinateList(java.util.List<? extends org.locationtech.jts.geom.Geometry> geometries)
- Parameters:
geometries
- A list, containingGeometry
's, which should be converted to a list ofCoordinate
's.- Returns:
- A list of
Coordinate
's, whichgeometries
is converted to.
-
toPolygon
public static org.locationtech.jts.geom.Polygon toPolygon(org.locationtech.jts.geom.Envelope envelope)
- Parameters:
envelope
- AnEnvelope
, which will be converted to anPolygon
.- Returns:
- A
Polygon
, aenvelope
is converted to.
-
getBoundaryIntersections
public static java.util.List<org.locationtech.jts.geom.Coordinate> getBoundaryIntersections(CanvasBoundary boundary, org.locationtech.jts.geom.LineSegment infinite)
Get the intersections between the infinite line and the visual boundary.- Parameters:
boundary
- boundary supplying the borderLineSegment
sinfinite
- infinite line- Returns:
- the intersections between the infinite line extension and the boundary
LineSegment
s
-
randomContainedCircle
public static Circle randomContainedCircle(Circle boundary, org.locationtech.jts.geom.Coordinate pivot, double radius)
Shuffles a new circle covered by the boundary circle, containing the pivot coordinate and obtaining the given radius;- Parameters:
boundary
- circle to cover the generated circlepivot
- coordinate, that must lay inside of the generated circleradius
- radius of the generated circle- Returns:
- a valid generated circle
-
createConvexHull
public static org.locationtech.jts.algorithm.ConvexHull createConvexHull(java.util.List<org.locationtech.jts.geom.Coordinate> coordinates)
Get theConvexHull
for a list ofCoordinate
s.- Parameters:
coordinates
- the list of coordinates- Returns:
- the convex hull for the list of coordinates
-
shuffleTreasure
public static org.locationtech.jts.geom.Point shuffleTreasure()
- Returns:
- A
Point
, where the treasure is located,msatisfyingPreferenceService.MIN_TREASURE_DISTANCE
,PreferenceService.MAX_TREASURE_DISTANCE
andPreferenceService.TREASURE_DISTANCE
.
-
isApproximatelyOnLine
public static boolean isApproximatelyOnLine(org.locationtech.jts.geom.Coordinate point, org.locationtech.jts.geom.LineSegment line)
-
randomInCircle
public static org.locationtech.jts.geom.Coordinate randomInCircle(Circle circle)
Generate a random coordinate in the given circle.- Parameters:
circle
- circle to cover the generated coordinate- Returns:
- random coordinate in given circle
-
isBadHint
public static boolean isBadHint(org.locationtech.jts.geom.Polygon rectangle, AngleHint hint)
this function can be called to determine if the specified hint is a bad Hint defined be the paper in the context of the specified rectangle- Parameters:
rectangle
- the rectangle asPolygon
hint
- theAngleHint
- Returns:
true
if the givenangleHint
is a bad hint, related on theStrategyFromPaper
.false
otherwise.
-
circleLineIntersectionPoints
public static java.util.List<org.locationtech.jts.geom.Point> circleLineIntersectionPoints(org.locationtech.jts.geom.Point pointA, org.locationtech.jts.geom.Point pointB, org.locationtech.jts.geom.Point center, double radius)
Calculates the intersectionPoint
s, from a line and a circle. The line is described as going frompointA
topointB
and the circle ist described by having his center oncenter
and a radius ofradius
.- Parameters:
pointA
- the firstPoint
of the linepointB
- the secondPoint
of the linecenter
- the centerPoint
of the circleradius
- the radius of the circle- Returns:
- a list, containing 0, 1 or 2
Point
s, representing the intersections of the line and the circle.
-
getLinearEquation
public static javafx.util.Pair<java.lang.Double,java.lang.Double> getLinearEquation(org.locationtech.jts.geom.Point pointA, org.locationtech.jts.geom.Point pointB)
Works only for 2-dimensionalPoint
s.- Parameters:
pointA
- the firstPoint
, forming a linepointB
- the secondPoint
, forming a line- Returns:
- the linear equation
y = xm + b
of the line,pointA
andpointB
form. The linear equation is returned by a Pair containing the gradientm
and the y-valueb
, where the line cuts the y-axis. - Throws:
java.lang.IllegalArgumentException
- ifpointA
andpointB
does not form a function.
-
getOrthogonal
public static javafx.util.Pair<java.lang.Double,java.lang.Double> getOrthogonal(double gradient, org.locationtech.jts.geom.Point point)
- Parameters:
gradient
- the gradient to the line, we will calculate the orthogonal form.point
- thePoint
, the orthogonal will run though.- Returns:
- the linear equation
y = xm + b
of the orthogonal line to a line with gradientgradient
, running through pointpoint
. The linear equation is returned by a Pair containing the gradientm
and the y-valueb
, where the line cuts the y-axis. - Throws:
java.lang.IllegalArgumentException
- if thegradient
is 0, where there is no orthogonal.
-
getLineIntersection
public static org.locationtech.jts.geom.Point getLineIntersection(javafx.util.Pair<java.lang.Double,java.lang.Double> function1, javafx.util.Pair<java.lang.Double,java.lang.Double> function2)
- Parameters:
function1
-y = m1*x + b1
, given as a pair containing the gradientm
and the y-coordinateb
, intersecting the y-axes.function2
-y = m2*x + b2
, given as a pair containing the gradientm
and the y-coordinateb
, intersecting the y-axes.- Returns:
- the intersection
Point
, offunction1
andfunction2
. Thus, we return - Throws:
java.lang.IllegalArgumentException
- if both functions have no intersection or are equal.
-
-