/** * Returns the singleton point of this shape. Only applicable for point and circle shapes. * * @return */ public Point getPoint() { Preconditions.checkArgument(getType()==Type.POINT || getType()==Type.CIRCLE,"Shape does not have a single point"); return new Point(shape.getCenter().getY(), shape.getCenter().getX()); }
/** * The <code>Y</code> coordinate of where the circle axis intersect. */ protected double getYAxis() { return point.getY(); }
@Override public double calcBoxByDistFromPt_yHorizAxisDEG(Point from, double distDEG, SpatialContext ctx) { return from.getY(); }
/** * All {@link Point} implementations should use this definition of {@link Object#equals(Object)}. */ public static boolean equals(Point thiz, Object o) { assert thiz != null; if (thiz == o) return true; if (!(o instanceof Point)) return false; Point point = (Point) o; if (Double.compare(point.getX(), thiz.getX()) != 0) return false; if (Double.compare(point.getY(), thiz.getY()) != 0) return false; return true; }
@Override public boolean within(Point from, double toX, double toY, double distance) { double deltaX = from.getX() - toX; double deltaY = from.getY() - toY; return deltaX*deltaX + deltaY*deltaY <= distance*distance; }
/** * All {@link Point} implementations should use this definition of {@link Object#hashCode()}. */ public static int hashCode(Point thiz) { int result; long temp; temp = thiz.getX() != +0.0d ? Double.doubleToLongBits(thiz.getX()) : 0L; result = (int) (temp ^ (temp >>> 32)); temp = thiz.getY() != +0.0d ? Double.doubleToLongBits(thiz.getY()) : 0L; result = 31 * result + (int) (temp ^ (temp >>> 32)); return result; } }
/** INTERNAL AKA lineToPointDistance */ public double distanceUnbuffered(Point c) { if (Double.isInfinite(slope)) return Math.abs(c.getX() - intercept); // http://math.ucsd.edu/~wgarner/math4c/derivations/distance/distptline.htm double num = Math.abs(c.getY() - slope * c.getX() - intercept); return num * distDenomInv; }
InfBufLine(double slope, Point point, double buf) { assert !Double.isNaN(slope); this.slope = slope; if (Double.isInfinite(slope)) { intercept = point.getX(); distDenomInv = Double.NaN; } else { intercept = point.getY() - slope * point.getX(); distDenomInv = 1 / Math.sqrt(slope * slope + 1); } this.buf = buf; }
@Override public double distance(Point from, double toX, double toY) { double xSquaredPlusYSquared = distanceSquared(from.getX(), from.getY(), toX, toY); if (squared) return xSquaredPlusYSquared; return Math.sqrt(xSquaredPlusYSquared); }
@Override public double distance(Point from, Point to) { return distance(from, to.getX(), to.getY()); }
@Override public Rectangle calcBoxByDistFromPt(Point from, double distDEG, SpatialContext ctx, Rectangle reuse) { double minX = from.getX() - distDEG; double maxX = from.getX() + distDEG; double minY = from.getY() - distDEG; double maxY = from.getY() + distDEG; if (reuse == null) { return ctx.makeRectangle(minX, maxX, minY, maxY); } else { reuse.reset(minX, maxX, minY, maxY); return reuse; } }
@Override public double calcBoxByDistFromPt_yHorizAxisDEG(Point from, double distDEG, SpatialContext ctx) { return DistanceUtils.calcBoxByDistFromPt_latHorizAxisDEG(from.getY(), from.getX(), distDEG); }
@Override public Rectangle calcBoxByDistFromPt(Point from, double distDEG, SpatialContext ctx, Rectangle reuse) { return DistanceUtils.calcBoxByDistFromPtDEG(from.getY(), from.getX(), distDEG, ctx, reuse); }
public SpatialRelation relate(Rectangle r) { //Note: Surprisingly complicated! //--We start by leveraging the fact we have a calculated bbox that is "cheaper" than use of DistanceCalculator. final SpatialRelation bboxSect = enclosingBox.relate(r); if (bboxSect == SpatialRelation.DISJOINT || bboxSect == SpatialRelation.WITHIN) return bboxSect; else if (bboxSect == SpatialRelation.CONTAINS && enclosingBox.equals(r))//nasty identity edge-case return SpatialRelation.WITHIN; //bboxSect is INTERSECTS or CONTAINS //The result can be DISJOINT, CONTAINS, or INTERSECTS (not WITHIN) return relateRectanglePhase2(r, bboxSect); }
public void writePoint(DataOutput dataOutput, Point pt) throws IOException { writeDim(dataOutput, pt.getX()); writeDim(dataOutput, pt.getY()); }
@Override public Point pointOnBearing(Point from, double distDEG, double bearingDEG, SpatialContext ctx, Point reuse) { if (distDEG == 0) { if (reuse == null) return from; reuse.reset(from.getX(), from.getY()); return reuse; } Point result = DistanceUtils.pointOnBearingRAD( toRadians(from.getY()), toRadians(from.getX()), toRadians(distDEG), toRadians(bearingDEG), ctx, reuse);//output result is in radians result.reset(toDegrees(result.getX()), toDegrees(result.getY())); return result; }
@Override public final double distance(Point from, double toX, double toY) { return toDegrees(distanceLatLonRAD(toRadians(from.getY()), toRadians(from.getX()), toRadians(toY), toRadians(toX))); }
public SpatialRelation relate(Point pt) { if (!getBoundingBox().relate(pt).intersects()) return SpatialRelation.DISJOINT; Geometry ptGeom; if (pt instanceof JtsPoint) ptGeom = ((JtsPoint)pt).getGeom(); else ptGeom = ctx.getGeometryFactory().createPoint(new Coordinate(pt.getX(), pt.getY())); return relate(ptGeom);//is point-optimized }