@Test
public void testIntersectsTriangle() {

  final Vector3 v0 = new Vector3(-1, -1, -1);
  final Vector3 v1 = new Vector3(+1, -1, -1);
  final Vector3 v2 = new Vector3(+1, +1, -1);
  final Vector3 intersectionPoint = new Vector3();
  // inside triangle
  Ray3 pickRay = new Ray3(new Vector3(0.5, -0.5, 3), new Vector3(0, 0, -1));
  assertTrue(pickRay.intersectsTriangle(v0, v1, v2, intersectionPoint));
  // horizontal edge
  pickRay = new Ray3(new Vector3(0, -1, 3), new Vector3(0, 0, -1));
  assertTrue(pickRay.intersectsTriangle(v0, v1, v2, intersectionPoint));
  // diagonal edge
  pickRay = new Ray3(new Vector3(0, 0, 3), new Vector3(0, 0, -1));
  assertTrue(pickRay.intersectsTriangle(v0, v1, v2, intersectionPoint));
  // vertical edge
  pickRay = new Ray3(new Vector3(+1, 0, 3), new Vector3(0, 0, -1));
  assertTrue(pickRay.intersectsTriangle(v0, v1, v2, intersectionPoint));
  // v0
  pickRay = new Ray3(new Vector3(-1, -1, 3), new Vector3(0, 0, -1));
  assertTrue(pickRay.intersectsTriangle(v0, v1, v2, intersectionPoint));
  // v1
  pickRay = new Ray3(new Vector3(+1, -1, 3), new Vector3(0, 0, -1));
  assertTrue(pickRay.intersectsTriangle(v0, v1, v2, intersectionPoint));
  // v2
  pickRay = new Ray3(new Vector3(1, 1, 3), new Vector3(0, 0, -1));
  assertTrue(pickRay.intersectsTriangle(v0, v1, v2, intersectionPoint));
  // outside horizontal edge
  pickRay = new Ray3(new Vector3(0, -1.1, 3), new Vector3(0, 0, -1));
  assertFalse(pickRay.intersectsTriangle(v0, v1, v2, intersectionPoint));
  // outside diagonal edge
  pickRay = new Ray3(new Vector3(-0.1, 0.1, 3), new Vector3(0, 0, -1));
  assertFalse(pickRay.intersectsTriangle(v0, v1, v2, intersectionPoint));
  // outside vertical edge
  pickRay = new Ray3(new Vector3(+1.1, 0, 3), new Vector3(0, 0, -1));
  assertFalse(pickRay.intersectsTriangle(v0, v1, v2, intersectionPoint));
  // inside triangle but ray pointing other way
  pickRay = new Ray3(new Vector3(-0.5, -0.5, 3), new Vector3(0, 0, +1));
  assertFalse(pickRay.intersectsTriangle(v0, v1, v2, intersectionPoint));
  // test distance
  pickRay = new Ray3(new Vector3(0.5, -0.5, 3), new Vector3(0, 0, -1));
  assertTrue(4.0 == pickRay.getDistanceToPrimitive(new Vector3[] {v0, v1, v2}));
  // test intersect planar
  assertTrue(pickRay.intersectsTrianglePlanar(v0, v1, v2, intersectionPoint));
}