Пример #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
  @Test
  public void testHierarchy() {
    final PVectorM4D<?> v = new PVectorM4D<Object>();

    Assert.assertTrue(v instanceof Vector4DType);
    Assert.assertTrue(v instanceof Vector3DType);
    Assert.assertTrue(v instanceof Vector2DType);

    Assert.assertTrue(v instanceof VectorReadable4DType);
    Assert.assertTrue(v instanceof VectorReadable3DType);
    Assert.assertTrue(v instanceof VectorReadable2DType);

    Assert.assertTrue(v instanceof VectorWritable4DType);
    Assert.assertTrue(v instanceof VectorWritable3DType);
    Assert.assertTrue(v instanceof VectorWritable2DType);

    Assert.assertTrue(v instanceof PVector4DType);
    Assert.assertTrue(v instanceof PVector3DType);
    Assert.assertTrue(v instanceof PVector2DType);

    Assert.assertTrue(v instanceof PVectorReadable4DType);
    Assert.assertTrue(v instanceof PVectorReadable3DType);
    Assert.assertTrue(v instanceof PVectorReadable2DType);

    Assert.assertTrue(v instanceof PVectorWritable4DType);
    Assert.assertTrue(v instanceof PVectorWritable3DType);
    Assert.assertTrue(v instanceof PVectorWritable2DType);

    final SortedMap<String, Class<?>> interfaces = TestUtilities.getInterfaces(v.getClass());
    for (final String k : interfaces.keySet()) {
      PVectorM4DTest.LOG.debug("{} implements {}", PVectorM4D.class, k);
    }

    Assert.assertEquals(18L, (long) interfaces.size());
  }
Пример #3
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);
    }
  }