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.Node;
|
---|
10 | import org.openstreetmap.josm.data.osm.RelationMember;
|
---|
11 | import org.openstreetmap.josm.data.osm.Way;
|
---|
12 | import org.openstreetmap.josm.gui.dialogs.relation.sort.WayConnectionType.Direction;
|
---|
13 |
|
---|
14 | final class RelationSortUtils {
|
---|
15 |
|
---|
16 | private RelationSortUtils() {
|
---|
17 | // Hide default constructor for utils classes
|
---|
18 | }
|
---|
19 |
|
---|
20 | /**
|
---|
21 | * determine, if the way i is a roundabout and if yes, what type of roundabout
|
---|
22 | * @param member relation member
|
---|
23 | * @return roundabout type
|
---|
24 | */
|
---|
25 | static Direction roundaboutType(RelationMember member) {
|
---|
26 | if (member == null || !member.isWay()) return NONE;
|
---|
27 | return roundaboutType(member.getWay());
|
---|
28 | }
|
---|
29 |
|
---|
30 | static Direction roundaboutType(Way w) {
|
---|
31 | if (w != null && "roundabout".equals(w.get("junction"))) {
|
---|
32 | int nodesCount = w.getNodesCount();
|
---|
33 | if (nodesCount > 2 && nodesCount < 200) {
|
---|
34 | Node n1 = w.getNode(0);
|
---|
35 | Node n2 = w.getNode(1);
|
---|
36 | Node n3 = w.getNode(2);
|
---|
37 | if (n1 != null && n2 != null && n3 != null && w.isClosed()) {
|
---|
38 | /** do some simple determinant / cross pruduct test on the first 3 nodes
|
---|
39 | to see, if the roundabout goes clock wise or ccw */
|
---|
40 | EastNorth en1 = n1.getEastNorth();
|
---|
41 | EastNorth en2 = n2.getEastNorth();
|
---|
42 | EastNorth en3 = n3.getEastNorth();
|
---|
43 | if (en1 != null && en2 != null && en3 != null) {
|
---|
44 | en1 = en2.subtract(en1);
|
---|
45 | en2 = en3.subtract(en2);
|
---|
46 | return en1.north() * en2.east() - en2.north() * en1.east() > 0 ? ROUNDABOUT_LEFT : ROUNDABOUT_RIGHT;
|
---|
47 | }
|
---|
48 | }
|
---|
49 | }
|
---|
50 | }
|
---|
51 | return NONE;
|
---|
52 | }
|
---|
53 |
|
---|
54 | static boolean isBackward(final RelationMember member) {
|
---|
55 | return "backward".equals(member.getRole());
|
---|
56 | }
|
---|
57 |
|
---|
58 | static boolean isForward(final RelationMember member) {
|
---|
59 | return "forward".equals(member.getRole());
|
---|
60 | }
|
---|
61 |
|
---|
62 | static boolean isOneway(final RelationMember member) {
|
---|
63 | return isForward(member) || isBackward(member);
|
---|
64 | }
|
---|
65 | }
|
---|