ArcsSet extends AbstractRegion<Sphere1D, Sphere1D> implements Iterable<double[]> { public Split split(final Arc arc) { final List<Double> minus = new ArrayList<Double>(); final List<Double> plus = new ArrayList<Double>(); final double reference = FastMath.PI + arc.getInf(); final double arcLength = arc.getSup() - arc.getInf(); for (final double[] a : this) { final double syncedStart = MathUtils.normalizeAngle(a[0], reference) - arc.getInf(); final double arcOffset = a[0] - syncedStart; final double syncedEnd = a[1] - arcOffset; if (syncedStart < arcLength) { minus.add(a[0]); if (syncedEnd > arcLength) { final double minusToPlus = arcLength + arcOffset; minus.add(minusToPlus); plus.add(minusToPlus); if (syncedEnd > MathUtils.TWO_PI) { final double plusToMinus = MathUtils.TWO_PI + arcOffset; plus.add(plusToMinus); minus.add(plusToMinus); minus.add(a[1]); } else { plus.add(a[1]); } } else { minus.add(a[1]); } } else { plus.add(a[0]); if (syncedEnd > MathUtils.TWO_PI) { final double plusToMinus = MathUtils.TWO_PI + arcOffset; plus.add(plusToMinus); minus.add(plusToMinus); if (syncedEnd > MathUtils.TWO_PI + arcLength) { final double minusToPlus = MathUtils.TWO_PI + arcLength + arcOffset; minus.add(minusToPlus); plus.add(minusToPlus); plus.add(a[1]); } else { minus.add(a[1]); } } else { plus.add(a[1]); } } } return new Split(createSplitPart(plus), createSplitPart(minus)); } 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 testSplitOver2Pi() { ArcsSet set = new ArcsSet(1.0e-10); Arc arc = new Arc(1.5 * FastMath.PI, 2.5 * FastMath.PI, 1.0e-10); ArcsSet.Split split = set.split(arc); for (double alpha = 0.0; alpha <= MathUtils.TWO_PI; alpha += 0.01) { S1Point p = new S1Point(alpha); if (alpha < 0.5 * FastMath.PI || alpha > 1.5 * FastMath.PI) { Assert.assertEquals(Location.OUTSIDE, split.getPlus().checkPoint(p)); Assert.assertEquals(Location.INSIDE, split.getMinus().checkPoint(p)); } else { Assert.assertEquals(Location.INSIDE, split.getPlus().checkPoint(p)); Assert.assertEquals(Location.OUTSIDE, split.getMinus().checkPoint(p)); } } }
@Test public void testSplitAtEnd() { ArcsSet set = new ArcsSet(1.0e-10); Arc arc = new Arc(FastMath.PI, MathUtils.TWO_PI, 1.0e-10); ArcsSet.Split split = set.split(arc); for (double alpha = 0.01; alpha < MathUtils.TWO_PI; alpha += 0.01) { S1Point p = new S1Point(alpha); if (alpha > FastMath.PI) { Assert.assertEquals(Location.OUTSIDE, split.getPlus().checkPoint(p)); Assert.assertEquals(Location.INSIDE, split.getMinus().checkPoint(p)); } else { Assert.assertEquals(Location.INSIDE, split.getPlus().checkPoint(p)); Assert.assertEquals(Location.OUTSIDE, split.getMinus().checkPoint(p)); } } S1Point zero = new S1Point(0.0); Assert.assertEquals(Location.BOUNDARY, split.getPlus().checkPoint(zero)); Assert.assertEquals(Location.BOUNDARY, split.getMinus().checkPoint(zero)); S1Point pi = new S1Point(FastMath.PI); Assert.assertEquals(Location.BOUNDARY, split.getPlus().checkPoint(pi)); Assert.assertEquals(Location.BOUNDARY, split.getMinus().checkPoint(pi)); }
@Test public void testSplitWithinEpsilon() { double epsilon = 1.0e-10; double a = 6.25; double b = a - 0.5 * epsilon; ArcsSet set = new ArcsSet(a - 1, a, epsilon); Arc arc = new Arc(b, b + FastMath.PI, epsilon); ArcsSet.Split split = set.split(arc); Assert.assertEquals(set.getSize(), split.getPlus().getSize(), epsilon); Assert.assertNull(split.getMinus()); }