@Test public void testCornerScenario(){ Set<Edge> cornerEdges = new HashSet<Edge>(); cornerEdges.add(new Edge(createXYPoint(1,1), createXYPoint(1,4))); cornerEdges.add(new Edge(createXYPoint(1,1), createXYPoint(4,1))); SimpleWaySnap simpleWaySnap = new SimpleWaySnap(new XYPointFactory(), cornerEdges); NicGeoPoint geoPointIn1 = createXYPoint(2,4); NicGeoPoint geoPointOut1 = simpleWaySnap.snap(geoPointIn1); NicGeoPoint expected1 = createXYPoint(1,4); assertEquals(expected1, geoPointOut1); NicGeoPoint geoPointIn2 = createXYPoint(4, 2); NicGeoPoint geoPointOut2 = simpleWaySnap.snap(geoPointIn2); NicGeoPoint expected2 = createXYPoint(4,1); assertEquals(expected2, geoPointOut2); NicGeoPoint geoPointIn3 = createXYPoint(2,2); NicGeoPoint geoPointOut3 = simpleWaySnap.snap(geoPointIn3); NicGeoPoint expected3 = createXYPoint(2,1); 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);  }