CartesianGeometricUtilities { public static double shortestDistanceToLineSegment(ILocated2D p1, ILocated2D l1, ILocated2D l2) { return shortestDistanceToLineSegment(p1.getX(), p1.getY(), l1.getX(), l2.getX(), l1.getY(), l2.getY()); }  static Tuple2D centerAndScale(Tuple2D toScale, int width, int height); static Vertex centerAndScale(Vertex toScale, int width, int height, int depth); static double centerAndScale(double toScale, int maxDimension); static Tuple2D Bottom1DCenterAndScale(Tuple2D toScale, int width, int height); static Tuple2D bottomCenterAndScale(Tuple2D toScale, int width, int height); static double bottomScale(double toScale, int maxDimension); static double shortestDistanceToLineSegment(ILocated2D p1, ILocated2D l1, ILocated2D l2); static double shortestDistanceToLineSegment(double x, double y, double x1, double x2, double y1, double y2); static double euclideanDistance(ArrayList<Double> x1, ArrayList<Double> x2); static double[] polarToCartesian(double r, double theta); static double signedAngleFromSourceHeadingToTarget(ILocated2D source, ILocated2D target, double sourceRads); static double signedAngleDifference(ILocated2D v1, ILocated2D v2); static double signedAngleDifference(double rad1, double rad2); static boolean sourceHeadingTowardsTarget(double sourceRadians, ILocated2D source, ILocated2D target,
			double allowance); static boolean onSideOf(ILocated2D source, double sourceRadians, ILocated2D other, boolean right); static double restrictRadians(double rads);  }
@Test public void testShortestDistanceToLineSegment() { ILocated2D bottomOfSegment = new Tuple2D(0, 0); ILocated2D topOfSegment = new Tuple2D(0, 1); ILocated2D point = new Tuple2D(1, 0); ILocated2D otherPoint = new Tuple2D(1, 1.5); ILocated2D paramLessThanZero = new Tuple2D(0, -1); ILocated2D paramGreaterThanOne = new Tuple2D(1, 2); assertEquals(CartesianGeometricUtilities.shortestDistanceToLineSegment(point, topOfSegment, bottomOfSegment), 1.0, DOUBLE_THRESHOLD); assertEquals( CartesianGeometricUtilities.shortestDistanceToLineSegment(otherPoint, topOfSegment, bottomOfSegment), 1.1180, DOUBLE_THRESHOLD); assertEquals( CartesianGeometricUtilities.shortestDistanceToLineSegment(paramLessThanZero, topOfSegment, bottomOfSegment), 1.0, DOUBLE_THRESHOLD); assertEquals( CartesianGeometricUtilities.shortestDistanceToLineSegment(paramGreaterThanOne, topOfSegment, bottomOfSegment), 1.4142, DOUBLE_THRESHOLD); }