ArcsSet extends AbstractRegion<Sphere1D, Sphere1D> implements Iterable<double[]> { public List<Arc> asList() { final List<Arc> list = new ArrayList<Arc>(); for (final double[] a : this) { list.add(new Arc(a[0], a[1], getTolerance())); } return list; } ArcsSet(final double tolerance);  ArcsSet(final double lower, final double upper, final double tolerance);  ArcsSet(final BSPTree<Sphere1D> tree, final double tolerance);  ArcsSet(final Collection<SubHyperplane<Sphere1D>> boundary, final double tolerance); @Override ArcsSet buildNew(final BSPTree<Sphere1D> tree); @Override BoundaryProjection<Sphere1D> projectToBoundary(final Point<Sphere1D> point); List<Arc> asList(); Iterator<double[]> iterator(); Side side(final Arc arc); Split split(final Arc arc);  }
@Test public void testArc() { ArcsSet set = new ArcsSet(2.3, 5.7, 1.0e-10); Assert.assertEquals(3.4, set.getSize(), 1.0e-10); Assert.assertEquals(1.0e-10, set.getTolerance(), 1.0e-20); Assert.assertEquals(Region.Location.BOUNDARY, set.checkPoint(new S1Point(2.3))); Assert.assertEquals(Region.Location.BOUNDARY, set.checkPoint(new S1Point(5.7))); Assert.assertEquals(Region.Location.OUTSIDE, set.checkPoint(new S1Point(1.2))); Assert.assertEquals(Region.Location.OUTSIDE, set.checkPoint(new S1Point(8.5))); Assert.assertEquals(Region.Location.INSIDE, set.checkPoint(new S1Point(8.7))); Assert.assertEquals(Region.Location.INSIDE, set.checkPoint(new S1Point(3.0))); Assert.assertEquals(1, set.asList().size()); Assert.assertEquals(2.3, set.asList().get(0).getInf(), 1.0e-10); Assert.assertEquals(5.7, set.asList().get(0).getSup(), 1.0e-10); }
@Test public void testWrapAround2PiArc() { ArcsSet set = new ArcsSet(5.7 - MathUtils.TWO_PI, 2.3, 1.0e-10); Assert.assertEquals(MathUtils.TWO_PI - 3.4, set.getSize(), 1.0e-10); Assert.assertEquals(1.0e-10, set.getTolerance(), 1.0e-20); Assert.assertEquals(Region.Location.BOUNDARY, set.checkPoint(new S1Point(2.3))); Assert.assertEquals(Region.Location.BOUNDARY, set.checkPoint(new S1Point(5.7))); Assert.assertEquals(Region.Location.INSIDE, set.checkPoint(new S1Point(1.2))); Assert.assertEquals(Region.Location.INSIDE, set.checkPoint(new S1Point(8.5))); Assert.assertEquals(Region.Location.OUTSIDE, set.checkPoint(new S1Point(8.7))); Assert.assertEquals(Region.Location.OUTSIDE, set.checkPoint(new S1Point(3.0))); Assert.assertEquals(1, set.asList().size()); Assert.assertEquals(5.7, set.asList().get(0).getInf(), 1.0e-10); Assert.assertEquals(2.3 + MathUtils.TWO_PI, set.asList().get(0).getSup(), 1.0e-10); }
@Test public void testFullEqualEndPoints() { ArcsSet set = new ArcsSet(1.0, 1.0, 1.0e-10); Assert.assertEquals(1.0e-10, set.getTolerance(), 1.0e-20); Assert.assertEquals(Region.Location.INSIDE, set.checkPoint(new S1Point(9.0))); for (double alpha = -20.0; alpha <= 20.0; alpha += 0.1) { Assert.assertEquals(Region.Location.INSIDE, set.checkPoint(new S1Point(alpha))); } Assert.assertEquals(1, set.asList().size()); Assert.assertEquals(0.0, set.asList().get(0).getInf(), 1.0e-10); Assert.assertEquals(2 * FastMath.PI, set.asList().get(0).getSup(), 1.0e-10); Assert.assertEquals(2 * FastMath.PI, set.getSize(), 1.0e-10); }
@Test public void testFullCircle() { ArcsSet set = new ArcsSet(1.0e-10); Assert.assertEquals(1.0e-10, set.getTolerance(), 1.0e-20); Assert.assertEquals(Region.Location.INSIDE, set.checkPoint(new S1Point(9.0))); for (double alpha = -20.0; alpha <= 20.0; alpha += 0.1) { Assert.assertEquals(Region.Location.INSIDE, set.checkPoint(new S1Point(alpha))); } Assert.assertEquals(1, set.asList().size()); Assert.assertEquals(0.0, set.asList().get(0).getInf(), 1.0e-10); Assert.assertEquals(2 * FastMath.PI, set.asList().get(0).getSup(), 1.0e-10); Assert.assertEquals(2 * FastMath.PI, set.getSize(), 1.0e-10); }
@Test public void testEmpty() { ArcsSet empty = (ArcsSet) new RegionFactory<Sphere1D>().getComplement(new ArcsSet(1.0e-10)); Assert.assertEquals(1.0e-10, empty.getTolerance(), 1.0e-20); Assert.assertEquals(0.0, empty.getSize(), 1.0e-10); Assert.assertTrue(empty.asList().isEmpty()); }
@Test public void testTiny() { ArcsSet tiny = new ArcsSet(0.0, Precision.SAFE_MIN / 2, 1.0e-10); Assert.assertEquals(1.0e-10, tiny.getTolerance(), 1.0e-20); Assert.assertEquals(Precision.SAFE_MIN / 2, tiny.getSize(), 1.0e-10); Assert.assertEquals(1, tiny.asList().size()); Assert.assertEquals(0.0, tiny.asList().get(0).getInf(), 1.0e-10); Assert.assertEquals(Precision.SAFE_MIN / 2, tiny.asList().get(0).getSup(), 1.0e-10); }
@Test public void testSpecialConstruction() { List<SubHyperplane<Sphere1D>> boundary = new ArrayList<SubHyperplane<Sphere1D>>(); boundary.add(new LimitAngle(new S1Point(0.0), false, 1.0e-10).wholeHyperplane()); boundary.add(new LimitAngle(new S1Point(MathUtils.TWO_PI - 1.0e-11), true, 1.0e-10).wholeHyperplane()); ArcsSet set = new ArcsSet(boundary, 1.0e-10); Assert.assertEquals(MathUtils.TWO_PI, set.getSize(), 1.0e-10); Assert.assertEquals(1.0e-10, set.getTolerance(), 1.0e-20); Assert.assertEquals(1, set.asList().size()); Assert.assertEquals(0.0, set.asList().get(0).getInf(), 1.0e-10); Assert.assertEquals(MathUtils.TWO_PI, set.asList().get(0).getSup(), 1.0e-10); }
@Test public void testDifference() { ArcsSet a = new ArcsSet(1.0, 6.0, 1.0e-10); List<Arc> aList = a.asList(); Assert.assertEquals(1, aList.size()); Assert.assertEquals(1.0, aList.get(0).getInf(), 1.0e-10); Assert.assertEquals(6.0, aList.get(0).getSup(), 1.0e-10); ArcsSet b = new ArcsSet(3.0, 5.0, 1.0e-10); List<Arc> bList = b.asList(); Assert.assertEquals(1, bList.size()); Assert.assertEquals(3.0, bList.get(0).getInf(), 1.0e-10); Assert.assertEquals(5.0, bList.get(0).getSup(), 1.0e-10); ArcsSet aMb = (ArcsSet) new RegionFactory<Sphere1D>().difference(a, b); for (int k = -2; k < 3; ++k) { Assert.assertEquals(Location.OUTSIDE, aMb.checkPoint(new S1Point(0.0 + k * MathUtils.TWO_PI))); Assert.assertEquals(Location.OUTSIDE, aMb.checkPoint(new S1Point(0.9 + k * MathUtils.TWO_PI))); Assert.assertEquals(Location.BOUNDARY, aMb.checkPoint(new S1Point(1.0 + k * MathUtils.TWO_PI))); Assert.assertEquals(Location.INSIDE, aMb.checkPoint(new S1Point(1.1 + k * MathUtils.TWO_PI))); Assert.assertEquals(Location.INSIDE, aMb.checkPoint(new S1Point(2.9 + k * MathUtils.TWO_PI))); Assert.assertEquals(Location.BOUNDARY, aMb.checkPoint(new S1Point(3.0 + k * MathUtils.TWO_PI))); Assert.assertEquals(Location.OUTSIDE, aMb.checkPoint(new S1Point(3.1 + k * MathUtils.TWO_PI))); Assert.assertEquals(Location.OUTSIDE, aMb.checkPoint(new S1Point(4.9 + k * MathUtils.TWO_PI))); Assert.assertEquals(Location.BOUNDARY, aMb.checkPoint(new S1Point(5.0 + k * MathUtils.TWO_PI))); Assert.assertEquals(Location.INSIDE, aMb.checkPoint(new S1Point(5.1 + k * MathUtils.TWO_PI))); Assert.assertEquals(Location.INSIDE, aMb.checkPoint(new S1Point(5.9 + k * MathUtils.TWO_PI))); Assert.assertEquals(Location.BOUNDARY, aMb.checkPoint(new S1Point(6.0 + k * MathUtils.TWO_PI))); Assert.assertEquals(Location.OUTSIDE, aMb.checkPoint(new S1Point(6.1 + k * MathUtils.TWO_PI))); Assert.assertEquals(Location.OUTSIDE, aMb.checkPoint(new S1Point(6.2 + k * MathUtils.TWO_PI))); } List<Arc> aMbList = aMb.asList(); Assert.assertEquals(2, aMbList.size()); Assert.assertEquals(1.0, aMbList.get(0).getInf(), 1.0e-10); Assert.assertEquals(3.0, aMbList.get(0).getSup(), 1.0e-10); Assert.assertEquals(5.0, aMbList.get(1).getInf(), 1.0e-10); Assert.assertEquals(6.0, aMbList.get(1).getSup(), 1.0e-10); }
@Test public void testIntersection() { ArcsSet a = (ArcsSet) new RegionFactory<Sphere1D>().union(new ArcsSet(1.0, 3.0, 1.0e-10), new ArcsSet(5.0, 6.0, 1.0e-10)); List<Arc> aList = a.asList(); Assert.assertEquals(2, aList.size()); Assert.assertEquals(1.0, aList.get(0).getInf(), 1.0e-10); Assert.assertEquals(3.0, aList.get(0).getSup(), 1.0e-10); Assert.assertEquals(5.0, aList.get(1).getInf(), 1.0e-10); Assert.assertEquals(6.0, aList.get(1).getSup(), 1.0e-10); ArcsSet b = new ArcsSet(0.0, 5.5, 1.0e-10); List<Arc> bList = b.asList(); Assert.assertEquals(1, bList.size()); Assert.assertEquals(0.0, bList.get(0).getInf(), 1.0e-10); Assert.assertEquals(5.5, bList.get(0).getSup(), 1.0e-10); ArcsSet aMb = (ArcsSet) new RegionFactory<Sphere1D>().intersection(a, b); for (int k = -2; k < 3; ++k) { Assert.assertEquals(Location.OUTSIDE, aMb.checkPoint(new S1Point(0.0 + k * MathUtils.TWO_PI))); Assert.assertEquals(Location.BOUNDARY, aMb.checkPoint(new S1Point(1.0 + k * MathUtils.TWO_PI))); Assert.assertEquals(Location.INSIDE, aMb.checkPoint(new S1Point(1.1 + k * MathUtils.TWO_PI))); Assert.assertEquals(Location.INSIDE, aMb.checkPoint(new S1Point(2.9 + k * MathUtils.TWO_PI))); Assert.assertEquals(Location.BOUNDARY, aMb.checkPoint(new S1Point(3.0 + k * MathUtils.TWO_PI))); Assert.assertEquals(Location.OUTSIDE, aMb.checkPoint(new S1Point(3.1 + k * MathUtils.TWO_PI))); Assert.assertEquals(Location.OUTSIDE, aMb.checkPoint(new S1Point(4.9 + k * MathUtils.TWO_PI))); Assert.assertEquals(Location.BOUNDARY, aMb.checkPoint(new S1Point(5.0 + k * MathUtils.TWO_PI))); Assert.assertEquals(Location.INSIDE, aMb.checkPoint(new S1Point(5.1 + k * MathUtils.TWO_PI))); Assert.assertEquals(Location.INSIDE, aMb.checkPoint(new S1Point(5.4 + k * MathUtils.TWO_PI))); Assert.assertEquals(Location.BOUNDARY, aMb.checkPoint(new S1Point(5.5 + k * MathUtils.TWO_PI))); Assert.assertEquals(Location.OUTSIDE, aMb.checkPoint(new S1Point(5.6 + k * MathUtils.TWO_PI))); Assert.assertEquals(Location.OUTSIDE, aMb.checkPoint(new S1Point(6.2 + k * MathUtils.TWO_PI))); } List<Arc> aMbList = aMb.asList(); Assert.assertEquals(2, aMbList.size()); Assert.assertEquals(1.0, aMbList.get(0).getInf(), 1.0e-10); Assert.assertEquals(3.0, aMbList.get(0).getSup(), 1.0e-10); Assert.assertEquals(5.0, aMbList.get(1).getInf(), 1.0e-10); Assert.assertEquals(5.5, aMbList.get(1).getSup(), 1.0e-10); }
@Test public void testMultiple() { RegionFactory<Sphere1D> factory = new RegionFactory<Sphere1D>(); ArcsSet set = (ArcsSet) factory.intersection(factory.union(factory.difference(new ArcsSet(1.0, 6.0, 1.0e-10), new ArcsSet(3.0, 5.0, 1.0e-10)), new ArcsSet(0.5, 2.0, 1.0e-10)), new ArcsSet(0.0, 5.5, 1.0e-10)); Assert.assertEquals(3.0, set.getSize(), 1.0e-10); Assert.assertEquals(Region.Location.OUTSIDE, set.checkPoint(new S1Point(0.0))); Assert.assertEquals(Region.Location.OUTSIDE, set.checkPoint(new S1Point(4.0))); Assert.assertEquals(Region.Location.OUTSIDE, set.checkPoint(new S1Point(6.0))); Assert.assertEquals(Region.Location.INSIDE, set.checkPoint(new S1Point(1.2))); Assert.assertEquals(Region.Location.INSIDE, set.checkPoint(new S1Point(5.25))); Assert.assertEquals(Region.Location.BOUNDARY, set.checkPoint(new S1Point(0.5))); Assert.assertEquals(Region.Location.BOUNDARY, set.checkPoint(new S1Point(3.0))); Assert.assertEquals(Region.Location.BOUNDARY, set.checkPoint(new S1Point(5.0))); Assert.assertEquals(Region.Location.BOUNDARY, set.checkPoint(new S1Point(5.5))); List<Arc> list = set.asList(); Assert.assertEquals(2, list.size()); Assert.assertEquals( 0.5, list.get(0).getInf(), 1.0e-10); Assert.assertEquals( 3.0, list.get(0).getSup(), 1.0e-10); Assert.assertEquals( 5.0, list.get(1).getInf(), 1.0e-10); Assert.assertEquals( 5.5, list.get(1).getSup(), 1.0e-10); }