Point { static DoublePoint getUnitNormal(LongPoint pt1, LongPoint pt2) { double dx = pt2.x - pt1.x; double dy = pt2.y - pt1.y; if (dx == 0 && dy == 0) { return new DoublePoint(); } final double f = 1 * 1.0 / Math.sqrt(dx * dx + dy * dy); dx *= f; dy *= f; return new DoublePoint(dy, -dx); } 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 getUnitNormalTest() { LongPoint pt1 = new LongPoint(1, 1); LongPoint pt2 = new LongPoint(1, 1); Assert.assertEquals(new DoublePoint(), Point.getUnitNormal(pt1, pt2)); pt2.setX(5L); Assert.assertEquals(new DoublePoint(0, -1), Point.getUnitNormal(pt1, pt2)); pt2.setY(4L); DoublePoint dp = Point.getUnitNormal(pt1, pt2); Assert.assertEquals(0.6, dp.getX(), DOUBLE_EPSILON_COMPARISON); Assert.assertEquals(-0.8, dp.getY(), DOUBLE_EPSILON_COMPARISON); }