Exemple #1
0
 @Test
 public void testCentralSymmetry() {
   IPoint pt = ShapeFactory.createPoint();
   assertNull(pt.centralSymmetry(null));
   assertEquals(
       ShapeFactory.createPoint(-1, 0), ShapeFactory.createPoint(1, 0).centralSymmetry(pt));
   assertEquals(
       ShapeFactory.createPoint(0, -1), ShapeFactory.createPoint(0, 1).centralSymmetry(pt));
   assertEquals(
       ShapeFactory.createPoint(1, 0), ShapeFactory.createPoint(-1, 0).centralSymmetry(pt));
   assertEquals(
       ShapeFactory.createPoint(0, 1), ShapeFactory.createPoint(0, -1).centralSymmetry(pt));
 }
Exemple #2
0
  @Test
  public void testHorizontalSymmetry() {
    IPoint pt = ShapeFactory.createPoint(10., 10.);

    assertNull(pt.horizontalSymmetry(null));
    assertNull(pt.horizontalSymmetry(ShapeFactory.createPoint(Double.NaN, 1.)));
    assertNull(pt.horizontalSymmetry(ShapeFactory.createPoint(1., Double.NaN)));
    assertNull(pt.horizontalSymmetry(ShapeFactory.createPoint(Double.POSITIVE_INFINITY, 1.)));
    assertNull(pt.horizontalSymmetry(ShapeFactory.createPoint(1., Double.POSITIVE_INFINITY)));
    assertNull(pt.horizontalSymmetry(ShapeFactory.createPoint(Double.NEGATIVE_INFINITY, 1.)));
    assertNull(pt.horizontalSymmetry(ShapeFactory.createPoint(1., Double.NEGATIVE_INFINITY)));
    assertEquals(
        pt.horizontalSymmetry(ShapeFactory.createPoint(0., 0.)),
        ShapeFactory.createPoint(-10., 10.));
    assertEquals(
        pt.horizontalSymmetry(ShapeFactory.createPoint(0., 18780.)),
        ShapeFactory.createPoint(-10., 10.));
    assertEquals(
        ShapeFactory.createPoint(-10., 10.)
            .horizontalSymmetry(ShapeFactory.createPoint(0., 18780.)),
        pt);
    assertEquals(
        ShapeFactory.createPoint(0., 0.).horizontalSymmetry(ShapeFactory.createPoint(0., 0.)),
        ShapeFactory.createPoint(0., 0.));
  }
Exemple #3
0
  @Test
  public void testLPoint() {
    IPoint pt = ShapeFactory.createPoint(1., -200.);

    assertEquals(ShapeFactory.createPoint(), ShapeFactory.createPoint(0., 0.));
    assertEquals(pt.getX(), 1., 0.1);
    assertEquals(pt.getY(), -200., 0.1);

    pt = ShapeFactory.createPoint((IPoint) null);
    assertEquals(pt.getX(), 0., 0.1);
    assertEquals(pt.getY(), 0., 0.1);

    pt = ShapeFactory.createPoint(ShapeFactory.createPoint(-1.34, Double.POSITIVE_INFINITY));
    assertEquals(pt.getX(), -1.34, 0.1);
    assertEquals(pt.getY(), Double.POSITIVE_INFINITY, 0.1);
  }
Exemple #4
0
  @Test
  public void testTranslate() {
    IPoint pt1 = ShapeFactory.createPoint(2., 1.);
    IPoint pt2 = ShapeFactory.createPoint(2., 1.);

    pt1.translate(Double.NaN, Double.NaN);
    assertEquals(pt1, pt2);
    pt1.translate(Double.NaN, 2.);
    assertEquals(pt1, pt2);
    pt1.translate(2., Double.NaN);
    assertEquals(pt1, pt2);
    pt1.translate(Double.POSITIVE_INFINITY, Double.POSITIVE_INFINITY);
    assertEquals(pt1, pt2);
    pt1.translate(Double.POSITIVE_INFINITY, 2.);
    assertEquals(pt1, pt2);
    pt1.translate(2., Double.POSITIVE_INFINITY);
    assertEquals(pt1, pt2);
    pt1.translate(Double.NEGATIVE_INFINITY, Double.NEGATIVE_INFINITY);
    assertEquals(pt1, pt2);
    pt1.translate(Double.NEGATIVE_INFINITY, 2.);
    assertEquals(pt1, pt2);
    pt1.translate(2., Double.NEGATIVE_INFINITY);
    assertEquals(pt1, pt2);
    pt1.translate(0., 0.);
    assertEquals(pt1, pt2);
    pt1.translate(0., 10.);
    assertEquals(pt1, ShapeFactory.createPoint(2., 11.));
    pt1.translate(0., -12.);
    assertEquals(pt1, ShapeFactory.createPoint(2., -1.));
    pt1.translate(5., 0.);
    assertEquals(pt1, ShapeFactory.createPoint(7., -1.));
    pt1.translate(-4., 0.);
    assertEquals(pt1, ShapeFactory.createPoint(3., -1.));
    pt1.translate(3.12, 7.98);
    assertEquals(pt1, ShapeFactory.createPoint(6.12, 6.98));
  }
Exemple #5
0
  @Test
  public void testRotatePoint() {
    IPoint pt = ShapeFactory.createPoint();

    assertNull(pt.rotatePoint(null, 0));
    assertNull(pt.rotatePoint(null, 0));
    assertNull(pt.rotatePoint(ShapeFactory.createPoint(), Double.NaN));
    assertNull(pt.rotatePoint(ShapeFactory.createPoint(), Double.NEGATIVE_INFINITY));
    assertNull(pt.rotatePoint(ShapeFactory.createPoint(), Double.POSITIVE_INFINITY));

    assertEquals(
        ShapeFactory.createPoint(0, 1),
        ShapeFactory.createPoint(1, 0).rotatePoint(ShapeFactory.createPoint(), Math.PI / 2.));
    assertEquals(
        ShapeFactory.createPoint(-1, 0),
        ShapeFactory.createPoint(0, 1).rotatePoint(ShapeFactory.createPoint(), Math.PI / 2.));
    assertEquals(
        ShapeFactory.createPoint(0, -1),
        ShapeFactory.createPoint(-1, 0).rotatePoint(ShapeFactory.createPoint(), Math.PI / 2.));
    assertEquals(
        ShapeFactory.createPoint(1, 0),
        ShapeFactory.createPoint(0, -1).rotatePoint(ShapeFactory.createPoint(), Math.PI / 2.));

    assertEquals(
        ShapeFactory.createPoint(0, 1),
        ShapeFactory.createPoint(1, 0).rotatePoint(pt, -3. * Math.PI / 2.));
    assertEquals(
        ShapeFactory.createPoint(-1, 0),
        ShapeFactory.createPoint(0, 1).rotatePoint(pt, -3. * Math.PI / 2.));
    assertEquals(
        ShapeFactory.createPoint(0, -1),
        ShapeFactory.createPoint(-1, 0).rotatePoint(pt, -3. * Math.PI / 2.));
    assertEquals(
        ShapeFactory.createPoint(1, 0),
        ShapeFactory.createPoint(0, -1).rotatePoint(pt, -3. * Math.PI / 2.));

    assertEquals(
        ShapeFactory.createPoint(-1, 0), ShapeFactory.createPoint(1, 0).rotatePoint(pt, Math.PI));
    assertEquals(
        ShapeFactory.createPoint(0, -1), ShapeFactory.createPoint(0, 1).rotatePoint(pt, Math.PI));
    assertEquals(
        ShapeFactory.createPoint(1, 0), ShapeFactory.createPoint(-1, 0).rotatePoint(pt, Math.PI));
    assertEquals(
        ShapeFactory.createPoint(0, 1), ShapeFactory.createPoint(0, -1).rotatePoint(pt, Math.PI));

    assertEquals(
        ShapeFactory.createPoint(-1, 0), ShapeFactory.createPoint(1, 0).rotatePoint(pt, -Math.PI));
    assertEquals(
        ShapeFactory.createPoint(0, -1), ShapeFactory.createPoint(0, 1).rotatePoint(pt, -Math.PI));
    assertEquals(
        ShapeFactory.createPoint(1, 0), ShapeFactory.createPoint(-1, 0).rotatePoint(pt, -Math.PI));
    assertEquals(
        ShapeFactory.createPoint(0, 1), ShapeFactory.createPoint(0, -1).rotatePoint(pt, -Math.PI));

    assertEquals(
        ShapeFactory.createPoint(0, -1),
        ShapeFactory.createPoint(1, 0).rotatePoint(pt, 3. * Math.PI / 2.));
    assertEquals(
        ShapeFactory.createPoint(1, 0),
        ShapeFactory.createPoint(0, 1).rotatePoint(pt, 3. * Math.PI / 2.));
    assertEquals(
        ShapeFactory.createPoint(0, 1),
        ShapeFactory.createPoint(-1, 0).rotatePoint(pt, 3. * Math.PI / 2.));
    assertEquals(
        ShapeFactory.createPoint(-1, 0),
        ShapeFactory.createPoint(0, -1).rotatePoint(pt, 3. * Math.PI / 2.));

    assertEquals(
        ShapeFactory.createPoint(0, -1),
        ShapeFactory.createPoint(1, 0).rotatePoint(pt, -Math.PI / 2.));
    assertEquals(
        ShapeFactory.createPoint(1, 0),
        ShapeFactory.createPoint(0, 1).rotatePoint(pt, -Math.PI / 2.));
    assertEquals(
        ShapeFactory.createPoint(0, 1),
        ShapeFactory.createPoint(-1, 0).rotatePoint(pt, -Math.PI / 2.));
    assertEquals(
        ShapeFactory.createPoint(-1, 0),
        ShapeFactory.createPoint(0, -1).rotatePoint(pt, -Math.PI / 2.));

    assertEquals(
        ShapeFactory.createPoint(1, 0),
        ShapeFactory.createPoint(1, 0).rotatePoint(pt, 2. * Math.PI));
    assertEquals(
        ShapeFactory.createPoint(0, 1),
        ShapeFactory.createPoint(0, 1).rotatePoint(pt, 2. * Math.PI));
    assertEquals(
        ShapeFactory.createPoint(-1, 0),
        ShapeFactory.createPoint(-1, 0).rotatePoint(pt, 2. * Math.PI));
    assertEquals(
        ShapeFactory.createPoint(0, -1),
        ShapeFactory.createPoint(0, -1).rotatePoint(pt, 2. * Math.PI));

    assertEquals(
        ShapeFactory.createPoint(1, 0),
        ShapeFactory.createPoint(1, 0).rotatePoint(pt, -2. * Math.PI));
    assertEquals(
        ShapeFactory.createPoint(0, 1),
        ShapeFactory.createPoint(0, 1).rotatePoint(pt, -2. * Math.PI));
    assertEquals(
        ShapeFactory.createPoint(-1, 0),
        ShapeFactory.createPoint(-1, 0).rotatePoint(pt, -2. * Math.PI));
    assertEquals(
        ShapeFactory.createPoint(0, -1),
        ShapeFactory.createPoint(0, -1).rotatePoint(pt, -2. * Math.PI));

    assertEquals(ShapeFactory.createPoint(1, 0), ShapeFactory.createPoint(1, 0).rotatePoint(pt, 0));
    assertEquals(ShapeFactory.createPoint(0, 1), ShapeFactory.createPoint(0, 1).rotatePoint(pt, 0));
    assertEquals(
        ShapeFactory.createPoint(-1, 0), ShapeFactory.createPoint(-1, 0).rotatePoint(pt, 0));
    assertEquals(
        ShapeFactory.createPoint(0, -1), ShapeFactory.createPoint(0, -1).rotatePoint(pt, 0));
  }
Exemple #6
0
  @Test
  public void testComputeRotationAngle() {
    IPoint pt1 = ShapeFactory.createPoint();

    assertEquals(Double.NaN, pt1.computeRotationAngle(null, null), 0.1);
    assertEquals(Double.NaN, pt1.computeRotationAngle(ShapeFactory.createPoint(), null), 0.1);
    assertEquals(Double.NaN, pt1.computeRotationAngle(null, ShapeFactory.createPoint()), 0.1);

    assertEquals(
        0.,
        pt1.computeRotationAngle(ShapeFactory.createPoint(1, 0), ShapeFactory.createPoint(1, 0)),
        0.1);
    assertEquals(
        0.,
        pt1.computeRotationAngle(ShapeFactory.createPoint(0, 1), ShapeFactory.createPoint(0, 1)),
        0.1);
    assertEquals(
        0.,
        pt1.computeRotationAngle(ShapeFactory.createPoint(-1, 0), ShapeFactory.createPoint(-1, 0)),
        0.1);
    assertEquals(
        0.,
        pt1.computeRotationAngle(ShapeFactory.createPoint(0, -1), ShapeFactory.createPoint(0, -1)),
        0.1);

    assertEquals(
        Math.PI / 2.,
        pt1.computeRotationAngle(ShapeFactory.createPoint(1, 0), ShapeFactory.createPoint(0, 1)),
        0.1);
    assertEquals(
        Math.PI,
        Math.abs(
            pt1.computeRotationAngle(
                ShapeFactory.createPoint(1, 0), ShapeFactory.createPoint(-1, 0))),
        0.1);
    assertEquals(
        3. * Math.PI / 2.,
        pt1.computeRotationAngle(ShapeFactory.createPoint(1, 0), ShapeFactory.createPoint(0, -1)),
        0.1);

    assertEquals(
        Math.PI / 2.,
        pt1.computeRotationAngle(ShapeFactory.createPoint(0, 1), ShapeFactory.createPoint(-1, 0)),
        0.1);
    assertEquals(
        Math.PI,
        Math.abs(
            pt1.computeRotationAngle(
                ShapeFactory.createPoint(0, 1), ShapeFactory.createPoint(0, -1))),
        0.1);
    assertEquals(
        -Math.PI / 2.,
        pt1.computeRotationAngle(ShapeFactory.createPoint(0, 1), ShapeFactory.createPoint(1, 0)),
        0.1);

    assertEquals(
        Math.PI / 2.,
        pt1.computeRotationAngle(ShapeFactory.createPoint(-1, 0), ShapeFactory.createPoint(0, -1)),
        0.1);
    assertEquals(
        Math.PI,
        Math.abs(
            pt1.computeRotationAngle(
                ShapeFactory.createPoint(-1, 0), ShapeFactory.createPoint(1, 0))),
        0.1);
    assertEquals(
        -Math.PI / 2.,
        pt1.computeRotationAngle(ShapeFactory.createPoint(-1, 0), ShapeFactory.createPoint(0, 1)),
        0.1);

    assertEquals(
        -3. * Math.PI / 2.,
        pt1.computeRotationAngle(ShapeFactory.createPoint(0, -1), ShapeFactory.createPoint(1, 0)),
        0.1);
    assertEquals(
        Math.PI,
        Math.abs(
            pt1.computeRotationAngle(
                ShapeFactory.createPoint(0, -1), ShapeFactory.createPoint(0, 1))),
        0.1);
    assertEquals(
        -Math.PI / 2.,
        pt1.computeRotationAngle(ShapeFactory.createPoint(0, -1), ShapeFactory.createPoint(-1, 0)),
        0.1);
  }
Exemple #7
0
  @Test
  public void testComputeAngle() {
    IPoint pt1 = ShapeFactory.createPoint();

    assertEquals(Double.NaN, pt1.computeAngle(null), 0.1);
    assertEquals(0., pt1.computeAngle(ShapeFactory.createPoint(1, 0)), 0.1);
    assertEquals(Math.PI / 2., pt1.computeAngle(ShapeFactory.createPoint(0, 1)), 0.1);
    assertEquals(Math.PI, pt1.computeAngle(ShapeFactory.createPoint(-1, 0)), 0.1);
    assertEquals(3. * Math.PI / 2., pt1.computeAngle(ShapeFactory.createPoint(0, -1)), 0.1);

    pt1.setPoint(1, 1);
    assertEquals(0., pt1.computeAngle(ShapeFactory.createPoint(2, 1)), 0.1);
    assertEquals(Math.PI / 2., pt1.computeAngle(ShapeFactory.createPoint(1, 2)), 0.1);
    assertEquals(Math.PI, pt1.computeAngle(ShapeFactory.createPoint(0, 1)), 0.1);
    assertEquals(3. * Math.PI / 2., pt1.computeAngle(ShapeFactory.createPoint(1, 0)), 0.1);
  }