- Timestamp:
- 2012-12-30T17:12:15+01:00 (12 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/validation/tests/Addresses.java
r5644 r5647 174 174 return; // TODO handle multipolygon houses ? 175 175 } 176 if (centroid == null) return; // fix #8305 176 177 double maxDistance = Main.pref.getDouble("validator.addresses.max_street_distance", 200.0); 177 178 for (Way streetPart : street) { -
trunk/src/org/openstreetmap/josm/tools/Geometry.java
r5542 r5647 312 312 } 313 313 314 private static EastNorth closestPointTo(EastNorth p1, EastNorth p2, EastNorth point, boolean segmentOnly) { 315 CheckParameterUtil.ensureParameterNotNull(p1, "p1"); 316 CheckParameterUtil.ensureParameterNotNull(p2, "p2"); 317 CheckParameterUtil.ensureParameterNotNull(point, "point"); 318 319 double ldx = p2.getX() - p1.getX(); 320 double ldy = p2.getY() - p1.getY(); 321 322 if (ldx == 0 && ldy == 0) //segment zero length 323 return p1; 324 325 double pdx = point.getX() - p1.getX(); 326 double pdy = point.getY() - p1.getY(); 327 328 double offset = (pdx * ldx + pdy * ldy) / (ldx * ldx + ldy * ldy); 329 330 if (segmentOnly && offset <= 0) 331 return p1; 332 else if (segmentOnly && offset >= 1) 333 return p2; 334 else 335 return new EastNorth(p1.getX() + ldx * offset, p1.getY() + ldy * offset); 336 } 337 314 338 /** 315 339 * Calculates closest point to a line segment. 316 * @param segmentP1 317 * @param segmentP2 318 * @param point 340 * @param segmentP1 First point determining line segment 341 * @param segmentP2 Second point determining line segment 342 * @param point Point for which a closest point is searched on line segment [P1,P2] 319 343 * @return segmentP1 if it is the closest point, segmentP2 if it is the closest point, 320 344 * a new point if closest point is between segmentP1 and segmentP2. 345 * @since 3650 346 * @see #closestPointToLine 321 347 */ 322 348 public static EastNorth closestPointToSegment(EastNorth segmentP1, EastNorth segmentP2, EastNorth point) { 323 324 double ldx = segmentP2.getX() - segmentP1.getX(); 325 double ldy = segmentP2.getY() - segmentP1.getY(); 326 327 if (ldx == 0 && ldy == 0) //segment zero length 328 return segmentP1; 329 330 double pdx = point.getX() - segmentP1.getX(); 331 double pdy = point.getY() - segmentP1.getY(); 332 333 double offset = (pdx * ldx + pdy * ldy) / (ldx * ldx + ldy * ldy); 334 335 if (offset <= 0) 336 return segmentP1; 337 else if (offset >= 1) 338 return segmentP2; 339 else 340 return new EastNorth(segmentP1.getX() + ldx * offset, segmentP1.getY() + ldy * offset); 341 } 342 349 return closestPointTo(segmentP1, segmentP2, point, true); 350 } 351 352 /** 353 * Calculates closest point to a line. 354 * @param lineP1 First point determining line 355 * @param lineP2 Second point determining line 356 * @param point Point for which a closest point is searched on line (P1,P2) 357 * @return The closest point found on line. It may be outside the segment [P1,P2]. 358 * @since 4134 359 * @see #closestPointToSegment 360 */ 343 361 public static EastNorth closestPointToLine(EastNorth lineP1, EastNorth lineP2, EastNorth point) { 344 double ldx = lineP2.getX() - lineP1.getX(); 345 double ldy = lineP2.getY() - lineP1.getY(); 346 347 if (ldx == 0 && ldy == 0) //segment zero length 348 return lineP1; 349 350 double pdx = point.getX() - lineP1.getX(); 351 double pdy = point.getY() - lineP1.getY(); 352 353 double offset = (pdx * ldx + pdy * ldy) / (ldx * ldx + ldy * ldy); 354 return new EastNorth(lineP1.getX() + ldx * offset, lineP1.getY() + ldy * offset); 362 return closestPointTo(lineP1, lineP2, point, false); 355 363 } 356 364
Note:
See TracChangeset
for help on using the changeset viewer.