source: josm/trunk/src/org/openstreetmap/josm/gui/dialogs/relation/sort/RelationSortUtils.java@ 6360

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

Sonar/Findbugs - Hide Utility Class Constructor

File size: 2.4 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.gui.dialogs.relation.sort;
3
4import static org.openstreetmap.josm.gui.dialogs.relation.sort.WayConnectionType.Direction.NONE;
5import static org.openstreetmap.josm.gui.dialogs.relation.sort.WayConnectionType.Direction.ROUNDABOUT_LEFT;
6import static org.openstreetmap.josm.gui.dialogs.relation.sort.WayConnectionType.Direction.ROUNDABOUT_RIGHT;
7
8import org.openstreetmap.josm.data.coor.EastNorth;
9import org.openstreetmap.josm.data.osm.RelationMember;
10import org.openstreetmap.josm.data.osm.Way;
11import org.openstreetmap.josm.gui.dialogs.relation.sort.WayConnectionType.Direction;
12
13class RelationSortUtils {
14
15 private RelationSortUtils() {
16 // Hide default constructor for utils classes
17 }
18
19 /**
20 * determine, if the way i is a roundabout and if yes, what type of roundabout
21 */
22 static Direction roundaboutType(RelationMember member) {
23 if (member == null || !member.isWay()) return NONE;
24 Way w = member.getWay();
25 return roundaboutType(w);
26 }
27
28 static Direction roundaboutType(Way w) {
29 if (w != null &&
30 "roundabout".equals(w.get("junction")) &&
31 w.getNodesCount() < 200 &&
32 w.getNodesCount() > 2 &&
33 w.getNode(0) != null &&
34 w.getNode(1) != null &&
35 w.getNode(2) != null &&
36 w.firstNode() == w.lastNode()) {
37 /** do some simple determinant / cross pruduct test on the first 3 nodes
38 to see, if the roundabout goes clock wise or ccw */
39 EastNorth en1 = w.getNode(0).getEastNorth();
40 EastNorth en2 = w.getNode(1).getEastNorth();
41 EastNorth en3 = w.getNode(2).getEastNorth();
42 if (en1 != null && en2 != null && en3 != null) {
43 en1 = en1.sub(en2);
44 en2 = en2.sub(en3);
45 return en1.north() * en2.east() - en2.north() * en1.east() > 0 ? ROUNDABOUT_LEFT : ROUNDABOUT_RIGHT;
46 }
47 }
48 return NONE;
49 }
50
51 static boolean isBackward(final RelationMember member){
52 return member.getRole().equals("backward");
53 }
54
55 static boolean isForward(final RelationMember member){
56 return member.getRole().equals("forward");
57 }
58
59 static boolean isOneway(final RelationMember member){
60 return isForward(member) || isBackward(member);
61 }
62
63}
Note: See TracBrowser for help on using the repository browser.