package org.apache.lucene.spatial3d.geom;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.IOException;
class GeoSouthLatitudeZone extends GeoBaseBBox {
protected final double topLat;
protected final double cosTopLat;
protected final SidedPlane topPlane;
protected final GeoPoint interiorPoint;
protected final static GeoPoint[] planePoints = new GeoPoint[0];
protected final GeoPoint topBoundaryPoint;
protected final GeoPoint[] edgePoints;
public GeoSouthLatitudeZone(final PlanetModel planetModel, final double topLat) {
super(planetModel);
this.topLat = topLat;
final double sinTopLat = Math.sin(topLat);
this.cosTopLat = Math.cos(topLat);
final double middleLat = (topLat - Math.PI * 0.5) * 0.5;
final double sinMiddleLat = Math.sin(middleLat);
this.interiorPoint = new GeoPoint(planetModel, sinMiddleLat, 0.0, Math.sqrt(1.0 - sinMiddleLat * sinMiddleLat), 1.0);
this.topBoundaryPoint = new GeoPoint(planetModel, sinTopLat, 0.0, Math.sqrt(1.0 - sinTopLat * sinTopLat), 1.0);
this.topPlane = new SidedPlane(interiorPoint, planetModel, sinTopLat);
this.edgePoints = new GeoPoint[]{topBoundaryPoint};
}
public GeoSouthLatitudeZone(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, topLat);
}
@Override
public GeoBBox expand(final double angle) {
final double newTopLat = topLat + angle;
final double newBottomLat = -Math.PI * 0.5;
return GeoBBoxFactory.makeGeoBBox(planetModel, newTopLat, newBottomLat, -Math.PI, Math.PI);
}
@Override
public boolean isWithin(final double x, final double y, final double z) {
return topPlane.isWithin(x, y, z);
}
@Override
public double getRadius() {
if (topLat > 0.0)
return Math.PI;
double maxCosLat = cosTopLat;
return maxCosLat * 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, topPlane, notablePoints, planePoints, bounds);
}
@Override
public boolean intersects(final GeoShape geoShape) {
return geoShape.intersects(topPlane, planePoints);
}
@Override
public void getBounds(Bounds bounds) {
super.getBounds(bounds);
bounds
.addHorizontalPlane(planetModel, topLat, topPlane);
}
@Override
protected double outsideDistance(final DistanceStyle distanceStyle, final double x, final double y, final double z) {
return distanceStyle.computeDistance(planetModel, topPlane, x,y,z);
}
@Override
public boolean equals(Object o) {
if (!(o instanceof GeoSouthLatitudeZone))
return false;
GeoSouthLatitudeZone other = (GeoSouthLatitudeZone) o;
return super.equals(other) && other.topBoundaryPoint.equals(topBoundaryPoint);
}
@Override
public int hashCode() {
int result = super.hashCode();
result = 31 * result + topBoundaryPoint.hashCode();
return result;
}
@Override
public String toString() {
return "GeoSouthLatitudeZone: {planetmodel="+planetModel+", toplat=" + topLat + "(" + topLat * 180.0 / Math.PI + ")}";
}
}