package org.apache.lucene.spatial3d.geom;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.IOException;
class GeoDegenerateLatitudeZone extends GeoBaseBBox {
protected final double latitude;
protected final double sinLatitude;
protected final Plane plane;
protected final GeoPoint interiorPoint;
protected final GeoPoint[] edgePoints;
protected final static GeoPoint[] planePoints = new GeoPoint[0];
public GeoDegenerateLatitudeZone(final PlanetModel planetModel, final double latitude) {
super(planetModel);
this.latitude = latitude;
this.sinLatitude = Math.sin(latitude);
double cosLatitude = Math.cos(latitude);
this.plane = new Plane(planetModel, sinLatitude);
interiorPoint = new GeoPoint(planetModel, sinLatitude, 0.0, cosLatitude, 1.0);
edgePoints = new GeoPoint[]{interiorPoint};
}
public GeoDegenerateLatitudeZone(final PlanetModel planetModel, final InputStream inputStream) throws IOException {
this(planetModel, SerializableObject.readDouble(inputStream));
}
@Override
public void write(final OutputStream outputStream) throws IOException {
SerializableObject.writeDouble(outputStream, latitude);
}
@Override
public GeoBBox expand(final double angle) {
double newTopLat = latitude + angle;
double newBottomLat = latitude - angle;
return GeoBBoxFactory.makeGeoBBox(planetModel, newTopLat, newBottomLat, -Math.PI, Math.PI);
}
@Override
public boolean isWithin(final double x, final double y, final double z) {
return Math.abs(z - this.sinLatitude) < 1e-10;
}
@Override
public double getRadius() {
return Math.PI;
}
@Override
public GeoPoint getCenter() {
return interiorPoint;
}
@Override
public GeoPoint[] getEdgePoints() {
return edgePoints;
}
@Override
public boolean intersects(final Plane p, final GeoPoint[] notablePoints, final Membership... bounds) {
return p.intersects(planetModel, plane, notablePoints, planePoints, bounds);
}
@Override
public boolean intersects(final GeoShape geoShape) {
return geoShape.intersects(plane, planePoints);
}
@Override
public void getBounds(Bounds bounds) {
super.getBounds(bounds);
bounds.noLongitudeBound()
.addHorizontalPlane(planetModel, latitude, plane);
}
@Override
public int getRelationship(final GeoShape path) {
if (intersects(path)) {
return OVERLAPS;
}
if (path.isWithin(interiorPoint)) {
return CONTAINS;
}
return DISJOINT;
}
@Override
protected double outsideDistance(final DistanceStyle distanceStyle, final double x, final double y, final double z) {
return distanceStyle.computeDistance(planetModel, plane, x,y,z);
}
@Override
public boolean equals(Object o) {
if (!(o instanceof GeoDegenerateLatitudeZone))
return false;
GeoDegenerateLatitudeZone other = (GeoDegenerateLatitudeZone) o;
return super.equals(other) && other.latitude == latitude;
}
@Override
public int hashCode() {
int result = super.hashCode();
long temp = Double.doubleToLongBits(latitude);
result = 31 * result + (int) (temp ^ (temp >>> 32));
return result;
}
@Override
public String toString() {
return "GeoDegenerateLatitudeZone: {planetmodel="+planetModel+", lat=" + latitude + "(" + latitude * 180.0 / Math.PI + ")}";
}
}