Point { static boolean slopesNearCollinear(LongPoint pt1, LongPoint pt2, LongPoint pt3, double distSqrd) { if (Math.abs(pt1.x - pt2.x) > Math.abs(pt1.y - pt2.y)) { if (pt1.x > pt2.x == pt1.x < pt3.x) { return distanceFromLineSqrd(pt1, pt2, pt3) < distSqrd; } else if (pt2.x > pt1.x == pt2.x < pt3.x) { return distanceFromLineSqrd(pt2, pt1, pt3) < distSqrd; } else { return distanceFromLineSqrd(pt3, pt1, pt2) < distSqrd; } } else { if (pt1.y > pt2.y == pt1.y < pt3.y) { return distanceFromLineSqrd(pt1, pt2, pt3) < distSqrd; } else if (pt2.y > pt1.y == pt2.y < pt3.y) { return distanceFromLineSqrd(pt2, pt1, pt3) < distSqrd; } else { return distanceFromLineSqrd(pt3, pt1, pt2) < distSqrd; } } } protected  Point(Point<T> pt); protected  Point(T x, T y, T z); @Override boolean equals(Object obj); void set(Point<T> other); void setX(T x); void setY(T y); void setZ(T z); @Override String toString();  }
@Test public void slopesNearCollinearTest01() { LongPoint pt1 = new LongPoint(5, 2); LongPoint pt2 = new LongPoint(1, 1); LongPoint pt3 = new LongPoint(6, 2); Assert.assertTrue(Point.slopesNearCollinear(pt1, pt2, pt3, 0.04)); Assert.assertFalse(Point.slopesNearCollinear(pt1, pt2, pt3, 0.03)); pt1 = new LongPoint(2, 5); pt2 = new LongPoint(1, 1); pt3 = new LongPoint(2, 6); Assert.assertTrue(Point.slopesNearCollinear(pt1, pt2, pt3, 0.04)); Assert.assertFalse(Point.slopesNearCollinear(pt1, pt2, pt3, 0.03)); }
@Test public void slopesNearCollinearTest02() { LongPoint pt1 = new LongPoint(1, 1); LongPoint pt2 = new LongPoint(5, 2); LongPoint pt3 = new LongPoint(6, 2); Assert.assertTrue(Point.slopesNearCollinear(pt1, pt2, pt3, 0.04)); Assert.assertFalse(Point.slopesNearCollinear(pt1, pt2, pt3, 0.03)); pt1 = new LongPoint(1, 1); pt2 = new LongPoint(2, 5); pt3 = new LongPoint(2, 6); Assert.assertTrue(Point.slopesNearCollinear(pt1, pt2, pt3, 0.04)); Assert.assertFalse(Point.slopesNearCollinear(pt1, pt2, pt3, 0.03)); }
@Test public void slopesNearCollinearTest03() { LongPoint pt1 = new LongPoint(1, 1); LongPoint pt2 = new LongPoint(6, 2); LongPoint pt3 = new LongPoint(5, 2); Assert.assertTrue(Point.slopesNearCollinear(pt1, pt2, pt3, 0.04)); Assert.assertFalse(Point.slopesNearCollinear(pt1, pt2, pt3, 0.03)); pt1 = new LongPoint(1, 1); pt2 = new LongPoint(2, 6); pt3 = new LongPoint(2, 5); Assert.assertTrue(Point.slopesNearCollinear(pt1, pt2, pt3, 0.04)); Assert.assertFalse(Point.slopesNearCollinear(pt1, pt2, pt3, 0.03)); }