Class CartesianDistCalc
- java.lang.Object
-
- org.locationtech.spatial4j.distance.AbstractDistanceCalculator
-
- org.locationtech.spatial4j.distance.CartesianDistCalc
-
- All Implemented Interfaces:
DistanceCalculator
public class CartesianDistCalc extends AbstractDistanceCalculator
Calculates based on Euclidean / Cartesian 2d plane.
-
-
Field Summary
Fields Modifier and Type Field Description static CartesianDistCalc
INSTANCE
static CartesianDistCalc
INSTANCE_SQUARED
private boolean
squared
-
Constructor Summary
Constructors Constructor Description CartesianDistCalc()
CartesianDistCalc(boolean squared)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description double
area(Circle circle)
double
area(Rectangle rect)
Rectangle
calcBoxByDistFromPt(Point from, double distDEG, SpatialContext ctx, Rectangle reuse)
Calculates the bounding box of a circle, as specified by its center point and distance.double
calcBoxByDistFromPt_yHorizAxisDEG(Point from, double distDEG, SpatialContext ctx)
TheY
coordinate of the horizontal axis of a circle that has maximum width.double
distance(Point from, double toX, double toY)
The distance betweenfrom
andPoint(toX,toY)
.private static double
distanceSquared(double fromX, double fromY, double toX, double toY)
double
distanceToLineSegment(Point point, double vX, double vY, double wX, double wY)
Distance from point to a line segment formed between points 'v' and 'w'.boolean
equals(java.lang.Object o)
int
hashCode()
Point
pointOnBearing(Point from, double distDEG, double bearingDEG, SpatialContext ctx, Point reuse)
Calculates where a destination point is given an origin (from
) distance, and bearing (given in degrees -- 0-360).boolean
within(Point from, double toX, double toY, double distance)
Returns true if the distance between from and to is <= distance.-
Methods inherited from class org.locationtech.spatial4j.distance.AbstractDistanceCalculator
distance, toString
-
-
-
-
Field Detail
-
INSTANCE
public static final CartesianDistCalc INSTANCE
-
INSTANCE_SQUARED
public static final CartesianDistCalc INSTANCE_SQUARED
-
squared
private final boolean squared
-
-
Constructor Detail
-
CartesianDistCalc
public CartesianDistCalc()
-
CartesianDistCalc
public CartesianDistCalc(boolean squared)
- Parameters:
squared
- Set to true to haveAbstractDistanceCalculator.distance(org.locationtech.spatial4j.shape.Point, org.locationtech.spatial4j.shape.Point)
return the square of the correct answer. This is a performance optimization used when sorting in which the actual distance doesn't matter so long as the sort order is consistent.
-
-
Method Detail
-
distance
public double distance(Point from, double toX, double toY)
Description copied from interface:DistanceCalculator
The distance betweenfrom
andPoint(toX,toY)
.
-
distanceSquared
private static double distanceSquared(double fromX, double fromY, double toX, double toY)
-
distanceToLineSegment
public double distanceToLineSegment(Point point, double vX, double vY, double wX, double wY)
Distance from point to a line segment formed between points 'v' and 'w'. It respects the "squared" option.
-
within
public boolean within(Point from, double toX, double toY, double distance)
Description copied from interface:DistanceCalculator
Returns true if the distance between from and to is <= distance.- Specified by:
within
in interfaceDistanceCalculator
- Overrides:
within
in classAbstractDistanceCalculator
-
pointOnBearing
public Point pointOnBearing(Point from, double distDEG, double bearingDEG, SpatialContext ctx, Point reuse)
Description copied from interface:DistanceCalculator
Calculates where a destination point is given an origin (from
) distance, and bearing (given in degrees -- 0-360). If reuse is given, then this method may reset() it and return it.
-
calcBoxByDistFromPt
public Rectangle calcBoxByDistFromPt(Point from, double distDEG, SpatialContext ctx, Rectangle reuse)
Description copied from interface:DistanceCalculator
Calculates the bounding box of a circle, as specified by its center point and distance.
-
calcBoxByDistFromPt_yHorizAxisDEG
public double calcBoxByDistFromPt_yHorizAxisDEG(Point from, double distDEG, SpatialContext ctx)
Description copied from interface:DistanceCalculator
TheY
coordinate of the horizontal axis of a circle that has maximum width. On a 2D plane, this result is alwaysfrom.getY()
but, perhaps surprisingly, on a sphere it is going to be slightly different.
-
area
public double area(Rectangle rect)
-
area
public double area(Circle circle)
-
equals
public boolean equals(java.lang.Object o)
- Overrides:
equals
in classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
-