package org.apache.lucene.spatial3d.geom;
import java.io.InputStream;
import java.io.IOException;
class GeoDegeneratePoint extends GeoPoint implements GeoPointShape {
protected final PlanetModel planetModel;
protected final GeoPoint[] edgePoints;
public GeoDegeneratePoint(final PlanetModel planetModel, final double lat, final double lon) {
super(planetModel, lat, lon);
this.planetModel = planetModel;
this.edgePoints = new GeoPoint[]{this};
}
public GeoDegeneratePoint(final PlanetModel planetModel, final InputStream inputStream) throws IOException {
super(planetModel, inputStream);
this.planetModel = planetModel;
this.edgePoints = new GeoPoint[]{this};
}
@Override
public PlanetModel getPlanetModel() {
return planetModel;
}
@Override
public GeoBBox expand(final double angle) {
final double newTopLat = latitude + angle;
final double newBottomLat = latitude - angle;
final double newLeftLon = longitude - angle;
final double newRightLon = longitude + angle;
return GeoBBoxFactory.makeGeoBBox(planetModel, newTopLat, newBottomLat, newLeftLon, newRightLon);
}
@Override
public GeoPoint[] getEdgePoints() {
return edgePoints;
}
@Override
public boolean intersects(final Plane plane, final GeoPoint[] notablePoints, final Membership... bounds) {
if (!plane.evaluateIsZero(this))
return false;
for (Membership m : bounds) {
if (!m.isWithin(this))
return false;
}
return true;
}
@Override
public boolean intersects(GeoShape geoShape) {
return geoShape.isWithin(this);
}
@Override
public void getBounds(Bounds bounds) {
bounds.addPoint(this);
}
@Override
public double computeOutsideDistance(final DistanceStyle distanceStyle, final GeoPoint point) {
return distanceStyle.computeDistance(this, point);
}
@Override
public double computeOutsideDistance(final DistanceStyle distanceStyle, final double x, final double y, final double z) {
return distanceStyle.computeDistance(this, x,y,z);
}
@Override
public boolean equals(Object o) {
if (!(o instanceof GeoDegeneratePoint))
return false;
GeoDegeneratePoint other = (GeoDegeneratePoint) o;
return super.equals(other) && other.latitude == latitude && other.longitude == longitude;
}
@Override
public String toString() {
return "GeoDegeneratePoint: {planetmodel="+planetModel+", lat=" + latitude + "(" + latitude * 180.0 / Math.PI + "), lon=" + longitude + "(" + longitude * 180.0 / Math.PI + ")}";
}
@Override
public boolean isWithin(final Vector point) {
return isWithin(point.x, point.y, point.z);
}
@Override
public boolean isWithin(final double x, final double y, final double z) {
return this.isIdentical(x, y, z);
}
@Override
public double getRadius() {
return 0.0;
}
@Override
public GeoPoint getCenter() {
return this;
}
@Override
public int getRelationship(final GeoShape shape) {
if (shape.isWithin(this)) {
return CONTAINS;
}
return DISJOINT;
}
@Override
public double computeDistance(final DistanceStyle distanceStyle, final double x, final double y, final double z) {
if (isWithin(x,y,z))
return 0.0;
return Double.POSITIVE_INFINITY;
}
@Override
public void getDistanceBounds(final Bounds bounds, final DistanceStyle distanceStyle, final double distanceValue) {
getBounds(bounds);
}
}