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