@Test public void lineIntersectionsWithLineSegment() { assertThat(penaltyArea.lineIntersections( Lines.segmentFromPoints(center, goalCenter))) .as("Does not intersect front border center") .containsExactly(penBorderCenter); assertThat(penaltyArea.lineIntersections( Lines.segmentFromPoints(Vector2.fromY(100), goalCenter.addNew(Vector2.fromY(100))))) .as("Does not intersect front border positive y") .containsExactly(Vector2.fromXY(borderX, 100)); assertThat(penaltyArea.lineIntersections( Lines.segmentFromPoints(Vector2.fromY(-100), goalCenter.addNew(Vector2.fromY(-100))))) .as("Does not intersect front border negative y") .containsExactly(Vector2.fromXY(borderX, -100)); assertThat(penaltyArea.lineIntersections( Lines.segmentFromPoints(Vector2.fromY(100), goalCenter.addNew(Vector2.fromXY(10, 100))))) .as("Does not does not intersect goal line") .containsExactly(Vector2.fromXY(borderX, 100)); assertThat(penaltyArea.lineIntersections( Lines.segmentFromPoints(Vector2.fromXY(goalX + depth / 2, length), Vector2.fromXY(goalX + depth / 2, 0)))) .as("Does not intersect positive side border") .containsExactly(Vector2.fromXY(goalX + depth / 2, length / 2)); assertThat(penaltyArea.lineIntersections( Lines.segmentFromPoints(Vector2.fromXY(goalX + depth / 2, -length), Vector2.fromXY(goalX + depth / 2, 0)))) .as("Does not intersect negative side border") .containsExactly(Vector2.fromXY(goalX + depth / 2, -length / 2)); assertThat(penaltyArea.lineIntersections( Lines.segmentFromPoints(Vector2.fromXY(goalX + depth * 2, length), goalCenter))) .as("Does not intersect positive upper corner") .containsExactly(Vector2.fromXY(goalX + depth, length / 2)); assertThat(penaltyArea.lineIntersections( Lines.segmentFromPoints(Vector2.fromXY(goalX + depth * 2, -length), goalCenter))) .as("Does not intersect negative upper corner") .containsExactly(Vector2.fromXY(goalX + depth, -length / 2)); assertThat(penaltyArea.lineIntersections( Lines.segmentFromPoints(center, Vector2.fromX(-100)))) .as("Intersection when line segment outside") .isEmpty(); assertThat(penaltyArea.lineIntersections( Lines.segmentFromPoints(goalCenter.addNew(Vector2.fromXY(-100, length)), goalCenter.addNew(Vector2.fromXY(100, -100))))) .as("Intersection when line segment crosses goal line only") .isEmpty(); }
@Override public List<IVector2> lineIntersections(final edu.tigers.sumatra.math.line.v2.ILine line) { return getEdges().stream() .map(edge -> edge.intersectLine(line)) .filter(Optional::isPresent) .map(Optional::get) .distinct() .collect(Collectors.toList()); }
PenaltyArea implements IPenaltyArea { @Override public List<IVector2> lineIntersections(final edu.tigers.sumatra.math.line.v2.ILine line) { return getEdges().stream() .map(edge -> edge.intersectLine(line)) .filter(Optional::isPresent) .map(Optional::get) .distinct() .collect(Collectors.toList()); } }
PenaltyArea implements IPenaltyArea { @Override public List<IVector2> lineIntersections(final edu.tigers.sumatra.math.line.v2.ILine line) { return getEdges().stream() .map(edge -> edge.intersectLine(line)) .filter(Optional::isPresent) .map(Optional::get) .distinct() .collect(Collectors.toList()); } PenaltyArea(final IVector2 goalCenter, final double depth, final double length); }
PenaltyArea implements IPenaltyArea { @Override public List<IVector2> lineIntersections(final edu.tigers.sumatra.math.line.v2.ILine line) { return getEdges().stream() .map(edge -> edge.intersectLine(line)) .filter(Optional::isPresent) .map(Optional::get) .distinct() .collect(Collectors.toList()); } PenaltyArea(final IVector2 goalCenter, final double depth, final double length); @Override IPenaltyArea withMargin(final double margin); @Override List<IVector2> lineIntersections(final edu.tigers.sumatra.math.line.v2.ILine line); @Override List<IVector2> lineIntersections(final ILineSegment line); @Override List<IVector2> lineIntersections(final IHalfLine line); @Override List<IVector2> lineIntersections(final ILine line); @Override @SuppressWarnings("squid:S1244") // equality check intended IVector2 projectPointOnToPenaltyAreaBorder(final IVector2 point); @Override boolean isPointInShape(final IVector2 point); @Override boolean isPointInShape(final IVector2 point, final double margin); @Override boolean isPointInShapeOrBehind(final IVector2 point); @Override IVector2 nearestPointInside(final IVector2 point); @Override IVector2 nearestPointOutside(final IVector2 point); @Override boolean isIntersectingWithLine(final ILine line); @Override boolean isBehindPenaltyArea(final IVector2 point); @Override IVector2 getGoalCenter(); @Override Rectangle getRectangle(); @Override IVector2 getNegCorner(); @Override IVector2 getPosCorner(); @Override List<IDrawableShape> getDrawableShapes(); @Override double distanceTo(final IVector2 point); @Override double distanceToNearestPointOutside(final IVector2 pos); @Override double intersectionArea(final IVector2 from, final IVector2 to); }
PenaltyArea implements IPenaltyArea { @Override public List<IVector2> lineIntersections(final edu.tigers.sumatra.math.line.v2.ILine line) { return getEdges().stream() .map(edge -> edge.intersectLine(line)) .filter(Optional::isPresent) .map(Optional::get) .distinct() .collect(Collectors.toList()); } PenaltyArea(final IVector2 goalCenter, final double depth, final double length); @Override IPenaltyArea withMargin(final double margin); @Override List<IVector2> lineIntersections(final edu.tigers.sumatra.math.line.v2.ILine line); @Override List<IVector2> lineIntersections(final ILineSegment line); @Override List<IVector2> lineIntersections(final IHalfLine line); @Override List<IVector2> lineIntersections(final ILine line); @Override @SuppressWarnings("squid:S1244") // equality check intended IVector2 projectPointOnToPenaltyAreaBorder(final IVector2 point); @Override boolean isPointInShape(final IVector2 point); @Override boolean isPointInShape(final IVector2 point, final double margin); @Override boolean isPointInShapeOrBehind(final IVector2 point); @Override IVector2 nearestPointInside(final IVector2 point); @Override IVector2 nearestPointOutside(final IVector2 point); @Override boolean isIntersectingWithLine(final ILine line); @Override boolean isBehindPenaltyArea(final IVector2 point); @Override IVector2 getGoalCenter(); @Override Rectangle getRectangle(); @Override IVector2 getNegCorner(); @Override IVector2 getPosCorner(); @Override List<IDrawableShape> getDrawableShapes(); @Override double distanceTo(final IVector2 point); @Override double distanceToNearestPointOutside(final IVector2 pos); @Override double intersectionArea(final IVector2 from, final IVector2 to);  }