Ray3 extends Line3Base implements ReadOnlyRay3, Poolable { @Override public double distanceSquared(final ReadOnlyVector3 point, final Vector3 store) { final Vector3 vectorA = Vector3.fetchTempInstance(); vectorA.set(point).subtractLocal(_origin); final double t0 = _direction.dot(vectorA); if (t0 > 0) { vectorA.set(_direction).multiplyLocal(t0); vectorA.addLocal(_origin); } else { vectorA.set(_origin); } if (store != null) { store.set(vectorA); } point.subtract(vectorA, vectorA); final double lSQ = vectorA.lengthSquared(); Vector3.releaseTempInstance(vectorA); return lSQ; } Ray3();  Ray3(final ReadOnlyRay3 source);  Ray3(final ReadOnlyVector3 origin, final ReadOnlyVector3 direction); Ray3 set(final ReadOnlyRay3 source); @Override double getDistanceToPrimitive(final Vector3[] worldVertices); @Override boolean intersects(final Vector3[] polygonVertices, final Vector3 locationStore); @Override boolean intersectsTriangle(final ReadOnlyVector3 pointA, final ReadOnlyVector3 pointB,
      final ReadOnlyVector3 pointC, final Vector3 locationStore); @Override boolean intersectsTrianglePlanar(final ReadOnlyVector3 pointA, final ReadOnlyVector3 pointB,
      final ReadOnlyVector3 pointC, final Vector3 locationStore); @Override boolean intersectsQuad(final ReadOnlyVector3 pointA, final ReadOnlyVector3 pointB,
      final ReadOnlyVector3 pointC, final ReadOnlyVector3 pointD, final Vector3 locationStore); @Override boolean intersectsQuadPlanar(final ReadOnlyVector3 pointA, final ReadOnlyVector3 pointB,
      final ReadOnlyVector3 pointC, final ReadOnlyVector3 pointD, final Vector3 locationStore); @Override boolean intersectsPlane(final ReadOnlyPlane plane, final Vector3 locationStore); @Override double distanceSquared(final ReadOnlyVector3 point, final Vector3 store); static boolean isValid(final ReadOnlyRay3 ray); @Override String toString(); @Override boolean equals(final Object o); @Override Ray3 clone(); final static Ray3 fetchTempInstance(); final static void releaseTempInstance(final Ray3 ray);  }
@Test public void testDistance() { final Ray3 ray1 = new Ray3(); assertTrue(25.0 == ray1.distanceSquared(new Vector3(0, 5, 3), null)); final Vector3 store = new Vector3(); assertTrue(9.0 == ray1.distanceSquared(new Vector3(0, 3, 3), store)); assertEquals(new Vector3(0, 0, 3), store); assertTrue(18.0 == ray1.distanceSquared(new Vector3(0, 3, -3), store)); assertEquals(new Vector3(0, 0, 0), store); }