package org.apache.commons.math3.geometry.spherical.twod;
import org.apache.commons.math3.geometry.euclidean.threed.Vector3D;
import org.apache.commons.math3.geometry.partitioning.AbstractSubHyperplane;
import org.apache.commons.math3.geometry.partitioning.Hyperplane;
import org.apache.commons.math3.geometry.partitioning.Region;
import org.apache.commons.math3.geometry.spherical.oned.Arc;
import org.apache.commons.math3.geometry.spherical.oned.ArcsSet;
import org.apache.commons.math3.geometry.spherical.oned.Sphere1D;
import org.apache.commons.math3.util.FastMath;
public class SubCircle extends AbstractSubHyperplane<Sphere2D, Sphere1D> {
public SubCircle(final Hyperplane<Sphere2D> hyperplane,
final Region<Sphere1D> remainingRegion) {
super(hyperplane, remainingRegion);
}
@Override
protected AbstractSubHyperplane<Sphere2D, Sphere1D> buildNew(final Hyperplane<Sphere2D> hyperplane,
final Region<Sphere1D> remainingRegion) {
return new SubCircle(hyperplane, remainingRegion);
}
@Override
public SplitSubHyperplane<Sphere2D> split(final Hyperplane<Sphere2D> hyperplane) {
final Circle thisCircle = (Circle) getHyperplane();
final Circle otherCircle = (Circle) hyperplane;
final double angle = Vector3D.angle(thisCircle.getPole(), otherCircle.getPole());
if (angle < thisCircle.getTolerance() || angle > FastMath.PI - thisCircle.getTolerance()) {
return new SplitSubHyperplane<Sphere2D>(null, null);
} else {
final Arc arc = thisCircle.getInsideArc(otherCircle);
final ArcsSet.Split split = ((ArcsSet) getRemainingRegion()).split(arc);
final ArcsSet plus = split.getPlus();
final ArcsSet minus = split.getMinus();
return new SplitSubHyperplane<Sphere2D>(plus == null ? null : new SubCircle(thisCircle.copySelf(), plus),
minus == null ? null : new SubCircle(thisCircle.copySelf(), minus));
}
}
}