@Test public void testDistanceTo() { IVector2 sV = Vector2f.ZERO_VECTOR; IVector2 dV = Vector2f.Y_AXIS; IHalfLine line = HalfLine.fromDirection(sV, dV); IHalfLine invalidLine = HalfLine.fromDirection(sV, Vector2f.ZERO_VECTOR); for (int i = -10; i <= 10; i += 1) { assertThat(line.distanceTo(Vector2.fromXY(i, 0)), closeTo(Math.abs(i), ACCURACY)); IVector2 identical = Vector2.fromXY(0, i); IVector2 parallel = Vector2.fromXY(1, i); if (i < 0) { assertThat(line.distanceTo(identical), closeTo(Math.abs(i), ACCURACY)); assertThat(line.distanceTo(parallel), closeTo(SumatraMath.sqrt(1 + i * i), ACCURACY)); } else { assertThat(line.distanceTo(identical), closeTo(0, ACCURACY)); assertThat(line.distanceTo(parallel), closeTo(1, ACCURACY)); } assertThat(invalidLine.distanceTo(parallel), closeTo(Math.sqrt(1 + i * i), ACCURACY)); } }
public static IHalfLine fromDirection(final IVector2 supportVector, final IVector2 directionVector) { IVector2 sV = Vector2.copy(supportVector); IVector2 dV = directionVector.normalizeNew(); return createNewWithoutCopy(sV, dV); }
HalfLine extends AUnboundedLine implements IHalfLine { public static IHalfLine fromDirection(final IVector2 supportVector, final IVector2 directionVector) { IVector2 sV = Vector2.copy(supportVector); IVector2 dV = directionVector.normalizeNew(); return createNewWithoutCopy(sV, dV); } }
HalfLine extends AUnboundedLine implements IHalfLine { public static IHalfLine fromDirection(final IVector2 supportVector, final IVector2 directionVector) { IVector2 sV = Vector2.copy(supportVector); IVector2 dV = directionVector.normalizeNew(); return createNewWithoutCopy(sV, dV); } private  HalfLine(final IVector2 supportVector, final IVector2 directionVector); }
HalfLine extends AUnboundedLine implements IHalfLine { public static IHalfLine fromDirection(final IVector2 supportVector, final IVector2 directionVector) { IVector2 sV = Vector2.copy(supportVector); IVector2 dV = directionVector.normalizeNew(); return createNewWithoutCopy(sV, dV); } private  HalfLine(final IVector2 supportVector, final IVector2 directionVector); static IHalfLine fromDirection(final IVector2 supportVector, final IVector2 directionVector); @Override boolean equals(final Object other); @Override int hashCode(); @Override IVector2 closestPointOnLine(final IVector2 point); @Override ILine toLine(); @Override IHalfLine copy(); @Override Optional<IVector2> intersectLine(final ILine line); @Override Optional<IVector2> intersectHalfLine(final IHalfLine other); @Override Optional<IVector2> intersectSegment(final ILineSegment segment); @Override boolean isPointInFront(final IVector2 point); @Override String toString(); }
HalfLine extends AUnboundedLine implements IHalfLine { public static IHalfLine fromDirection(final IVector2 supportVector, final IVector2 directionVector) { IVector2 sV = Vector2.copy(supportVector); IVector2 dV = directionVector.normalizeNew(); return createNewWithoutCopy(sV, dV); } private  HalfLine(final IVector2 supportVector, final IVector2 directionVector); static IHalfLine fromDirection(final IVector2 supportVector, final IVector2 directionVector); @Override boolean equals(final Object other); @Override int hashCode(); @Override IVector2 closestPointOnLine(final IVector2 point); @Override ILine toLine(); @Override IHalfLine copy(); @Override Optional<IVector2> intersectLine(final ILine line); @Override Optional<IVector2> intersectHalfLine(final IHalfLine other); @Override Optional<IVector2> intersectSegment(final ILineSegment segment); @Override boolean isPointInFront(final IVector2 point); @Override String toString();  }