Changeset 13689 in josm for trunk/src/org


Ignore:
Timestamp:
2018-04-27T00:42:18+02:00 (6 years ago)
Author:
Don-vip
Message:

see #16189 - do not alter non-orthogonal building shapes

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/validation/tests/RightAngleBuildingTest.java

    r13688 r13689  
    55
    66import java.util.Collections;
     7import java.util.List;
    78
    89import org.openstreetmap.josm.actions.OrthogonalizeAction;
     
    4445        if (!w.isUsable() || !w.isClosed() || !isBuilding(w)) return;
    4546
    46         for (Pair<Double, Node> pair: w.getAngles()) {
    47             if (!checkAngle(w, pair.a, pair.b))
     47        List<Pair<Double, Node>> angles = w.getAngles();
     48        for (Pair<Double, Node> pair: angles) {
     49            if (checkAngle(w, pair.a, pair.b)) {
     50                TestError.Builder builder = TestError.builder(this, Severity.WARNING, 3701)
     51                                                     .message(tr("Building with an almost square angle"))
     52                                                     .primitives(w)
     53                                                     .highlight(pair.b);
     54                if (angles.stream().noneMatch(p -> Math.abs(p.a - 90) >= maxAngleDelta)) {
     55                    builder.fix(() -> {
     56                        try {
     57                            return OrthogonalizeAction.orthogonalize(Collections.singleton(w));
     58                        } catch (InvalidUserInputException e) {
     59                            Logging.warn(e);
     60                            return null;
     61                        }
     62                    });
     63                }
     64                errors.add(builder.build());
    4865                return;
     66            }
    4967        }
    5068    }
     
    5977    private boolean checkAngle(Way w, double angle, Node n) {
    6078        double difference = Math.abs(angle - 90);
    61 
    62         if (difference > minAngleDelta && difference < maxAngleDelta) {
    63             errors.add(TestError.builder(this, Severity.WARNING, 3701)
    64                     .message(tr("Building with an almost square angle"))
    65                     .primitives(w)
    66                     .highlight(n)
    67                     .fix(() -> {
    68                         try {
    69                             return OrthogonalizeAction.orthogonalize(Collections.singleton(w));
    70                         } catch (InvalidUserInputException e) {
    71                             Logging.warn(e);
    72                             return null;
    73                         }
    74                     })
    75                     .build());
    76             return false;
    77         }
    78 
    79         return true;
     79        return difference > minAngleDelta && difference < maxAngleDelta;
    8080    }
    8181}
Note: See TracChangeset for help on using the changeset viewer.