1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.gui.dialogs.relation.sort;
|
---|
3 |
|
---|
4 | import static org.openstreetmap.josm.gui.dialogs.relation.sort.WayConnectionType.Direction.NONE;
|
---|
5 | import static org.openstreetmap.josm.gui.dialogs.relation.sort.WayConnectionType.Direction.ROUNDABOUT_LEFT;
|
---|
6 | import static org.openstreetmap.josm.gui.dialogs.relation.sort.WayConnectionType.Direction.ROUNDABOUT_RIGHT;
|
---|
7 |
|
---|
8 | import org.openstreetmap.josm.data.coor.EastNorth;
|
---|
9 | import org.openstreetmap.josm.data.osm.RelationMember;
|
---|
10 | import org.openstreetmap.josm.data.osm.Way;
|
---|
11 | import org.openstreetmap.josm.gui.dialogs.relation.sort.WayConnectionType.Direction;
|
---|
12 |
|
---|
13 | final class 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 "backward".equals(member.getRole());
|
---|
53 | }
|
---|
54 |
|
---|
55 | static boolean isForward(final RelationMember member){
|
---|
56 | return "forward".equals(member.getRole());
|
---|
57 | }
|
---|
58 |
|
---|
59 | static boolean isOneway(final RelationMember member){
|
---|
60 | return isForward(member) || isBackward(member);
|
---|
61 | }
|
---|
62 | }
|
---|