@Test
@Repeat(iterations = 15)
public void quadrants() {
//random line
BufferedLine line = newRandomLine();
// if (line.getA().equals(line.getB()))
// return;//this test doesn't work
Rectangle rect = newRandomLine().getBoundingBox();
//logShapes(line, rect);
//compute closest corner brute force
ArrayList<Point> corners = quadrantCorners(rect);
// a collection instead of 1 value due to ties
Collection<Integer> farthestDistanceQuads = new LinkedList<Integer>();
double farthestDistance = -1;
int quad = 1;
for (Point corner : corners) {
double d = line.getLinePrimary().distanceUnbuffered(corner);
if (Math.abs(d - farthestDistance) < 0.000001) {//about equal
farthestDistanceQuads.add(quad);
} else if (d > farthestDistance) {
farthestDistanceQuads.clear();
farthestDistanceQuads.add(quad);
farthestDistance = d;
}
quad++;
}
//compare results
int calcClosestQuad = line.getLinePrimary().quadrant(rect.getCenter());
assertTrue(farthestDistanceQuads.contains(calcClosestQuad));
}