Package com.treasure.hunt.utils
Class JTSUtils
- java.lang.Object
-
- com.treasure.hunt.utils.JTSUtils
-
public final class JTSUtils extends java.lang.ObjectA utility class for the work withorg.locationtech.jts.
-
-
Field Summary
Fields Modifier and Type Field Description static org.locationtech.jts.geom.PrecisionModelAPPROXIMATELY_PRECISIONstatic org.locationtech.jts.geom.GeometryFactoryGEOMETRY_FACTORYA static final sharedGeometryFactorywe 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 intersectionPoints, 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 booleancoordinateEqual(org.locationtech.jts.geom.Coordinate a, org.locationtech.jts.geom.Coordinate b)static org.locationtech.jts.geom.CoordinatecoordinateInDistance(org.locationtech.jts.geom.Coordinate fixed, org.locationtech.jts.geom.Coordinate floating, double scale)Get the coordinate a given length-unit away from fixedCoordinatein vector (fixed to floating) direction.static org.locationtech.jts.algorithm.ConvexHullcreateConvexHull(java.util.List<org.locationtech.jts.geom.Coordinate> coordinates)Get theConvexHullfor a list ofCoordinates.static org.locationtech.jts.geom.LineStringcreateLineString(org.locationtech.jts.geom.Point a, org.locationtech.jts.geom.Point b)static org.locationtech.jts.geom.PointcreatePoint(double x, double y)static org.locationtech.jts.geom.PointcreatePoint(org.locationtech.jts.geom.Coordinate coordinate)static booleandoubleEqual(double a, double b)static booleandoubleEqualApproximately(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-dimensionalPoints.static org.locationtech.jts.geom.PointgetLineIntersection(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 booleanisApproximatelyOnLine(org.locationtech.jts.geom.Coordinate point, org.locationtech.jts.geom.LineSegment line)static booleanisBadHint(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.CoordinatelineWayIntersection(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.CoordinatemiddleOfAngleHint(AngleHint angleHint)static org.locationtech.jts.geom.CoordinatemiddleOfAngleHint(org.locationtech.jts.geom.Coordinate right, org.locationtech.jts.geom.Coordinate center, org.locationtech.jts.geom.Coordinate left)static org.locationtech.jts.geom.CoordinatemiddleOfGeometryAngle(GeometryAngle angle)static org.locationtech.jts.math.Vector2DnegateX(org.locationtech.jts.math.Vector2D vector)static org.locationtech.jts.math.Vector2DnegateY(org.locationtech.jts.math.Vector2D vector)static org.locationtech.jts.geom.CoordinatenormalizedCoordinate(org.locationtech.jts.geom.Coordinate fixed, org.locationtech.jts.geom.Coordinate floating)Get the coordinate 1 length-unit away from fixedCoordinatein vector (fixed to floating) direction.static org.locationtech.jts.math.Vector2DnormalizedVector(org.locationtech.jts.geom.Coordinate from, org.locationtech.jts.geom.Coordinate to)static booleanpointInAngle(GeometryAngle geometryAngle, org.locationtech.jts.geom.Coordinate coordinate)static booleanpointInAngle(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 givenCoordinatelies inside the given angle, which is defined byright,centerandleft.static CirclerandomContainedCircle(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.CoordinaterandomInCircle(Circle circle)Generate a random coordinate in the given circle.static org.locationtech.jts.geom.PointshuffleTreasure()static booleansignsEqual(org.locationtech.jts.math.Vector2D v0, org.locationtech.jts.math.Vector2D v1)static org.locationtech.jts.geom.PolygontoPolygon(org.locationtech.jts.geom.Envelope envelope)static GeometryAnglevalidRandomAngle(org.locationtech.jts.geom.Coordinate searcher, org.locationtech.jts.geom.Coordinate treasure, double maxExtend)static GeometryAnglevalidRandomAngle(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 sharedGeometryFactorywe 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:
Pointlying 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:
Pointlying 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
LineStringcontaining onlyaandb.
-
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- aLineSegmentsegment- aLineSegment- Returns:
- an intersection
Pointof theLineSegmentobjectslineandlineSegment
-
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- aPolygonline- 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:
Coordinategoing 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:
Coordinategoing 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
Vector2Dgiven by twoCoordinatesfromandto.
-
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 fixedCoordinatein vector (fixed to floating) direction.- Parameters:
fixed- fixed relative coordinatefloating- coordinate to provide direction vectorscale- length between fixed and asked coordinate- Returns:
- the
Coordinatea given length-unit away from fixedCoordinatein 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 fixedCoordinatein vector (fixed to floating) direction.- Parameters:
fixed- fixed relative coordinatefloating- coordinate to provide direction vector- Returns:
- coordinate 1 length-unit away from fixed
Coordinatein 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 vectorsv0andv1have 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
Vector2Dwith 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
Vector2Dwith negated y-Coordinate of avector.
-
pointInAngle
public static boolean pointInAngle(GeometryAngle geometryAngle, org.locationtech.jts.geom.Coordinate coordinate)
- Parameters:
geometryAngle- the viewGeometryAnglethe method looks upon searching the given pointcoordinate- theCoordinate, we want to know, whether it lies in thegeometryAngle.- Returns:
true, ifcoordinatelies 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 givenCoordinatelies inside the given angle, which is defined byright,centerandleft.- 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, ifcoordinatelies 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- theCoordinateof theSearcher.treasure- theCoordinateof 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- theCoordinateof theSearcher.treasure- theCoordinateof 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, whichgeometriesis 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, aenvelopeis 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 borderLineSegmentsinfinite- infinite line- Returns:
- the intersections between the infinite line extension and the boundary
LineSegments
-
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 theConvexHullfor a list ofCoordinates.- 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_DISTANCEandPreferenceService.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 asPolygonhint- theAngleHint- Returns:
trueif the givenangleHintis a bad hint, related on theStrategyFromPaper.falseotherwise.
-
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 intersectionPoints, from a line and a circle. The line is described as going frompointAtopointBand the circle ist described by having his center oncenterand a radius ofradius.- Parameters:
pointA- the firstPointof the linepointB- the secondPointof the linecenter- the centerPointof the circleradius- the radius of the circle- Returns:
- a list, containing 0, 1 or 2
Points, 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-dimensionalPoints.- Parameters:
pointA- the firstPoint, forming a linepointB- the secondPoint, forming a line- Returns:
- the linear equation
y = xm + bof the line,pointAandpointBform. The linear equation is returned by a Pair containing the gradientmand the y-valueb, where the line cuts the y-axis. - Throws:
java.lang.IllegalArgumentException- ifpointAandpointBdoes 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 + bof the orthogonal line to a line with gradientgradient, running through pointpoint. The linear equation is returned by a Pair containing the gradientmand the y-valueb, where the line cuts the y-axis. - Throws:
java.lang.IllegalArgumentException- if thegradientis 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 gradientmand the y-coordinateb, intersecting the y-axes.function2-y = m2*x + b2, given as a pair containing the gradientmand the y-coordinateb, intersecting the y-axes.- Returns:
- the intersection
Point, offunction1andfunction2. Thus, we return - Throws:
java.lang.IllegalArgumentException- if both functions have no intersection or are equal.
-
-