AbsoluteOneCenter { static <V> Double intersect(final Distance<V> distance, final V e0, final V e1, final double l, final V u, final V v) { final double lu = distance.getDistance(e0, u).doubleValue(); final double ru = distance.getDistance(e1, u).doubleValue(); final double lv = distance.getDistance(e0, v).doubleValue(); final double rv = distance.getDistance(e1, v).doubleValue(); if (lu == lv || ru == rv) { return null; } else if (lu > lv && ru > rv) { return null; } else if (lu < lv && ru < rv) { return null; } else { final double t1 = 0.5 * (rv - lu + l); final double t2 = 0.5 * (ru - lv + l); if (t1 + lu <= l - t1 + ru) { return t1; } else { return t2; } } } AbsoluteOneCenter(final UndirectedGraph<V, E> graph);  AbsoluteOneCenter(final UndirectedGraph<V, E> graph, final Comparator<V> comparator);  AbsoluteOneCenter(final UndirectedGraph<V, E> graph, final Transformer<E, Number> edgeLength);  AbsoluteOneCenter(final UndirectedGraph<V, E> graph, final Transformer<E, Number> edgeLength, final Comparator<V> comparator);  AbsoluteOneCenter(final UndirectedGraph<V, E> graph, final Transformer<E, Number> edgeLength, final Distance<V> distance);  AbsoluteOneCenter(final UndirectedGraph<V, E> graph, final Transformer<E, Number> edgeLength, final Distance<V> distance, final Comparator<V> comparator); PointOnEdge<V, E> getCenter();  }
@Test public void testIntersect() { final UndirectedGraph<Integer, Integer> g = lineGraph(); final Distance<Integer> distance1 = new DijkstraDistance<Integer, Integer>(g); assertEquals(0.5, AbsoluteOneCenter.intersect(distance1, 1, 2, 1.0, 0, 3), EPSILON); assertNull(AbsoluteOneCenter.intersect(distance1, 1, 2, 1.0, 0, 4)); final Distance<Integer> distance2 = new DijkstraDistance<Integer, Integer>(g, new EdgeLength(new double[] {1.0, 1.0, 1.0, 0.5})); assertEquals(0.5, AbsoluteOneCenter.intersect(distance2, 1, 2, 1.0, 0, 3), EPSILON); assertEquals(0.75, AbsoluteOneCenter.intersect(distance2, 1, 2, 1.0, 0, 4), EPSILON); final Distance<Integer> distance3 = new DijkstraDistance<Integer, Integer>(g, new EdgeLength(new double[] {1.0, 0.5, 1.0, 0.5})); assertEquals(0.25, AbsoluteOneCenter.intersect(distance3, 1, 2, 0.5, 0, 3), EPSILON); assertNull(AbsoluteOneCenter.intersect(distance3, 1, 2, 0.5, 0, 4)); }