Changeset 30737 in osm for applications/editors/josm/plugins/FastDraw/src
- Timestamp:
- 2014-10-18T23:07:52+02:00 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/FastDraw/src/org/openstreetmap/josm/plugins/fastdraw/DrawnPolyLine.java
r30710 r30737 8 8 import java.util.ListIterator; 9 9 import java.util.Set; 10 10 11 import org.openstreetmap.josm.data.coor.LatLon; 11 12 import org.openstreetmap.josm.gui.MapView; … … 13 14 public class DrawnPolyLine { 14 15 MapView mv; 15 private LinkedList<LatLon> points = new LinkedList< LatLon>();16 private LinkedList<LatLon> simplePoints = new LinkedList< LatLon>();16 private LinkedList<LatLon> points = new LinkedList<>(); 17 private LinkedList<LatLon> simplePoints = new LinkedList<>(); 17 18 private Set<LatLon> used; 18 private Set<LatLon> fixed = new HashSet< LatLon>();19 19 private Set<LatLon> fixed = new HashSet<>(); 20 20 21 private int lastIdx; 21 22 private boolean closedFlag; … … 31 32 return fixed.contains(pp2); 32 33 } 33 34 34 35 double getLength() { 35 36 List<LatLon> pts = getPoints(); … … 55 56 return (simplePoints!=null && simplePoints.size()>0); 56 57 } 57 58 58 59 int findClosestPoint(Point p, double d) { 59 60 double x=p.x, y=p.y; … … 87 88 } 88 89 } 89 90 90 91 void fixPoint(LatLon p) { 91 92 fixed.add(p); … … 100 101 return fixed; 101 102 } 102 103 103 104 void addLast(LatLon coor) { 104 105 if (closedFlag && lastIdx>points.size()-1) return; 105 106 if (lastIdx>=points.size()-1) { 106 // 107 // 107 108 if (points.isEmpty() || !coor.equals(points.getLast())) { 108 points.addLast(coor); 109 points.addLast(coor); 109 110 if (points.size()>1) lastIdx++; 110 111 } … … 112 113 // insert point into midlle of the line 113 114 if (points.isEmpty() || !coor.equals(points.get(lastIdx))) { 114 points.add(lastIdx+1, coor); 115 lastIdx++; 116 } 117 } 118 } 119 115 points.add(lastIdx+1, coor); 116 lastIdx++; 117 } 118 } 119 } 120 120 121 Point getLastPoint() { 121 122 if (lastIdx<points.size()) return getPoint(points.get(lastIdx)); … … 126 127 return mv.getPoint(p); 127 128 } 128 129 129 130 int getSimplePointsCount() { 130 131 if (simplePoints!=null)return simplePoints.size(); else return -1; 131 132 } 132 133 133 134 /** 134 135 * Increase epsilon to fit points count in maxPKM point per 1 km … … 146 147 return e; 147 148 } 148 149 149 150 /** 150 151 * Simplified drawn line, not touching the nodes includes in "fixed" set. … … 154 155 int n = points.size(); 155 156 if (n < 3) return; 156 used = new HashSet< LatLon>(n);157 used = new HashSet<>(n); 157 158 int start = 0; 158 159 for (int i = 0; i < n; i++) { … … 166 167 } 167 168 } 168 simplePoints = new LinkedList< LatLon>();169 simplePoints = new LinkedList<>(); 169 170 simplePoints.addAll(points); 170 171 simplePoints.retainAll(used); … … 192 193 193 194 if (end - start < 2) return; 194 195 195 196 int farthest_node = -1; 196 197 double farthest_dist = 0; … … 233 234 return closedFlag; 234 235 } 235 236 236 237 void deleteNode(int idx) { 237 238 if (idx<=lastIdx) lastIdx--; 238 239 fixed.remove(points.get(idx)); 239 points.remove(idx); 240 points.remove(idx); 240 241 } 241 242 void tryToDeleteSegment(Point p) { 242 243 if (points.size()<3) return; 243 244 244 245 LatLon start; 245 246 start = findBigSegment(p); … … 261 262 return; 262 263 } 263 264 264 265 // if we are deleting this segment 265 if (f) it.remove(); 266 if (f) it.remove(); 266 267 if (pp == start) {f=true;idx=i;} // next node should be removed 267 268 i++; … … 273 274 * line fragment = segments between two fixed (green) nodes 274 275 * @param p 275 * @return 276 * @return 276 277 */ 277 278 LatLon findBigSegment(Point p) { … … 291 292 if (pointSegmentDistance(p,p1,p2) < 5) { 292 293 return start; 293 } 294 } 294 295 } while (it2.hasNext()); 295 296 return null; 296 297 297 298 } 298 299 299 300 private double pointSegmentDistance(Point p, Point p1, Point p2) { 300 301 double a,b,x,y,l,kt,kn,dist; 301 x=p.x-p1.x; y=p.y-p1.y; 302 x=p.x-p1.x; y=p.y-p1.y; 302 303 a=p2.x-p1.x; b=p2.y-p1.y; 303 304 l=Math.hypot(a,b); … … 344 345 } 345 346 } 346 347 347 348 /** 348 349 * Returns maximum number of simplified line points divided by line segment length … … 357 358 if (k<2) k=2; 358 359 if (k>n) k=n; 359 360 360 361 LatLon pp1, pp2=null; 361 362 Iterator<LatLon> it1,it2; … … 385 386 } 386 387 return Math.round(maxpkm); 387 388 388 389 } 389 390
Note:
See TracChangeset
for help on using the changeset viewer.