@Test public void closestPoint() { assertThat(penAreaBoundary.closestPoint(Vector2.zero())) .isEqualTo(Vector2.fromX(penAreaBoundary.getCorner1().x())); assertThat(penAreaBoundary.closestPoint(Vector2.fromY(-50))) .isEqualTo(Vector2.fromXY(penAreaBoundary.getCorner1().x(), -50)); assertThat(penAreaBoundary.closestPoint(Vector2.fromXY(penAreaBoundary.getCorner1().x() - 50, -5000))) .isEqualTo(Vector2.fromXY(penAreaBoundary.getCorner1().x() - 50, penAreaBoundary.getCorner1().y())); assertThat(penAreaBoundary.closestPoint(Vector2.fromXY(penAreaBoundary.getCorner1().x() - 50, 5000))) .isEqualTo(Vector2.fromXY(penAreaBoundary.getCorner1().x() - 50, penAreaBoundary.getCorner2().y())); assertThat(penAreaBoundary .closestPoint(Vector2.fromXY(penAreaBoundary.getStart().x() - 100, -penAreaBoundary.getWidth()))) .isEqualTo(Vector2.fromXY(penAreaBoundary.getStart().x(), penAreaBoundary.getStart().y())); assertThat(penAreaBoundary .closestPoint(Vector2.fromXY(penAreaBoundary.getStart().x() - 100, penAreaBoundary.getWidth()))) .isEqualTo(Vector2.fromXY(penAreaBoundary.getStart().x(), penAreaBoundary.getEnd().y())); }
public IVector2 closestPoint(final IVector2 p) { return edges.stream().min(Comparator.comparingDouble(l -> l.distanceTo(p))) .map(l -> l.closestPointOnLine(p)).orElseThrow(IllegalStateException::new); }
PenAreaBoundary implements Comparator<IVector2> { public IVector2 closestPoint(final IVector2 p) { return edges.stream().min(Comparator.comparingDouble(l -> l.distanceTo(p))) .map(l -> l.closestPointOnLine(p)).orElseThrow(IllegalStateException::new); } }
PenAreaBoundary implements Comparator<IVector2> { public IVector2 closestPoint(final IVector2 p) { return edges.stream().min(Comparator.comparingDouble(l -> l.distanceTo(p))) .map(l -> l.closestPointOnLine(p)).orElseThrow(IllegalStateException::new); } private  PenAreaBoundary(final double width, final double depth, final double sign); }
PenAreaBoundary implements Comparator<IVector2> { public IVector2 closestPoint(final IVector2 p) { return edges.stream().min(Comparator.comparingDouble(l -> l.distanceTo(p))) .map(l -> l.closestPointOnLine(p)).orElseThrow(IllegalStateException::new); } private  PenAreaBoundary(final double width, final double depth, final double sign); static PenAreaBoundary ownWithMargin(final double margin); PenAreaBoundary withMargin(final double margin); IVector2 closestPoint(final IVector2 p); IVector2 projectPoint(final IVector2 p); IVector2 projectPoint(final IVector2 p1, final IVector2 p2); Optional<IVector2> nextTo(final IVector2 p, final double margin, final int direction); Optional<IVector2> nextIntermediateCorner(final IVector2 pFrom, final IVector2 pTo); double distanceBetween(final IVector2 p1, final IVector2 p2); @Override int compare(IVector2 p1, IVector2 p2); Optional<IVector2> stepAlongBoundary(final IVector2 start, final double distance); boolean isPointInShape(IVector2 point); double getWidth(); double getDepth(); IVector2 getStart(); IVector2 getCorner1(); IVector2 getCorner2(); IVector2 getEnd(); IVector2 getCenter(); }
PenAreaBoundary implements Comparator<IVector2> { public IVector2 closestPoint(final IVector2 p) { return edges.stream().min(Comparator.comparingDouble(l -> l.distanceTo(p))) .map(l -> l.closestPointOnLine(p)).orElseThrow(IllegalStateException::new); } private  PenAreaBoundary(final double width, final double depth, final double sign); static PenAreaBoundary ownWithMargin(final double margin); PenAreaBoundary withMargin(final double margin); IVector2 closestPoint(final IVector2 p); IVector2 projectPoint(final IVector2 p); IVector2 projectPoint(final IVector2 p1, final IVector2 p2); Optional<IVector2> nextTo(final IVector2 p, final double margin, final int direction); Optional<IVector2> nextIntermediateCorner(final IVector2 pFrom, final IVector2 pTo); double distanceBetween(final IVector2 p1, final IVector2 p2); @Override int compare(IVector2 p1, IVector2 p2); Optional<IVector2> stepAlongBoundary(final IVector2 start, final double distance); boolean isPointInShape(IVector2 point); double getWidth(); double getDepth(); IVector2 getStart(); IVector2 getCorner1(); IVector2 getCorner2(); IVector2 getEnd(); IVector2 getCenter();  }