Changeset 30791 in osm for applications/editors


Ignore:
Timestamp:
2014-11-04T19:12:00+01:00 (10 years ago)
Author:
mzdila
Message:

fixing https://josm.openstreetmap.de/ticket/8217

File:
1 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/simplifyarea/src/sk/zdila/josm/plugin/simplify/SimplifyAreaAction.java

    r30689 r30791  
    3232import org.openstreetmap.josm.data.osm.Node;
    3333import org.openstreetmap.josm.data.osm.OsmPrimitive;
     34import org.openstreetmap.josm.data.osm.OsmPrimitiveType;
    3435import org.openstreetmap.josm.data.osm.Way;
    3536import org.openstreetmap.josm.gui.HelpAwareOptionPane;
     
    3839import org.openstreetmap.josm.tools.Shortcut;
    3940
    40 public class SimplifyAreaAction extends JosmAction {
     41public final class SimplifyAreaAction extends JosmAction {
    4142
    4243    public SimplifyAreaAction() {
     
    5051    }
    5152
    52     private boolean isInBounds(final Node node, final List<Bounds> bounds) {
     53    private static boolean isInBounds(final Node node, final List<Bounds> bounds) {
    5354        for (final Bounds b : bounds) {
    5455            if (b.contains(node.getCoor())) {
     
    5960    }
    6061
    61     private boolean confirmWayWithNodesOutsideBoundingBox() {
     62    private static boolean confirmWayWithNodesOutsideBoundingBox() {
    6263        final ButtonSpec[] options = new ButtonSpec[] { new ButtonSpec(tr("Yes, delete nodes"), ImageProvider.get("ok"), tr("Delete nodes outside of downloaded data regions"), null),
    6364                new ButtonSpec(tr("No, abort"), ImageProvider.get("cancel"), tr("Cancel operation"), null) };
     
    175176    }
    176177
     178    private static boolean nodeGluesWays(final Node node) {
     179        Set<Node> referenceNeighbours = null;
     180        for (final OsmPrimitive ref : node.getReferrers()) {
     181            if (ref.getType() == OsmPrimitiveType.WAY) {
     182                final Way way = ((Way) ref);
     183                final Set<Node> neighbours = way.getNeighbours(node);
     184                if (referenceNeighbours == null) {
     185                    referenceNeighbours = neighbours;
     186                } else if (!referenceNeighbours.containsAll(neighbours)) {
     187                    return true;
     188                }
     189            }
     190        }
     191       
     192        return false;
     193    }
     194
    177195    // average nearby nodes
    178     private Collection<Command> averageNearbyNodes(final Collection<Way> ways, final Collection<Node> nodesAlreadyDeleted) {
     196    private static Collection<Command> averageNearbyNodes(final Collection<Way> ways, final Collection<Node> nodesAlreadyDeleted) {
    179197        final double mergeThreshold = Main.pref.getDouble(SimplifyAreaPreferenceSetting.MERGE_THRESHOLD, 0.2);
    180198
     
    200218
    201219            while (true) {
    202                 double minDist = Double.MAX_VALUE;
     220                double minDist = Double.POSITIVE_INFINITY;
    203221                Node node1 = null;
    204222                Node node2 = null;
     
    299317    }
    300318
    301     private void addNodesToDelete(final Collection<Node> nodesToDelete, final Way w) {
     319    private static void addNodesToDelete(final Collection<Node> nodesToDelete, final Way w) {
    302320        final double angleThreshold = Main.pref.getDouble(SimplifyAreaPreferenceSetting.ANGLE_THRESHOLD, 10);
    303321        final double angleFactor = Main.pref.getDouble(SimplifyAreaPreferenceSetting.ANGLE_FACTOR, 1.0);
     
    333351            int prevIndex = -1;
    334352
    335             double minWeight = Double.MAX_VALUE;
     353            double minWeight = Double.POSITIVE_INFINITY;
    336354            Node bestMatch = null;
    337355
     
    357375
    358376                        weight = !closed && i == len - 1 || // don't remove last node of the not closed way
    359                                 angleWeight > 1.0 || areaWeight > 1.0 || distanceWeight > 1.0 ? Double.MAX_VALUE :
     377                                nodeGluesWays(prevNode) ||
     378                                angleWeight > 1.0 || areaWeight > 1.0 || distanceWeight > 1.0 ? Double.POSITIVE_INFINITY :
    360379                                angleWeight * angleFactor + areaWeight * areaFactor + distanceWeight * distanceFactor;
    361380
Note: See TracChangeset for help on using the changeset viewer.