@Test public void testFullCircle() { Circle circle = new Circle(100); // create control points that will match exactly the points the algo should generate CircularArc arc = circle.getCircularArc(0, Math.PI, 0); assertEquals(envelopeFrom(arc, 100, 0, 0, 100, -100, 0, 0, -100), arc.getEnvelope()); }
@Test public void testSamePoints() { CircularArc arc = new CircularArc(0, 0, 0, 0, 0, 0); assertEquals(0, arc.getRadius(), 0d); assertCoordinateEquals(ORIGIN, arc.getCenter()); double[] linearized = arc.linearize(0); assertArrayEquals(new double[] {0, 0, 0, 0, 0, 0}, linearized, 0d); assertEquals(envelopeFrom(arc), arc.getEnvelope()); assertEquals(0, arc.getEnvelope().getArea(), 0d); }
@Test public void testCollinear() { CircularArc arc = new CircularArc(0, 0, 0, 10, 0, 20); assertEquals(CircularArc.COLLINEARS, arc.getRadius(), 0d); assertCoordinateEquals(null, arc.getCenter()); double[] linearized = arc.linearize(0); assertArrayEquals(new double[] {0, 0, 0, 10, 0, 20}, linearized, 0d); assertEquals(envelopeFrom(arc), arc.getEnvelope()); }
@Test public void testMinuscule() { Circle circle = new Circle(100); CircularArc arc = circle.getCircularArc(0, CircularArc.HALF_PI / 128, CircularArc.HALF_PI / 64); assertEquals(100, arc.getRadius(), 1e-9); assertCoordinateEquals(ORIGIN, arc.getCenter()); // linearize with a large tolerance, we should get back just the control points assertArrayEquals(arc.getControlPoints(), arc.linearize(10), 0d); assertEquals(envelopeFrom(arc), arc.getEnvelope()); }
@Test public void testCrossPIPI() { Circle circle = new Circle(100); // create control points that will match exactly the points the algo should generate double step = CircularArc.HALF_PI / 32; CircularArc arc = circle.getCircularArc(-step * 2, step, step * 2); assertEquals(100, arc.getRadius(), 1e-9); assertCoordinateEquals(ORIGIN, arc.getCenter()); // linearize, we should get back the control points, plus the regular points in the middle double[] expected = circle.samplePoints(-step * 2, -step, 0, step, step * 2); assertArrayEquals(expected, arc.linearize(0.2), Circle.EPS); assertEquals(envelopeFrom(arc, 100, 0), arc.getEnvelope()); }
@Test public void testOutsideSequenceClockwise() { Circle circle = new Circle(100); // create control points that will match exactly the points the algo should generate double halfStep = CircularArc.HALF_PI / 64; CircularArc arc = circle.getCircularArc(halfStep * 5, halfStep * 3, halfStep); assertEquals(100, arc.getRadius(), 1e-9); assertCoordinateEquals(ORIGIN, arc.getCenter()); // linearize, we should get back the control points, plus the regular points in the middle double[] expected = circle.samplePoints( halfStep * 5, halfStep * 4, halfStep * 3, halfStep * 2, halfStep); assertArrayEquals(expected, arc.linearize(0.1), Circle.EPS); assertEquals(envelopeFrom(arc), arc.getEnvelope()); }