Changeset 6049 in josm for trunk/src/org/openstreetmap/josm
- Timestamp:
- 2013-07-06T10:28:01+02:00 (11 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/JoinAreasAction.java
r5947 r6049 315 315 * Checks whether the selected objects are suitable to join and joins them if so 316 316 */ 317 @Override 317 318 public void actionPerformed(ActionEvent e) { 318 319 LinkedList<Way> ways = new LinkedList<Way>(Main.main.getCurrentDataSet().getSelectedWays()); … … 1295 1296 */ 1296 1297 private RelationRole addOwnMultigonRelation(Collection<Way> inner, Way outer) { 1297 if (inner. size() == 0) return null;1298 if (inner.isEmpty()) return null; 1298 1299 // Create new multipolygon relation and add all inner ways to it 1299 1300 Relation newRel = new Relation(); … … 1371 1372 } 1372 1373 1373 Relation newRel = null;1374 Relation newRel; 1374 1375 switch (multiouters.size()) { 1375 1376 case 0: -
trunk/src/org/openstreetmap/josm/tools/Geometry.java
r6007 r6049 51 51 //stupid java, cannot instantiate array of generic classes.. 52 52 @SuppressWarnings("unchecked") 53 ArrayList<Node>[] newNodes = new ArrayList[ways.size()]; 54 BBox[] wayBounds = new BBox[ways.size()]; 55 boolean[] changedWays = new boolean[ways.size()]; 53 int n = ways.size(); 54 ArrayList<Node>[] newNodes = new ArrayList[n]; 55 BBox[] wayBounds = new BBox[n]; 56 boolean[] changedWays = new boolean[n]; 56 57 57 58 Set<Node> intersectionNodes = new LinkedHashSet<Node>(); 58 59 59 60 //copy node arrays for local usage. 60 for (int pos = 0; pos < ways.size(); pos ++) {61 for (int pos = 0; pos < n; pos ++) { 61 62 newNodes[pos] = new ArrayList<Node>(ways.get(pos).getNodes()); 62 63 wayBounds[pos] = getNodesBounds(newNodes[pos]); … … 66 67 //iterate over all way pairs and introduce the intersections 67 68 Comparator<Node> coordsComparator = new NodePositionComparator(); 68 69 WayLoop: for (int seg1Way = 0; seg1Way < ways.size(); seg1Way ++) { 70 for (int seg2Way = seg1Way; seg2Way < ways.size(); seg2Way ++) { 69 WayLoop: for (int seg1Way = 0; seg1Way < n; seg1Way ++) { 70 for (int seg2Way = seg1Way; seg2Way < n; seg2Way ++) { 71 71 72 72 //do not waste time on bounds that do not intersect … … 128 128 boolean insertInSeg1 = false; 129 129 boolean insertInSeg2 = false; 130 131 130 //find if the intersection point is at end point of one of the segments, if so use that point 132 131 … … 264 263 265 264 //TODO: do this locally. 265 //TODO: remove this check after careful testing 266 266 if (!Line2D.linesIntersect(x1, y1, x2, y2, x3, y3, x4, y4)) return null; 267 267 268 // Convert line from (point, point) form to ax+by=c 269 double a1 = y2 - y1; 270 double b1 = x1 - x2; 271 double c1 = x2*y1 - x1*y2; 272 273 double a2 = y4 - y3; 274 double b2 = x3 - x4; 275 double c2 = x4*y3 - x3*y4; 268 // solve line-line intersection in parametric form: 269 // (x1,y1) + (x2-x1,y2-y1)* u = (x3,y3) + (x4-x3,y4-y3)* v 270 // (x2-x1,y2-y1)*u - (x4-x3,y4-y3)*v = (x3-x1,y3-y1) 271 // if 0<= u,v <=1, intersection exists at ( x1+ (x2-x1)*u, y1 + (y2-y1)*u ) 272 273 double a1 = x2 - x1; 274 double b1 = x3 - x4; 275 double c1 = x3 - x1; 276 277 double a2 = y2 - y1; 278 double b2 = y3 - y4; 279 double c2 = y3 - y1; 276 280 277 281 // Solve the equations 278 282 double det = a1*b2 - a2*b1; 279 if (det == 0) return null; // Lines are parallel 280 281 double x = (b1*c2 - b2*c1)/det; 282 double y = (a2*c1 -a1*c2)/det; 283 284 return new EastNorth(x, y); 283 284 double uu = b2*c1 - b1*c2 ; 285 double vv = a1*c2 - a2*c1; 286 double mag = Math.abs(uu)+Math.abs(vv); 287 288 if (Math.abs(det) > 1e-12 * mag) { 289 double u = uu/det, v = vv/det; 290 if (u>-1e-8 && u < 1+1e-8 && v>-1e-8 && v < 1+1e-8 ) { 291 if (u<0) u=0; 292 if (u>1) u=1.0; 293 return new EastNorth(x1+a1*u, y1+a2*u); 294 } else { 295 return null; 296 } 297 } else { 298 // parallel lines 299 return null; 300 } 285 301 } 286 302
Note:
See TracChangeset
for help on using the changeset viewer.