Changeset 15938 in josm for trunk/src/org/openstreetmap/josm
- Timestamp:
- 2020-02-26T17:16:35+01:00 (5 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/validation/TestError.java
r15640 r15938 2 2 package org.openstreetmap.josm.data.validation; 3 3 4 import java.awt.geom.Area; 5 import java.awt.geom.PathIterator; 4 6 import java.text.MessageFormat; 7 import java.util.ArrayList; 5 8 import java.util.Arrays; 6 9 import java.util.Collection; … … 12 15 13 16 import org.openstreetmap.josm.command.Command; 17 import org.openstreetmap.josm.data.coor.EastNorth; 14 18 import org.openstreetmap.josm.data.osm.Node; 15 19 import org.openstreetmap.josm.data.osm.OsmPrimitive; … … 189 193 190 194 /** 195 * Sets an area to highlight when selecting this error. 196 * 197 * @param highlighted the area to highlight 198 * @return {@code this} 199 */ 200 public Builder highlight(Area highlighted) { 201 CheckParameterUtil.ensureParameterNotNull(highlighted, "highlighted"); 202 this.highlighted = Collections.singleton(highlighted); 203 return this; 204 } 205 206 /** 191 207 * Sets a supplier to obtain a command to fix the error. 192 208 * … … 422 438 } else if (o instanceof List<?>) { 423 439 v.visit((List<Node>) o); 440 } else if (o instanceof Area) { 441 for (List<Node> l : getHiliteNodesForArea((Area) o)) { 442 v.visit(l); 443 } 424 444 } 425 445 } 426 446 } 447 448 /** 449 * Calculate list of node pairs describing the area. 450 * @param area the area 451 * @return list of node pairs describing the area 452 */ 453 private static List<List<Node>> getHiliteNodesForArea(Area area) { 454 List<List<Node>> hilite = new ArrayList<>(); 455 PathIterator pit = area.getPathIterator(null); 456 double[] res = new double[6]; 457 List<Node> nodes = new ArrayList<>(); 458 while (!pit.isDone()) { 459 int type = pit.currentSegment(res); 460 Node n = new Node(new EastNorth(res[0], res[1])); 461 switch (type) { 462 case PathIterator.SEG_MOVETO: 463 if (!nodes.isEmpty()) { 464 hilite.add(nodes); 465 } 466 nodes = new ArrayList<>(); 467 nodes.add(n); 468 break; 469 case PathIterator.SEG_LINETO: 470 nodes.add(n); 471 break; 472 case PathIterator.SEG_CLOSE: 473 if (!nodes.isEmpty()) { 474 nodes.add(nodes.get(0)); 475 hilite.add(nodes); 476 nodes = new ArrayList<>(); 477 } 478 break; 479 default: 480 break; 481 } 482 pit.next(); 483 } 484 if (nodes.size() > 1) { 485 hilite.add(nodes); 486 } 487 return hilite; 488 } 489 427 490 428 491 /** -
trunk/src/org/openstreetmap/josm/data/validation/tests/MapCSSTagChecker.java
r15902 r15938 4 4 import static org.openstreetmap.josm.tools.I18n.tr; 5 5 6 import java.awt.geom.Area; 6 7 import java.io.BufferedReader; 7 8 import java.io.IOException; … … 619 620 errorBuilder = errorBuilder.fix(() -> fix); 620 621 } 622 if (env.intersections != null) { 623 Area is = env.intersections.get(c); 624 if (is != null) { 625 errorBuilder = errorBuilder.highlight(is); 626 } 627 } 621 628 res.add(errorBuilder.primitives(p, (OsmPrimitive) c).build()); 622 629 } … … 743 750 && e.getPrimitives().size() == toAdd.getPrimitives().size() 744 751 && e.getPrimitives().containsAll(toAdd.getPrimitives()) 745 && e.getHighlighted().size() == toAdd.getHighlighted().size() 746 && e.getHighlighted().containsAll(toAdd.getHighlighted())) { 752 && highlightedIsEqual(e.getHighlighted(), toAdd.getHighlighted())) { 747 753 isDup = true; 748 754 break; … … 752 758 if (!isDup) 753 759 errors.add(toAdd); 760 } 761 762 private static boolean highlightedIsEqual(Collection<?> highlighted, Collection<?> highlighted2) { 763 if (highlighted.size() == highlighted2.size()) { 764 if (!highlighted.isEmpty()) { 765 Object h1 = highlighted.iterator().next(); 766 Object h2 = highlighted2.iterator().next(); 767 if (h1 instanceof Area && h2 instanceof Area) { 768 return ((Area) h1).equals((Area) h2); 769 } 770 return highlighted.containsAll(highlighted2); 771 } 772 return true; 773 } 774 return false; 754 775 } 755 776 -
trunk/src/org/openstreetmap/josm/gui/mappaint/Environment.java
r15064 r15938 2 2 package org.openstreetmap.josm.gui.mappaint; 3 3 4 import java.awt.geom.Area; 5 import java.util.HashMap; 4 6 import java.util.LinkedHashSet; 7 import java.util.Map; 5 8 import java.util.Set; 6 9 … … 67 70 */ 68 71 public Set<IPrimitive> children; 72 73 /** 74 * Intersection areas (only filled with CrossingFinder if children is not null) 75 */ 76 public Map<IPrimitive, Area> intersections; 69 77 70 78 /** … … 118 126 this.context = other.getContext(); 119 127 this.children = other.children == null ? null : new LinkedHashSet<>(other.children); 128 this.intersections = other.intersections == null ? null : new HashMap<>(other.intersections); 120 129 } 121 130 … … 284 293 count = null; 285 294 children = null; 295 intersections = null; 286 296 } 287 297 -
trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/Selector.java
r15925 r15938 4 4 import static org.openstreetmap.josm.data.projection.Ellipsoid.WGS84; 5 5 6 import java.awt.geom.Area; 6 7 import java.text.MessageFormat; 7 8 import java.util.ArrayList; 8 9 import java.util.Collection; 9 10 import java.util.Collections; 11 import java.util.HashMap; 10 12 import java.util.LinkedHashSet; 11 13 import java.util.List; … … 31 33 import org.openstreetmap.josm.tools.CheckParameterUtil; 32 34 import org.openstreetmap.josm.tools.Geometry; 35 import org.openstreetmap.josm.tools.Geometry.PolygonIntersection; 33 36 import org.openstreetmap.josm.tools.Logging; 37 import org.openstreetmap.josm.tools.Pair; 34 38 import org.openstreetmap.josm.tools.Utils; 35 39 … … 298 302 299 303 private final String layer; 304 private Area area; 300 305 301 306 private CrossingFinder(Environment e) { … … 309 314 if (Objects.equals(layer, OsmUtils.getLayer(w)) 310 315 && left.matches(new Environment(w).withParent(e.osm)) 311 && e.osm instanceof IWay && Geometry.PolygonIntersection.CROSSING.equals( 312 Geometry.polygonIntersection(w.getNodes(), ((IWay<?>) e.osm).getNodes()))) { 313 addToChildren(e, w); 316 && e.osm instanceof IWay) { 317 if (area == null) { 318 area = Geometry.getAreaEastNorth(e.osm); 319 } 320 Pair<PolygonIntersection, Area> is = Geometry.polygonIntersectionResult( 321 Geometry.getAreaEastNorth(w), area, Geometry.INTERSECTION_EPS_EAST_NORTH); 322 if (Geometry.PolygonIntersection.CROSSING == is.a) { 323 addToChildren(e, w); 324 // store intersection area to improve highlight and zoom to problem 325 if (e.intersections == null) { 326 e.intersections = new HashMap<>(); 327 } 328 e.intersections.put(w, is.b); 329 } 314 330 } 315 331 } -
trunk/src/org/openstreetmap/josm/tools/Geometry.java
r15730 r15938 30 30 import org.openstreetmap.josm.data.osm.INode; 31 31 import org.openstreetmap.josm.data.osm.IPrimitive; 32 import org.openstreetmap.josm.data.osm.IRelation; 32 33 import org.openstreetmap.josm.data.osm.IWay; 33 34 import org.openstreetmap.josm.data.osm.MultipolygonBuilder; … … 553 554 554 555 /** 556 * Calculate area in east/north space for given primitive. Uses {@link MultipolygonCache} for multipolygon relations. 557 * @param p the primitive 558 * @return the area in east/north space, might be empty if the primitive is incomplete or not closed or a node 559 * since 15938 560 */ 561 public static Area getAreaEastNorth(IPrimitive p) { 562 if (p instanceof Way && ((Way) p).isClosed()) { 563 return Geometry.getArea(((Way) p).getNodes()); 564 } 565 if (p.isMultipolygon() && !p.isIncomplete() && !((IRelation<?>) p).hasIncompleteMembers()) { 566 Multipolygon mp = MultipolygonCache.getInstance().get((Relation) p); 567 Path2D path = new Path2D.Double(); 568 path.setWindingRule(Path2D.WIND_EVEN_ODD); 569 for (PolyData pd : mp.getCombinedPolygons()) { 570 path.append(pd.get(), false); 571 } 572 return new Area(path); 573 } 574 return new Area(); 575 } 576 577 /** 555 578 * Returns the Area of a polygon, from the multipolygon relation. 556 579 * @param multipolygon the multipolygon relation … … 601 624 */ 602 625 public static PolygonIntersection polygonIntersection(Area a1, Area a2, double eps) { 603 626 return polygonIntersectionResult(a1, a2, eps).a; 627 } 628 629 /** 630 * Calculate intersection area and kind of intersection between two polygons. 631 * @param a1 Area of first polygon 632 * @param a2 Area of second polygon 633 * @param eps an area threshold, everything below is considered an empty intersection 634 * @return pair with intersection kind and intersection area (never null, but maybe empty) 635 * @since 15938 636 */ 637 public static Pair<PolygonIntersection, Area> polygonIntersectionResult(Area a1, Area a2, double eps) { 604 638 Area inter = new Area(a1); 605 639 inter.intersect(a2); 606 640 607 641 if (inter.isEmpty() || !checkIntersection(inter, eps)) { 608 return PolygonIntersection.OUTSIDE;642 return new Pair<>(PolygonIntersection.OUTSIDE, inter); 609 643 } else if (a2.getBounds2D().contains(a1.getBounds2D()) && inter.equals(a1)) { 610 return PolygonIntersection.FIRST_INSIDE_SECOND;644 return new Pair<>(PolygonIntersection.FIRST_INSIDE_SECOND, inter); 611 645 } else if (a1.getBounds2D().contains(a2.getBounds2D()) && inter.equals(a2)) { 612 return PolygonIntersection.SECOND_INSIDE_FIRST;646 return new Pair<>(PolygonIntersection.SECOND_INSIDE_FIRST, inter); 613 647 } else { 614 return PolygonIntersection.CROSSING;648 return new Pair<>(PolygonIntersection.CROSSING, inter); 615 649 } 616 650 }
Note:
See TracChangeset
for help on using the changeset viewer.