Exemplo n.º 1
0
  @Test
  public void testToVector3() {
    Vector4 x = new Vector4(3, 5, 6, 7);
    Vector3 y = new Vector3(3, 5, 6);

    assertTrue(x.toVector3().equals(y));
  }
Exemplo n.º 2
0
 @Test
 public void testHashCode() {
   Vector4 x = new Vector4(5, 27, 1, 2);
   Vector4 y = new Vector4(5, -3, 0, 1);
   doAssertDouble(-1677538473, x.hashCode());
   doAssertDouble(2032847703, y.hashCode());
 }
Exemplo n.º 3
0
 @Test
 public void testNormalize() {
   Vector4 x = new Vector4(3, 4, 5, 6);
   Vector4 y = x.normalize();
   doAssertDouble(0.323, y.x);
   doAssertDouble(0.431, y.y);
   doAssertDouble(1, y.length());
 }
Exemplo n.º 4
0
  @Test
  public void testCompareTo() {
    assertTrue(Vector4.ZERO.compareTo(Vector4.ONE) < 0);

    Vector4 x = new Vector4(5, 3, 4, 6);
    Vector4 y = new Vector4(-2, 5, -2, 4);
    assertTrue(x.compareTo(y) >= 0);
  }
Exemplo n.º 5
0
 @Test
 public void testEquals() {
   Vector4 x = new Vector4(1, 1, 1, 1);
   Vector4 y = new Vector4(1, 1, 1, 1);
   Vector4 z = new Vector4(1, 2, 1, 1);
   assertTrue(x.equals(y));
   assertFalse(x.equals(z));
 }
Exemplo n.º 6
0
 @Test
 public void testAbs() {
   Vector4 x = new Vector4(1.4, -0.2, -2.4, 3.4);
   Vector4 y = x.abs();
   doAssertDouble(1.4, y.x);
   doAssertDouble(0.2, y.y);
   doAssertDouble(2.4, y.z);
   doAssertDouble(3.4, y.w);
 }
Exemplo n.º 7
0
 @Test
 public void testFloor() {
   Vector4 x = new Vector4(1.4, -0.2, -2.4, 3.4);
   Vector4 y = x.floor();
   doAssertDouble(1, y.x);
   doAssertDouble(-1, y.y);
   doAssertDouble(-3, y.z);
   doAssertDouble(3, y.w);
 }
Exemplo n.º 8
0
 @Test
 public void testCeil() {
   Vector4 x = new Vector4(1.4, -0.2, -2.4, 3.4);
   Vector4 y = x.ceil();
   doAssertDouble(2, y.x);
   doAssertDouble(0, y.y);
   doAssertDouble(-2, y.z);
   doAssertDouble(4, y.w);
 }
Exemplo n.º 9
0
  @Test
  public void testDot() {
    Vector4 x = new Vector4(2, 3, 4, 5);
    doAssertDouble("x dot x should be 54", 54, x.dot(x));

    x = new Vector4(3, 2, 4, 5);
    Vector4 y = new Vector4(4, -1, 4, 2);
    doAssertDouble("x dot y should be 36", 36, x.dot(y));
  }
Exemplo n.º 10
0
 @Test
 public void testRound() {
   Vector4 x = new Vector4(1.4, -0.2, -2.4, 3.4);
   Vector4 y = x.round();
   doAssertDouble(1, y.x);
   doAssertDouble(0, y.y);
   doAssertDouble(-2, y.z);
   doAssertDouble(3, y.w);
 }
Exemplo n.º 11
0
  @Test
  public void testAddDouble() {
    Vector4 a = new Vector4(1, -1, 3, 5);
    Vector4 c = a.add(2d, 6d, -2d, 5d);

    doAssertDouble(3, c.x);
    doAssertDouble(5, c.y);
    doAssertDouble(1, c.z);
    doAssertDouble(10, c.w);
  }
Exemplo n.º 12
0
  @Test
  public void testSubtractInt() {
    Vector4 a = new Vector4(1, -1, 4, -2);
    Vector4 c = a.subtract(2, 6, 4, 1);

    doAssertDouble(-1, c.x);
    doAssertDouble(-7, c.y);
    doAssertDouble(0, c.z);
    doAssertDouble(-3, c.w);
  }
Exemplo n.º 13
0
  @Test
  public void testSubtractDouble() {
    Vector4 a = new Vector4(1, -1, 4, -2);
    Vector4 c = a.subtract(2d, 6d, 4d, 1d);

    doAssertDouble(-1, c.x);
    doAssertDouble(-7, c.y);
    doAssertDouble(0, c.z);
    doAssertDouble(-3, c.w);
  }
Exemplo n.º 14
0
  @Test
  public void testSubtractFloat() {
    Vector4 a = new Vector4(1, -1, 4, -2);
    Vector4 c = a.subtract(2f, 6f, 4f, 1f);

    doAssertDouble(-1, c.x);
    doAssertDouble(-7, c.y);
    doAssertDouble(0, c.z);
    doAssertDouble(-3, c.w);
  }
Exemplo n.º 15
0
  @Test
  public void testAddInt() {
    Vector4 a = new Vector4(1, -1, 3, 5);
    Vector4 c = a.add(2, 6, -2, 5);

    doAssertDouble(3, c.x);
    doAssertDouble(5, c.y);
    doAssertDouble(1, c.z);
    doAssertDouble(10, c.w);
  }
Exemplo n.º 16
0
  @Test
  public void testDistance() {
    Vector4 x = new Vector4(2, 3, 4, 5);
    Vector4 y = new Vector4(1, 2, 3, 4);
    doAssertDouble(2, x.distance(y));

    x = new Vector4(10, 3, 6, -5);
    y = new Vector4(7, 3, -2, 1);
    doAssertDouble(Math.sqrt(109), x.distance(y));
  }
Exemplo n.º 17
0
  @Test
  public void testAddFloat() {
    Vector4 a = new Vector4(1, -1, 3, 5);
    Vector4 c = a.add(2f, 6f, -2f, 5f);

    doAssertDouble(3, c.x);
    doAssertDouble(5, c.y);
    doAssertDouble(1, c.z);
    doAssertDouble(10, c.w);
  }
Exemplo n.º 18
0
 @Test
 public void testToArray() {
   Vector4 x = new Vector4(5, 3, 6, 7);
   float[] r = x.toArray();
   assertArrayEquals(new float[] {5, 3, 6, 7}, r, (float) eps);
   doAssertDouble(5, r[0]);
   doAssertDouble(3, r[1]);
   doAssertDouble(6, r[2]);
   doAssertDouble(7, r[3]);
 }
Exemplo n.º 19
0
  @Test
  public void testMultiplyVector4() {
    Vector4 a = new Vector4(1, -1, 4, 2);
    Vector4 b = new Vector4(2, 6, 4, 1);
    Vector4 c = a.multiply(b);

    doAssertDouble(2, c.x);
    doAssertDouble(-6, c.y);
    doAssertDouble(16, c.z);
    doAssertDouble(2, c.w);
  }
Exemplo n.º 20
0
  @Test
  public void testMultiplyFloat() {
    Vector4 a = new Vector4(1, -1, 4, 2);
    Vector4 b = a.multiply(2f, 6f, 4f, 1f);

    doAssertDouble(2, b.x);
    doAssertDouble(-6, b.y);
    doAssertDouble(16, b.z);
    doAssertDouble(2, b.w);

    Vector4 c = a.multiply(2.0F);

    doAssertDouble(2, c.x);
    doAssertDouble(-2, c.y);
    doAssertDouble(8, c.z);
    doAssertDouble(4, c.w);
  }
Exemplo n.º 21
0
  @Test
  public void testMultiplyDouble() {
    Vector4 a = new Vector4(1, -1, 4, 2);
    Vector4 b = a.multiply(2d, 6d, 4d, 1d);

    doAssertDouble(2, b.x);
    doAssertDouble(-6, b.y);
    doAssertDouble(16, b.z);
    doAssertDouble(2, b.w);

    Vector4 c = a.multiply(2.0d);

    doAssertDouble(2, c.x);
    doAssertDouble(-2, c.y);
    doAssertDouble(8, c.z);
    doAssertDouble(4, c.w);
  }
Exemplo n.º 22
0
  @Test
  public void testMultiplyInt() {
    Vector4 a = new Vector4(1, -1, 4, 2);
    Vector4 b = a.multiply(2, 6, 4, 1);

    doAssertDouble(2, b.x);
    doAssertDouble(-6, b.y);
    doAssertDouble(16, b.z);
    doAssertDouble(2, b.w);

    Vector4 c = a.multiply(2.0);

    doAssertDouble(2, c.x);
    doAssertDouble(-2, c.y);
    doAssertDouble(8, c.z);
    doAssertDouble(4, c.w);
  }
Exemplo n.º 23
0
 @Test
 public void testRand() {
   for (int i = 0; i < 100; ++i) {
     Vector4 x = Vector4.rand();
     assertTrue(x.x >= -1);
     assertTrue(x.x <= 1);
     assertTrue(x.y >= -1);
     assertTrue(x.y <= 1);
     assertTrue(x.z >= -1);
     assertTrue(x.z <= 1);
     assertTrue(x.w >= -1);
     assertTrue(x.w <= 1);
   }
 }
Exemplo n.º 24
0
  @Test
  public void testPow() {
    Vector4 x = new Vector4(1, 2, 3, 4);
    Vector4 y = x.pow(3);
    doAssertDouble(1, y.x);
    doAssertDouble(8, y.y);
    doAssertDouble(27, y.z);
    doAssertDouble(64, y.w);

    x = new Vector4(1, 2, 3, 4);
    y = x.pow(2);
    doAssertDouble(1, y.x);
    doAssertDouble(4, y.y);
    doAssertDouble(9, y.z);
    doAssertDouble(16, y.w);

    x = new Vector4(25, 16, 9, 4);
    y = x.pow(0.5);
    doAssertDouble(5, y.x);
    doAssertDouble(4, y.y);
    doAssertDouble(3, y.z);
    doAssertDouble(2, y.w);
  }
Exemplo n.º 25
0
 @Test
 public void testMax() {
   Vector4 x = new Vector4(5, -15, 3, 1);
   Vector4 y = new Vector4(3, 2, 5, -1);
   assertEquals(new Vector4(5, 2, 5, 1), Vector4.max(x, y));
 }
Exemplo n.º 26
0
 @Test
 public void testToString() {
   Vector4 x = new Vector4(3, 5, 0, 1);
   assertEquals("(3.0, 5.0, 0.0, 1.0)", x.toString());
 }
Exemplo n.º 27
0
 @Test
 public void testLength() {
   Vector4 x = new Vector4(2, 3, 4, 5);
   doAssertDouble(Math.sqrt(54), x.length());
 }
Exemplo n.º 28
0
 @Test
 public void testLengthSquared() {
   Vector4 x = new Vector4(2, 3, 4, 5);
   doAssertDouble(54, x.lengthSquared());
 }