LineSegment3 extends Line3Base implements ReadOnlyLineSegment3, 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 (-_extent < t0) { if (t0 < _extent) { vectorA.set(getDirection()).multiplyLocal(t0); vectorA.addLocal(getOrigin()); } else { getPositiveEnd(vectorA); } } else { getNegativeEnd(vectorA); } if (store != null) { store.set(vectorA); } point.subtract(vectorA, vectorA); final double lSQ = vectorA.lengthSquared(); Vector3.releaseTempInstance(vectorA); return lSQ; } LineSegment3();  LineSegment3(final ReadOnlyLineSegment3 source);  LineSegment3(final ReadOnlyVector3 origin, final ReadOnlyVector3 direction, final double extent);  LineSegment3(final ReadOnlyVector3 start, final ReadOnlyVector3 end); LineSegment3 set(final ReadOnlyLineSegment3 source); @Override double getExtent(); void setExtent(final double extent); Vector3 getPositiveEnd(final Vector3 store); Vector3 getNegativeEnd(final Vector3 store); @Override double distanceSquared(final ReadOnlyVector3 point, final Vector3 store); Vector3 random(final Vector3 store); static boolean isValid(final ReadOnlyLineSegment3 segment); @Override String toString(); @Override boolean equals(final Object o); @Override int hashCode(); @Override LineSegment3 clone(); @Override void write(final OutputCapsule capsule); @Override void read(final InputCapsule capsule); @Override void readExternal(final ObjectInput in); @Override void writeExternal(final ObjectOutput out); final static LineSegment3 fetchTempInstance(); final static void releaseTempInstance(final LineSegment3 segment);  }
@Test public void testDistance() { final LineSegment3 seg1 = new LineSegment3(Vector3.ZERO, Vector3.UNIT_Z, 1.0); final Vector3 store = new Vector3(); assertTrue(16.0 == seg1.distanceSquared(new Vector3(0, 0, 5), store)); assertEquals(Vector3.UNIT_Z, store); assertTrue(9.0 == seg1.distanceSquared(new Vector3(0, 0, -4), store)); assertEquals(Vector3.NEG_UNIT_Z, store); assertTrue(4.0 == seg1.distanceSquared(new Vector3(2, 0, 0), store)); assertEquals(Vector3.ZERO, store); assertTrue(1.0 == seg1.distanceSquared(Vector3.NEG_UNIT_X, null)); }