@Test public void compare() { double x = penAreaBoundary.getCorner1().x(); double y = penAreaBoundary.getCorner2().y(); assertThat(penAreaBoundary.compare(Vector2.fromXY(x, 0), Vector2.fromXY(x, 0))).isEqualTo(0); assertThat(penAreaBoundary.compare(Vector2.fromXY(x, 50), Vector2.fromXY(x, 50))).isEqualTo(0); assertThat(penAreaBoundary.compare(Vector2.fromXY(x - 50, y), Vector2.fromXY(x - 50, y))).isEqualTo(0); assertThat(penAreaBoundary.compare(Vector2.fromXY(x - 50, -y), Vector2.fromXY(x - 50, -y))).isEqualTo(0); assertThat(penAreaBoundary.compare(Vector2.fromXY(x - 100, -y), Vector2.fromXY(x - 99, -y))).isEqualTo(-1); assertThat(penAreaBoundary.compare(Vector2.fromXY(x - 99, -y), Vector2.fromXY(x - 100, -y))).isEqualTo(1); assertThat(penAreaBoundary.compare(Vector2.fromXY(x, 50), Vector2.fromXY(x, 51))).isEqualTo(-1); assertThat(penAreaBoundary.compare(Vector2.fromXY(x, 51), Vector2.fromXY(x, 50))).isEqualTo(1); assertThat(penAreaBoundary.compare(Vector2.fromXY(x, -50), Vector2.fromXY(x, -49))).isEqualTo(-1); assertThat(penAreaBoundary.compare(Vector2.fromXY(x, -49), Vector2.fromXY(x, -50))).isEqualTo(1); assertThat(penAreaBoundary.compare(Vector2.fromXY(x, -50), Vector2.fromXY(x, 50))).isEqualTo(-1); assertThat(penAreaBoundary.compare(Vector2.fromXY(x, 50), Vector2.fromXY(x, -50))).isEqualTo(1); assertThat(penAreaBoundary.compare(Vector2.fromXY(x - 100, y), Vector2.fromXY(x - 99, y))).isEqualTo(1); assertThat(penAreaBoundary.compare(Vector2.fromXY(x - 99, y), Vector2.fromXY(x - 100, y))).isEqualTo(-1); assertThat(penAreaBoundary.compare(Vector2.fromXY(x - 50, -y), Vector2.fromXY(x, -y + 80))).isEqualTo(-1); assertThat(penAreaBoundary.compare(Vector2.fromXY(x, -y + 80), Vector2.fromXY(x - 50, -y))).isEqualTo(1); assertThat(penAreaBoundary.compare(Vector2.fromXY(x - 50, y), Vector2.fromXY(x, y - 80))).isEqualTo(1); assertThat(penAreaBoundary.compare(Vector2.fromXY(x, y - 80), Vector2.fromXY(x - 50, y))).isEqualTo(-1); assertThat(penAreaBoundary.compare(Vector2.fromXY(x - 50, -y), Vector2.fromXY(x - 50, y))).isEqualTo(-1); assertThat(penAreaBoundary.compare(Vector2.fromXY(x - 50, y), Vector2.fromXY(x - 50, -y))).isEqualTo(1); }
@Override public int compare(IVector2 p1, IVector2 p2) { final IVector2 cp1 = projectPoint(p1); final IVector2 cp2 = projectPoint(p2); ILineSegment edge1 = edgeOf(cp1); ILineSegment edge2 = edgeOf(cp2); if (edge1 == edge2) { double distance1 = edge1.getStart().distanceToSqr(cp1); double distance2 = edge2.getStart().distanceToSqr(cp2); if (distance1 < distance2) { return -1; } else if (distance1 > distance2) { return 1; } return 0; } for (ILineSegment edge : edges) { if (edge1 == edge) { return -1; } if (edge2 == edge) { return 1; } } return 0; }
PenAreaBoundary implements Comparator<IVector2> { @Override public int compare(IVector2 p1, IVector2 p2) { final IVector2 cp1 = projectPoint(p1); final IVector2 cp2 = projectPoint(p2); ILineSegment edge1 = edgeOf(cp1); ILineSegment edge2 = edgeOf(cp2); if (edge1 == edge2) { double distance1 = edge1.getStart().distanceToSqr(cp1); double distance2 = edge2.getStart().distanceToSqr(cp2); if (distance1 < distance2) { return -1; } else if (distance1 > distance2) { return 1; } return 0; } for (ILineSegment edge : edges) { if (edge1 == edge) { return -1; } if (edge2 == edge) { return 1; } } return 0; } }
PenAreaBoundary implements Comparator<IVector2> { @Override public int compare(IVector2 p1, IVector2 p2) { final IVector2 cp1 = projectPoint(p1); final IVector2 cp2 = projectPoint(p2); ILineSegment edge1 = edgeOf(cp1); ILineSegment edge2 = edgeOf(cp2); if (edge1 == edge2) { double distance1 = edge1.getStart().distanceToSqr(cp1); double distance2 = edge2.getStart().distanceToSqr(cp2); if (distance1 < distance2) { return -1; } else if (distance1 > distance2) { return 1; } return 0; } for (ILineSegment edge : edges) { if (edge1 == edge) { return -1; } if (edge2 == edge) { return 1; } } return 0; } private  PenAreaBoundary(final double width, final double depth, final double sign); }
PenAreaBoundary implements Comparator<IVector2> { @Override public int compare(IVector2 p1, IVector2 p2) { final IVector2 cp1 = projectPoint(p1); final IVector2 cp2 = projectPoint(p2); ILineSegment edge1 = edgeOf(cp1); ILineSegment edge2 = edgeOf(cp2); if (edge1 == edge2) { double distance1 = edge1.getStart().distanceToSqr(cp1); double distance2 = edge2.getStart().distanceToSqr(cp2); if (distance1 < distance2) { return -1; } else if (distance1 > distance2) { return 1; } return 0; } for (ILineSegment edge : edges) { if (edge1 == edge) { return -1; } if (edge2 == edge) { return 1; } } return 0; } 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> { @Override public int compare(IVector2 p1, IVector2 p2) { final IVector2 cp1 = projectPoint(p1); final IVector2 cp2 = projectPoint(p2); ILineSegment edge1 = edgeOf(cp1); ILineSegment edge2 = edgeOf(cp2); if (edge1 == edge2) { double distance1 = edge1.getStart().distanceToSqr(cp1); double distance2 = edge2.getStart().distanceToSqr(cp2); if (distance1 < distance2) { return -1; } else if (distance1 > distance2) { return 1; } return 0; } for (ILineSegment edge : edges) { if (edge1 == edge) { return -1; } if (edge2 == edge) { return 1; } } return 0; } 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();  }