source: josm/trunk/src/org/openstreetmap/josm/data/validation/tests/RightAngleBuildingTest.java@ 13688

Last change on this file since 13688 was 13688, checked in by Don-vip, 6 years ago

see #16189 - increase right angle min threshold to 0.1

  • Property svn:eol-style set to native
File size: 2.8 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.data.validation.tests;
3
4import static org.openstreetmap.josm.tools.I18n.tr;
5
6import java.util.Collections;
7
8import org.openstreetmap.josm.actions.OrthogonalizeAction;
9import org.openstreetmap.josm.actions.OrthogonalizeAction.InvalidUserInputException;
10import org.openstreetmap.josm.data.osm.Node;
11import org.openstreetmap.josm.data.osm.Way;
12import org.openstreetmap.josm.data.validation.Severity;
13import org.openstreetmap.josm.data.validation.Test;
14import org.openstreetmap.josm.data.validation.TestError;
15import org.openstreetmap.josm.gui.progress.ProgressMonitor;
16import org.openstreetmap.josm.spi.preferences.Config;
17import org.openstreetmap.josm.tools.Logging;
18import org.openstreetmap.josm.tools.Pair;
19
20/**
21 * Checks for buildings with angles close to right angle.
22 *
23 * @author marxin
24 * @since 13670
25 */
26public class RightAngleBuildingTest extends Test {
27
28 /** Maximum angle difference from right angle that is considered as invalid. */
29 protected double maxAngleDelta;
30
31 /** Minimum angle difference from right angle that is considered as invalid. */
32 protected double minAngleDelta;
33
34 /**
35 * Constructs a new {@code RightAngleBuildingTest} test.
36 */
37 public RightAngleBuildingTest() {
38 super(tr("Almost right angle buildings"),
39 tr("Checks for buildings that have angles close to right angle and are not orthogonalized."));
40 }
41
42 @Override
43 public void visit(Way w) {
44 if (!w.isUsable() || !w.isClosed() || !isBuilding(w)) return;
45
46 for (Pair<Double, Node> pair: w.getAngles()) {
47 if (!checkAngle(w, pair.a, pair.b))
48 return;
49 }
50 }
51
52 @Override
53 public void startTest(ProgressMonitor monitor) {
54 super.startTest(monitor);
55 maxAngleDelta = Config.getPref().getDouble("validator.RightAngleBuilding.maximumDelta", 10.0);
56 minAngleDelta = Config.getPref().getDouble("validator.RightAngleBuilding.minimumDelta", 0.1);
57 }
58
59 private boolean checkAngle(Way w, double angle, Node n) {
60 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;
80 }
81}
Note: See TracBrowser for help on using the repository browser.