VecmathUtil { static Vector2d newUnitVector(final Tuple2d from, final Tuple2d to) { final Vector2d vector = new Vector2d(to.x - from.x, to.y - from.y); vector.normalize(); return vector; } private  VecmathUtil();   }
@Test public void testNewUnitVector() throws Exception { Vector2d unit = VecmathUtil.newUnitVector(new Point2d(4, 2), new Point2d(6, 7)); assertThat(unit.x, closeTo(0.371d, 0.01)); assertThat(unit.y, closeTo(0.928d, 0.01)); assertThat(unit.length(), closeTo(1d, 0.01)); }
@Test public void testNewUnitVectorFromBond() throws Exception { IAtom a1 = mock(IAtom.class); IAtom a2 = mock(IAtom.class); when(a1.getPoint2d()).thenReturn(new Point2d(0, 1)); when(a2.getPoint2d()).thenReturn(new Point2d(1, 0)); IBond bond = mock(IBond.class); when(bond.getOther(a1)).thenReturn(a2); when(bond.getOther(a2)).thenReturn(a1); Vector2d unit = VecmathUtil.newUnitVector(a1, bond); assertThat(unit.x, closeTo(0.707d, 0.01)); assertThat(unit.y, closeTo(-0.707d, 0.01)); assertThat(unit.length(), closeTo(1d, 0.01)); }