@Test public void projectPointOnToPenaltyAreaBorder() { assertThat(penaltyArea.projectPointOnToPenaltyAreaBorder(Vector2.fromXY(0, 0))) .as("Center does not project to front border center") .isEqualTo(penBorderCenter); assertThat(penaltyArea.projectPointOnToPenaltyAreaBorder(goalCenter)) .as("Goal center does not project to front border center") .isEqualTo(penBorderCenter); assertThat(penaltyArea.projectPointOnToPenaltyAreaBorder(Vector2.fromXY(goalX - 1, 0))) .as("Behind goal center does not project to front border center") .isEqualTo(penBorderCenter); assertThat(penaltyArea.projectPointOnToPenaltyAreaBorder(Vector2.fromXY(borderX + 1, 0))) .as("In front of penArea does not project to front border center") .isEqualTo(penBorderCenter); assertThat(penaltyArea.projectPointOnToPenaltyAreaBorder(Vector2.fromXY(goalX + depth * 2, depth))) .as("Does not project to positive front from outside") .isEqualTo(Vector2.fromXY(borderX, length / 2 / 2)); assertThat(penaltyArea.projectPointOnToPenaltyAreaBorder(Vector2.fromXY(goalX + depth * 2, -depth))) .as("Does not project to negative front from outside") .isEqualTo(Vector2.fromXY(borderX, -length / 2 / 2)); assertThat(penaltyArea.projectPointOnToPenaltyAreaBorder(Vector2.fromXY(goalX + depth * 2, depth * 2))) .as("Does not project to positive corner from outside") .isEqualTo(Vector2.fromXY(borderX, length / 2)); assertThat(penaltyArea.projectPointOnToPenaltyAreaBorder(Vector2.fromXY(goalX + depth * 2, -depth * 2))) .as("Does not project to negative corner from outside") .isEqualTo(Vector2.fromXY(borderX, -length / 2)); assertThat(penaltyArea.projectPointOnToPenaltyAreaBorder(Vector2.fromXY(goalX + depth / 2, depth / 2))) .as("Does not project to positive corner from inside") .isEqualTo(Vector2.fromXY(borderX, length / 2)); assertThat(penaltyArea.projectPointOnToPenaltyAreaBorder(Vector2.fromXY(goalX + depth / 2, -depth / 2))) .as("Does not project to negative corner from inside") .isEqualTo(Vector2.fromXY(borderX, -length / 2)); assertThat(penaltyArea.projectPointOnToPenaltyAreaBorder(Vector2.fromXY(goalX + depth, length))) .as("Does not project to positive side from outside") .isEqualTo(Vector2.fromXY(borderX - depth / 2, length / 2)); assertThat(penaltyArea.projectPointOnToPenaltyAreaBorder(Vector2.fromXY(goalX + depth, -length))) .as("Does not project to negative side from outside") .isEqualTo(Vector2.fromXY(borderX - depth / 2, -length / 2)); assertThat(penaltyArea.projectPointOnToPenaltyAreaBorder(Vector2.fromXY(goalX + depth / 4, length / 4))) .as("Does not project to positive side from inside") .isEqualTo(Vector2.fromXY(borderX - depth / 2, length / 2)); assertThat(penaltyArea.projectPointOnToPenaltyAreaBorder(Vector2.fromXY(goalX + depth / 4, -length / 4))) .as("Does not project to negative side from inside") .isEqualTo(Vector2.fromXY(borderX - depth / 2, -length / 2)); assertThat(penaltyArea.projectPointOnToPenaltyAreaBorder(Vector2.fromXY(goalX, length))) .as("Does not project to lower positive corner") .isEqualTo(Vector2.fromXY(goalX, length / 2)); assertThat(penaltyArea.projectPointOnToPenaltyAreaBorder(Vector2.fromXY(goalX, -length))) .as("Does not project to lower negative corner") .isEqualTo(Vector2.fromXY(goalX, -length / 2)); assertThat(penaltyArea.projectPointOnToPenaltyAreaBorder(Vector2.fromXY(goalX - 100, length))) .as("Does not project to lower positive corner from outside field") .isEqualTo(Vector2.fromXY(goalX, length / 2)); assertThat(penaltyArea.projectPointOnToPenaltyAreaBorder(Vector2.fromXY(goalX - 100, -length))) .as("Does not project to lower negative corner from outside field") .isEqualTo(Vector2.fromXY(goalX, -length / 2)); }
@Override @SuppressWarnings("squid:S1244") public IVector2 projectPointOnToPenaltyAreaBorder(final IVector2 point) { if (point.x() * Math.signum(getGoalCenter().x()) >= Math.abs(getGoalCenter().x())) { if (point.y() == 0.0) { return getGoalCenter().addNew(Vector2.fromX(getDepth())); } return getGoalCenter().addNew(Vector2.fromY(Math.signum(point.y()) * getLength() / 2)); } return point.nearestToOpt(lineIntersections(Lines.lineFromPoints(point, getGoalCenter()))) .orElseGet(() -> getGoalCenter().addNew(Vector2.fromX(getDepth()))); }
PenaltyArea implements IPenaltyArea { @Override @SuppressWarnings("squid:S1244") public IVector2 projectPointOnToPenaltyAreaBorder(final IVector2 point) { if (point.x() * Math.signum(getGoalCenter().x()) >= Math.abs(getGoalCenter().x())) { if (point.y() == 0.0) { return getGoalCenter().addNew(Vector2.fromX(getDepth())); } return getGoalCenter().addNew(Vector2.fromY(Math.signum(point.y()) * getLength() / 2)); } return point.nearestToOpt(lineIntersections(Lines.lineFromPoints(point, getGoalCenter()))) .orElseGet(() -> getGoalCenter().addNew(Vector2.fromX(getDepth()))); } }
PenaltyArea implements IPenaltyArea { @Override @SuppressWarnings("squid:S1244") public IVector2 projectPointOnToPenaltyAreaBorder(final IVector2 point) { if (point.x() * Math.signum(getGoalCenter().x()) >= Math.abs(getGoalCenter().x())) { if (point.y() == 0.0) { return getGoalCenter().addNew(Vector2.fromX(getDepth())); } return getGoalCenter().addNew(Vector2.fromY(Math.signum(point.y()) * getLength() / 2)); } return point.nearestToOpt(lineIntersections(Lines.lineFromPoints(point, getGoalCenter()))) .orElseGet(() -> getGoalCenter().addNew(Vector2.fromX(getDepth()))); } PenaltyArea(final IVector2 goalCenter, final double depth, final double length); }
PenaltyArea implements IPenaltyArea { @Override @SuppressWarnings("squid:S1244") public IVector2 projectPointOnToPenaltyAreaBorder(final IVector2 point) { if (point.x() * Math.signum(getGoalCenter().x()) >= Math.abs(getGoalCenter().x())) { if (point.y() == 0.0) { return getGoalCenter().addNew(Vector2.fromX(getDepth())); } return getGoalCenter().addNew(Vector2.fromY(Math.signum(point.y()) * getLength() / 2)); } return point.nearestToOpt(lineIntersections(Lines.lineFromPoints(point, getGoalCenter()))) .orElseGet(() -> getGoalCenter().addNew(Vector2.fromX(getDepth()))); } 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 @SuppressWarnings("squid:S1244") public IVector2 projectPointOnToPenaltyAreaBorder(final IVector2 point) { if (point.x() * Math.signum(getGoalCenter().x()) >= Math.abs(getGoalCenter().x())) { if (point.y() == 0.0) { return getGoalCenter().addNew(Vector2.fromX(getDepth())); } return getGoalCenter().addNew(Vector2.fromY(Math.signum(point.y()) * getLength() / 2)); } return point.nearestToOpt(lineIntersections(Lines.lineFromPoints(point, getGoalCenter()))) .orElseGet(() -> getGoalCenter().addNew(Vector2.fromX(getDepth()))); } 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);  }