@Test public void testIntersectHalfLine() { IHalfLine lineA = HalfLine.fromDirection(Vector2f.ZERO_VECTOR, Vector2f.X_AXIS); IVector2 sV = Vector2.fromXY(0, 1); IVector2 dV = Vector2f.X_AXIS; for (int degAngle = 0; degAngle < 360; degAngle++) { double radAngle = Math.toRadians(degAngle); IHalfLine lineB = HalfLine.fromDirection(sV, dV.turnToNew(radAngle)); Optional<IVector2> intersection = lineA.intersectHalfLine(lineB); Optional<IVector2> inverseIntersection = lineB.intersectHalfLine(lineA); assertThat(intersection, is(inverseIntersection)); if (degAngle < 270) { assertThat(intersection, isNotPresent()); } else { IVector2 expected = Vector2.fromXY(SumatraMath.tan(radAngle - Math.PI * 3 / 2), 0); assertThat(intersection, isPresentAnd(is(expected))); } } }
@Override public Optional<IVector2> intersectHalfLine(final IHalfLine other) { if (this.isValid() && other.isValid()) { return LineMath.intersectionPointOfHalfLines(this, other); } return Optional.empty(); }
HalfLine extends AUnboundedLine implements IHalfLine { @Override public Optional<IVector2> intersectHalfLine(final IHalfLine other) { if (this.isValid() && other.isValid()) { return LineMath.intersectionPointOfHalfLines(this, other); } return Optional.empty(); } }
HalfLine extends AUnboundedLine implements IHalfLine { @Override public Optional<IVector2> intersectHalfLine(final IHalfLine other) { if (this.isValid() && other.isValid()) { return LineMath.intersectionPointOfHalfLines(this, other); } return Optional.empty(); } private  HalfLine(final IVector2 supportVector, final IVector2 directionVector); }
HalfLine extends AUnboundedLine implements IHalfLine { @Override public Optional<IVector2> intersectHalfLine(final IHalfLine other) { if (this.isValid() && other.isValid()) { return LineMath.intersectionPointOfHalfLines(this, other); } return Optional.empty(); } 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 { @Override public Optional<IVector2> intersectHalfLine(final IHalfLine other) { if (this.isValid() && other.isValid()) { return LineMath.intersectionPointOfHalfLines(this, other); } return Optional.empty(); } 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();  }