@Test public void testJumpToDifferentCorner() { Set<Edge> cornerEdges = new HashSet<Edge>(); cornerEdges.add(new Edge(createXYPoint(0,0), createXYPoint(0,4))); cornerEdges.add(new Edge(createXYPoint(0,0), createXYPoint(4,0))); cornerEdges.add(new Edge(createXYPoint(4,4), createXYPoint(0,4))); SimpleWaySnap simpleWaySnap = new SimpleWaySnap(new XYPointFactory(), cornerEdges); NicGeoPoint geoPointIn1 = createXYPoint(2,5); NicGeoPoint geoPointOut1 = simpleWaySnap.snap(geoPointIn1); NicGeoPoint expected1 = createXYPoint(2,4); assertEquals(expected1, geoPointOut1); NicGeoPoint geoPointIn2 = createXYPoint(1,1); NicGeoPoint geoPointOut2 = simpleWaySnap.snap(geoPointIn2); NicGeoPoint expected2a = createXYPoint(1, 0); NicGeoPoint expected2b = createXYPoint(0,1); assertTrue(geoPointOut2.equals(expected2a) || geoPointOut2.equals(expected2b)); NicGeoPoint expected3 = geoPointOut2; NicGeoPoint geoPointOut3 = simpleWaySnap.snap(geoPointIn2); assertEquals(expected3, geoPointOut3); }
public NicGeoPoint snap(NicGeoPoint point) { if (edges != null) { edgesByDistance = new TreeMap<Float, Edge>(); nearestPoints = new HashMap<Edge, NicGeoPoint>(); for (final Edge edge : edges) { final float distance = distance(edge, point); if ((!edgesByDistance.containsKey(distance)) || (edge == lastEdge)) { edgesByDistance.put(distance, edge); } } lastEdge = edgesByDistance.get(edgesByDistance.firstKey()); point = nearestPoints.get(lastEdge); } return point; }
SimpleWaySnap { public NicGeoPoint snap(NicGeoPoint point) { if (edges != null) { edgesByDistance = new TreeMap<Float, Edge>(); nearestPoints = new HashMap<Edge, NicGeoPoint>(); for (final Edge edge : edges) { final float distance = distance(edge, point); if ((!edgesByDistance.containsKey(distance)) || (edge == lastEdge)) { edgesByDistance.put(distance, edge); } } lastEdge = edgesByDistance.get(edgesByDistance.firstKey()); point = nearestPoints.get(lastEdge); } return point; } }
SimpleWaySnap { public NicGeoPoint snap(NicGeoPoint point) { if (edges != null) { edgesByDistance = new TreeMap<Float, Edge>(); nearestPoints = new HashMap<Edge, NicGeoPoint>(); for (final Edge edge : edges) { final float distance = distance(edge, point); if ((!edgesByDistance.containsKey(distance)) || (edge == lastEdge)) { edgesByDistance.put(distance, edge); } } lastEdge = edgesByDistance.get(edgesByDistance.firstKey()); point = nearestPoints.get(lastEdge); } return point; } SimpleWaySnap(PointFactory factory, final Collection<Edge> edges); }
SimpleWaySnap { public NicGeoPoint snap(NicGeoPoint point) { if (edges != null) { edgesByDistance = new TreeMap<Float, Edge>(); nearestPoints = new HashMap<Edge, NicGeoPoint>(); for (final Edge edge : edges) { final float distance = distance(edge, point); if ((!edgesByDistance.containsKey(distance)) || (edge == lastEdge)) { edgesByDistance.put(distance, edge); } } lastEdge = edgesByDistance.get(edgesByDistance.firstKey()); point = nearestPoints.get(lastEdge); } return point; } SimpleWaySnap(PointFactory factory, final Collection<Edge> edges); NicGeoPoint snap(NicGeoPoint point); }
SimpleWaySnap { public NicGeoPoint snap(NicGeoPoint point) { if (edges != null) { edgesByDistance = new TreeMap<Float, Edge>(); nearestPoints = new HashMap<Edge, NicGeoPoint>(); for (final Edge edge : edges) { final float distance = distance(edge, point); if ((!edgesByDistance.containsKey(distance)) || (edge == lastEdge)) { edgesByDistance.put(distance, edge); } } lastEdge = edgesByDistance.get(edgesByDistance.firstKey()); point = nearestPoints.get(lastEdge); } return point; } SimpleWaySnap(PointFactory factory, final Collection<Edge> edges); NicGeoPoint snap(NicGeoPoint point);  }