/** * 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()); }
@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; } double bearingRAD = DistanceUtils.toRadians(bearingDEG); double x = from.getX() + Math.sin(bearingRAD) * distDEG; double y = from.getY() + Math.cos(bearingRAD) * distDEG; if (reuse == null) { return ctx.makePoint(x, y); } else { reuse.reset(x, y); return reuse; } }
@Override public boolean isEmpty() { return point.isEmpty(); }
/** * The <code>Y</code> coordinate of where the circle axis intersect. */ protected double getYAxis() { return point.getY(); }
/** * The <code>X</code> coordinate of where the circle axis intersect. */ protected double getXAxis() { return point.getX(); }
return ctx.makePoint(lon2, lat2); } else { reuse.reset(lon2, lat2);//x y return reuse;
@Override public double calcBoxByDistFromPt_yHorizAxisDEG(Point from, double distDEG, SpatialContext ctx) { return from.getY(); }
@Override public double getX() { return s.getX(); }
@Override public void reset(double x, double y, double radiusDEG) { assert ! isEmpty(); point.reset(x, y); this.radiusDEG = radiusDEG; this.enclosingBox = ctx.getDistCalc().calcBoxByDistFromPt(point, this.radiusDEG, ctx, enclosingBox); }
@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; }
/** * Calls {@link DistanceUtils#calcLonDegreesAtLat(double, double)} given pA or pB's latitude; * whichever is farthest. It's useful to expand a buffer of a line segment when used in * a geospatial context to cover the desired area. */ public static double expandBufForLongitudeSkew(Point pA, Point pB, double buf) { double absA = Math.abs(pA.getY()); double absB = Math.abs(pB.getY()); double maxLat = Math.max(absA, absB); double newBuf = DistanceUtils.calcLonDegreesAtLat(maxLat, buf); // if (newBuf + maxLat >= 90) { // //TODO substitute spherical cap ? // } assert newBuf >= buf; return newBuf; }
public static void cornerByQuadrant(Rectangle r, int cornerQuad, Point out) { double x = (cornerQuad == 1 || cornerQuad == 4) ? r.getMaxX() : r.getMinX(); double y = (cornerQuad == 1 || cornerQuad == 2) ? r.getMaxY() : r.getMinY(); out.reset(x, y); }
@Override public boolean isEmpty() { return pA.isEmpty(); }
@Override public double getY() { return s.getY(); }
@Override public void reset(double x, double y) { s.reset(x, y); }
public CircleImpl(Point p, double radiusDEG, SpatialContext ctx) { super(ctx); //We assume any validation of params already occurred (including bounding dist) this.point = p; this.radiusDEG = point.isEmpty() ? Double.NaN : radiusDEG; this.enclosingBox = point.isEmpty() ? ctx.makeRectangle(Double.NaN, Double.NaN, Double.NaN, Double.NaN) : ctx.getDistCalc().calcBoxByDistFromPt(point, this.radiusDEG, ctx, null); }
/** * 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; }