{ 41.58361, 8.77572 }, { 41.38000, 9.22975 }
});
RegionFactory<Sphere2D> factory = new RegionFactory<Sphere2D>();
SphericalPolygonsSet zone = (SphericalPolygonsSet) factory.union(continental, corsica);
EnclosingBall<Sphere2D, S2Point> enclosing = zone.getEnclosingCap();
Vector3D enclosingCenter = ((S2Point) enclosing.getCenter()).getVector();
double step = FastMath.toRadians(0.1);
for (Vertex loopStart : zone.getBoundaryLoops()) {
int count = 0;
for (Vertex v = loopStart; count == 0 || v != loopStart; v = v.getOutgoing().getEnd()) {
++count;
for (int i = 0; i < FastMath.ceil(v.getOutgoing().getLength() / step); ++i) {
Vector3D p = v.getOutgoing().getPointAt(i * step);
Assert.assertTrue(Vector3D.angle(p, enclosingCenter) <= enclosing.getRadius());
}
}
}
S2Point supportPointA = s2Point(48.68416, -4.59234);
S2Point supportPointB = s2Point(41.38000, 9.22975);
Assert.assertEquals(enclosing.getRadius(), supportPointA.distance(enclosing.getCenter()), 1.0e-10);
Assert.assertEquals(enclosing.getRadius(), supportPointB.distance(enclosing.getCenter()), 1.0e-10);
Assert.assertEquals(0.5 * supportPointA.distance(supportPointB), enclosing.getRadius(), 1.0e-10);
Assert.assertEquals(2, enclosing.getSupportSize());
EnclosingBall<Sphere2D, S2Point> continentalInscribed =
((SphericalPolygonsSet) factory.getComplement(continental)).getEnclosingCap();
Vector3D continentalCenter = ((S2Point) continentalInscribed.getCenter()).getVector();
Assert.assertEquals(2.2, FastMath.toDegrees(FastMath.PI - continentalInscribed.getRadius()), 0.1);
for (Vertex loopStart : continental.getBoundaryLoops()) {
int count = 0;
for (Vertex v = loopStart; count == 0 || v != loopStart; v = v.getOutgoing().getEnd()) {
++count;
for (int i = 0; i < FastMath.ceil(v.getOutgoing().getLength() / step); ++i) {
Vector3D p = v.getOutgoing().getPointAt(i * step);
Assert.assertTrue(Vector3D.angle(p, continentalCenter) <= continentalInscribed.getRadius());
}
}
}
EnclosingBall<Sphere2D, S2Point> corsicaInscribed =
((SphericalPolygonsSet) factory.getComplement(corsica)).getEnclosingCap();
Vector3D corsicaCenter = ((S2Point) corsicaInscribed.getCenter()).getVector();
Assert.assertEquals(0.34, FastMath.toDegrees(FastMath.PI - corsicaInscribed.getRadius()), 0.01);
for (Vertex loopStart : corsica.getBoundaryLoops()) {
int count = 0;
for (Vertex v = loopStart; count == 0 || v != loopStart; v = v.getOutgoing().getEnd()) {
++count;
for (int i = 0; i < FastMath.ceil(v.getOutgoing().getLength() / step); ++i) {
Vector3D p = v.getOutgoing().getPointAt(i * step);
Assert.assertTrue(Vector3D.angle(p, corsicaCenter) <= corsicaInscribed.getRadius());
}
}
}