VecmathUtil { static Point2d intersection(final Tuple2d p1, final Tuple2d d1, final Tuple2d p2, final Tuple2d d2) { final Vector2d p1End = sum(p1, d1); final Vector2d p2End = sum(p2, d2); return intersection(p1.x, p1.y, p1End.x, p1End.y, p2.x, p2.y, p2End.x, p2End.y); } private  VecmathUtil();   }
@Test public void intersection1() { Tuple2d intersect = VecmathUtil.intersection(new Point2d(1, 1), new Vector2d(0, 1), new Point2d(1, 0), new Vector2d(1, 0)); assertThat(intersect.x, closeTo(1.0, 0.01)); assertThat(intersect.y, closeTo(0.0, 0.01)); }
@Test public void intersection2() { Tuple2d intersect = VecmathUtil.intersection(new Point2d(6, 1), new Vector2d(-4, -2), new Point2d(1, 6), new Vector2d(2, 4)); assertThat(intersect.x, closeTo(-4, 0.01)); assertThat(intersect.y, closeTo(-4, 0.01)); }
@Test public void parallelLines() { Tuple2d intersect = VecmathUtil.intersection(new Point2d(0, 1), new Vector2d(0, 1), new Point2d(0, -1), new Vector2d(0, 1)); assertTrue(Double.isNaN(intersect.x)); assertTrue(Double.isNaN(intersect.y)); }