package org.apache.lucene.spatial3d.geom;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.IOException;
class dXYdZSolid extends BaseXYZSolid {
protected final double X;
protected final double minY;
protected final double maxY;
protected final double Z;
protected final GeoPoint[] surfacePoints;
public dXYdZSolid(final PlanetModel planetModel,
final double X,
final double minY,
final double maxY,
final double Z) {
super(planetModel);
if (maxY - minY < Vector.MINIMUM_RESOLUTION)
throw new IllegalArgumentException("Y values in wrong order or identical");
this.X = X;
this.minY = minY;
this.maxY = maxY;
this.Z = Z;
final Plane xPlane = new Plane(xUnitVector,-X);
final Plane zPlane = new Plane(zUnitVector,-Z);
final SidedPlane minYPlane = new SidedPlane(0.0,maxY,0.0,yUnitVector,-minY);
final SidedPlane maxYPlane = new SidedPlane(0.0,minY,0.0,yUnitVector,-maxY);
surfacePoints = xPlane.findIntersections(planetModel,zPlane,minYPlane,maxYPlane);
}
public dXYdZSolid(final PlanetModel planetModel, final InputStream inputStream) throws IOException {
this(planetModel,
SerializableObject.readDouble(inputStream),
SerializableObject.readDouble(inputStream),
SerializableObject.readDouble(inputStream),
SerializableObject.readDouble(inputStream));
}
@Override
public void write(final OutputStream outputStream) throws IOException {
SerializableObject.writeDouble(outputStream, X);
SerializableObject.writeDouble(outputStream, minY);
SerializableObject.writeDouble(outputStream, maxY);
SerializableObject.writeDouble(outputStream, Z);
}
@Override
protected GeoPoint[] getEdgePoints() {
return surfacePoints;
}
@Override
public boolean isWithin(final double x, final double y, final double z) {
for (final GeoPoint p : surfacePoints) {
if (p.isIdentical(x,y,z))
return true;
}
return false;
}
@Override
public int getRelationship(final GeoShape path) {
final int insideRectangle = isShapeInsideArea(path);
if (insideRectangle == SOME_INSIDE) {
return OVERLAPS;
}
final int insideShape = isAreaInsideShape(path);
if (insideShape == SOME_INSIDE) {
return OVERLAPS;
}
if (insideRectangle == ALL_INSIDE && insideShape == ALL_INSIDE) {
return OVERLAPS;
}
if (insideRectangle == ALL_INSIDE) {
return WITHIN;
}
if (insideShape == ALL_INSIDE) {
return CONTAINS;
}
return DISJOINT;
}
@Override
public boolean equals(Object o) {
if (!(o instanceof dXYdZSolid))
return false;
dXYdZSolid other = (dXYdZSolid) o;
if (!super.equals(other) || surfacePoints.length != other.surfacePoints.length ) {
return false;
}
for (int i = 0; i < surfacePoints.length; i++) {
if (!surfacePoints[i].equals(other.surfacePoints[i]))
return false;
}
return true;
}
@Override
public int hashCode() {
int result = super.hashCode();
for (final GeoPoint p : surfacePoints) {
result = 31 * result + p.hashCode();
}
return result;
}
@Override
public String toString() {
final StringBuilder sb = new StringBuilder();
for (final GeoPoint p : surfacePoints) {
sb.append(" ").append(p).append(" ");
}
return "dXYdZSolid: {planetmodel="+planetModel+", "+sb.toString()+"}";
}
}