Example #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));
  }
Example #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());
 }
Example #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());
 }
Example #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);
  }
Example #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));
 }
Example #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);
 }
Example #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);
 }
Example #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);
 }
Example #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));
  }
Example #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);
 }
Example #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);
  }
Example #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);
  }
Example #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);
  }
Example #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);
  }
Example #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);
  }
Example #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));
  }
Example #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);
  }
Example #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]);
 }
Example #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);
  }
Example #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);
  }
Example #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);
  }
Example #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);
  }
Example #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);
   }
 }
Example #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);
  }
Example #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));
 }
Example #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());
 }
Example #27
0
 @Test
 public void testLength() {
   Vector4 x = new Vector4(2, 3, 4, 5);
   doAssertDouble(Math.sqrt(54), x.length());
 }
Example #28
0
 @Test
 public void testLengthSquared() {
   Vector4 x = new Vector4(2, 3, 4, 5);
   doAssertDouble(54, x.lengthSquared());
 }