@Test public void nearestPointOutside() { assertThat(penaltyArea.nearestPointOutside(center)) .as("Center is outside and should be returned as-is") .isEqualTo(center); assertThat(penaltyArea.nearestPointOutside(goalCenter)) .as("Goal center should be moved to border") .isIn(Vector2.fromXY(goalX, length / 2), Vector2.fromXY(goalX, -length / 2), Vector2.fromXY(goalX + depth, 0)); assertThat(penaltyArea.nearestPointOutside(Vector2.fromXY(goalX + 1, 0))) .as("Point inside should be outside") .isEqualTo(Vector2.fromXY(borderX, 0)); assertThat(penaltyArea.nearestPointOutside(Vector2.fromXY(goalX, 1))) .as("Point inside should be outside") .isEqualTo(Vector2.fromXY(goalX, length / 2)); assertThat(penaltyArea.nearestPointOutside(Vector2.fromXY(goalX, -1))) .as("Point inside should be outside") .isEqualTo(Vector2.fromXY(goalX, -length / 2)); assertThat(penaltyArea.nearestPointOutside(Vector2.fromXY(borderX - 1, 1))) .as("Point inside should be outside") .isEqualTo(Vector2.fromXY(borderX, 1)); assertThat(penaltyArea.nearestPointOutside(Vector2.fromXY(borderX - 1, -1))) .as("Point inside should be outside") .isEqualTo(Vector2.fromXY(borderX, -1)); assertThat(penaltyArea.nearestPointOutside(Vector2.fromXY(goalX - 1, 0))) .as("Point outside should be outside") .isEqualTo(Vector2.fromXY(goalX - 1, 0)); }
@Override public IVector2 nearestPointOutside(final IVector2 point) { if (getRectangle().isPointInShape(point)) { return point.nearestTo( getEdges().stream() .map(e -> e.closestPointOnLine(point)) .collect(Collectors.toList())); } return point; }
PenaltyArea implements IPenaltyArea { @Override public IVector2 nearestPointOutside(final IVector2 point) { if (getRectangle().isPointInShape(point)) { return point.nearestTo( getEdges().stream() .map(e -> e.closestPointOnLine(point)) .collect(Collectors.toList())); } return point; } }
PenaltyArea implements IPenaltyArea { @Override public IVector2 nearestPointOutside(final IVector2 point) { if (getRectangle().isPointInShape(point)) { return point.nearestTo( getEdges().stream() .map(e -> e.closestPointOnLine(point)) .collect(Collectors.toList())); } return point; } PenaltyArea(final IVector2 goalCenter, final double depth, final double length); }
PenaltyArea implements IPenaltyArea { @Override public IVector2 nearestPointOutside(final IVector2 point) { if (getRectangle().isPointInShape(point)) { return point.nearestTo( getEdges().stream() .map(e -> e.closestPointOnLine(point)) .collect(Collectors.toList())); } return point; } 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 IVector2 nearestPointOutside(final IVector2 point) { if (getRectangle().isPointInShape(point)) { return point.nearestTo( getEdges().stream() .map(e -> e.closestPointOnLine(point)) .collect(Collectors.toList())); } return point; } 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);  }