ArcsSet extends AbstractRegion<Sphere1D, Sphere1D> implements Iterable<double[]> { public Side side(final Arc arc) { final double reference = FastMath.PI + arc.getInf(); final double arcLength = arc.getSup() - arc.getInf(); boolean inMinus = false; boolean inPlus = false; 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 - getTolerance() || syncedEnd >= MathUtils.TWO_PI + getTolerance()) { inMinus = true; } if (syncedEnd >= arcLength + getTolerance()) { inPlus = true; } } if (inMinus) { if (inPlus) { return Side.BOTH; } else { return Side.MINUS; } } else { if (inPlus) { return Side.PLUS; } else { return Side.HYPER; } } } 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 testSide() { ArcsSet set = (ArcsSet) new RegionFactory<Sphere1D>().difference(new ArcsSet(1.0, 6.0, 1.0e-10), new ArcsSet(3.0, 5.0, 1.0e-10)); for (int k = -2; k < 3; ++k) { Assert.assertEquals(Side.MINUS, set.side(new Arc(0.5 + k * MathUtils.TWO_PI, 6.1 + k * MathUtils.TWO_PI, set.getTolerance()))); Assert.assertEquals(Side.PLUS, set.side(new Arc(0.5 + k * MathUtils.TWO_PI, 0.8 + k * MathUtils.TWO_PI, set.getTolerance()))); Assert.assertEquals(Side.PLUS, set.side(new Arc(6.2 + k * MathUtils.TWO_PI, 6.3 + k * MathUtils.TWO_PI, set.getTolerance()))); Assert.assertEquals(Side.PLUS, set.side(new Arc(3.5 + k * MathUtils.TWO_PI, 4.5 + k * MathUtils.TWO_PI, set.getTolerance()))); Assert.assertEquals(Side.BOTH, set.side(new Arc(2.9 + k * MathUtils.TWO_PI, 4.5 + k * MathUtils.TWO_PI, set.getTolerance()))); Assert.assertEquals(Side.BOTH, set.side(new Arc(0.5 + k * MathUtils.TWO_PI, 1.2 + k * MathUtils.TWO_PI, set.getTolerance()))); Assert.assertEquals(Side.BOTH, set.side(new Arc(0.5 + k * MathUtils.TWO_PI, 5.9 + k * MathUtils.TWO_PI, set.getTolerance()))); } }
@Test public void testSideEmbedded() { ArcsSet s35 = new ArcsSet(3.0, 5.0, 1.0e-10); ArcsSet s16 = new ArcsSet(1.0, 6.0, 1.0e-10); Assert.assertEquals(Side.BOTH, s16.side(new Arc(3.0, 5.0, 1.0e-10))); Assert.assertEquals(Side.BOTH, s16.side(new Arc(5.0, 3.0 + MathUtils.TWO_PI, 1.0e-10))); Assert.assertEquals(Side.MINUS, s35.side(new Arc(1.0, 6.0, 1.0e-10))); Assert.assertEquals(Side.PLUS, s35.side(new Arc(6.0, 1.0 + MathUtils.TWO_PI, 1.0e-10))); }
@Test public void testSideOverlapping() { ArcsSet s35 = new ArcsSet(3.0, 5.0, 1.0e-10); ArcsSet s46 = new ArcsSet(4.0, 6.0, 1.0e-10); Assert.assertEquals(Side.BOTH, s46.side(new Arc(3.0, 5.0, 1.0e-10))); Assert.assertEquals(Side.BOTH, s46.side(new Arc(5.0, 3.0 + MathUtils.TWO_PI, 1.0e-10))); Assert.assertEquals(Side.BOTH, s35.side(new Arc(4.0, 6.0, 1.0e-10))); Assert.assertEquals(Side.BOTH, s35.side(new Arc(6.0, 4.0 + MathUtils.TWO_PI, 1.0e-10))); }
@Test public void testSideHyper() { ArcsSet sub = (ArcsSet) new RegionFactory<Sphere1D>().getComplement(new ArcsSet(1.0e-10)); Assert.assertTrue(sub.isEmpty()); Assert.assertEquals(Side.HYPER, sub.side(new Arc(2.0, 3.0, 1.0e-10))); }