示例#1
0
  @Override
  @Test
  public void testAngle() {
    final AlmostEqualDouble.ContextRelative ec = TestUtilities.getDoubleEqualityContext3dp();

    {
      final PVectorI2I<T> v0 = new PVectorI2I<T>(1, 0);
      final PVectorI2I<T> v1 = new PVectorI2I<T>(1, 0);
      final double angle = PVectorI2I.angle(v0, v1);

      Assert.assertTrue(AlmostEqualDouble.almostEqual(ec, angle, 0.0));
    }

    {
      final int x = (int) (Math.random() * 200);
      final int y = (int) (Math.random() * 200);
      final PVectorI2I<T> v0 = new PVectorI2I<T>(x, y);
      final PVectorI2I<T> v1 = new PVectorI2I<T>(y, -x);
      final double angle = PVectorI2I.angle(v0, v1);

      Assert.assertTrue(AlmostEqualDouble.almostEqual(ec, angle, Math.toRadians(90)));
    }

    {
      final int x = (int) (Math.random() * 200);
      final int y = (int) (Math.random() * 200);
      final PVectorI2I<T> v0 = new PVectorI2I<T>(x, y);
      final PVectorI2I<T> v1 = new PVectorI2I<T>(-y, x);
      final double angle = PVectorI2I.angle(v0, v1);

      Assert.assertTrue(AlmostEqualDouble.almostEqual(ec, angle, Math.toRadians(90)));
    }
  }
示例#2
0
  @Override
  @Test
  public void testDotProductSelf() {
    final AlmostEqualDouble.ContextRelative ec = TestUtilities.getDoubleEqualityContext();

    for (int index = 0; index < TestUtilities.TEST_RANDOM_ITERATIONS; ++index) {
      final int max = 1000;
      final int x = (int) (Math.random() * max);
      final int y = (int) (Math.random() * max);
      final PVectorI2I<T> q = new PVectorI2I<T>(x, y);
      final double dp = PVectorI2I.dotProduct(q, q);

      AlmostEqualDouble.almostEqual(ec, 1.0, dp);
    }
  }