Changeset 11725 in josm
- Timestamp:
- 2017-03-13T18:48:20+01:00 (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/util/RotationAngle.java
r10599 r11725 20 20 21 21 /** 22 * The rotation along a way. 23 */ 24 static final class WayDirectionRotationAngle implements RotationAngle { 25 @Override 26 public double getRotationAngle(OsmPrimitive p) { 27 if (!(p instanceof Node)) { 28 return 0; 29 } 30 final Node n = (Node) p; 31 final SubclassFilteredCollection<OsmPrimitive, Way> ways = Utils.filteredCollection(n.getReferrers(), Way.class); 32 if (ways.isEmpty()) { 33 return 0; 34 } 35 final Way w = ways.iterator().next(); 36 final int idx = w.getNodes().indexOf(n); 37 if (idx == 0) { 38 return -Geometry.getSegmentAngle(n.getEastNorth(), w.getNode(idx + 1).getEastNorth()); 39 } else { 40 return -Geometry.getSegmentAngle(w.getNode(idx - 1).getEastNorth(), n.getEastNorth()); 41 } 42 } 43 44 @Override 45 public String toString() { 46 return "way-direction"; 47 } 48 49 @Override 50 public int hashCode() { 51 return 1; 52 } 53 54 @Override 55 public boolean equals(Object obj) { 56 if (this == obj) { 57 return true; 58 } 59 if (obj == null) { 60 return false; 61 } 62 if (getClass() != obj.getClass()) { 63 return false; 64 } 65 return true; 66 } 67 68 } 69 70 /** 71 * A static rotation 72 */ 73 static final class StaticRotationAngle implements RotationAngle { 74 private final double angle; 75 76 private StaticRotationAngle(double angle) { 77 this.angle = angle; 78 } 79 80 @Override 81 public double getRotationAngle(OsmPrimitive p) { 82 return angle; 83 } 84 85 @Override 86 public String toString() { 87 return angle + "rad"; 88 } 89 90 @Override 91 public int hashCode() { 92 final int prime = 31; 93 int result = 1; 94 long temp; 95 temp = Double.doubleToLongBits(angle); 96 result = prime * result + (int) (temp ^ (temp >>> 32)); 97 return result; 98 } 99 100 @Override 101 public boolean equals(Object obj) { 102 if (this == obj) { 103 return true; 104 } 105 if (obj == null) { 106 return false; 107 } 108 if (getClass() != obj.getClass()) { 109 return false; 110 } 111 StaticRotationAngle other = (StaticRotationAngle) obj; 112 if (Double.doubleToLongBits(angle) != Double.doubleToLongBits(other.angle)) { 113 return false; 114 } 115 return true; 116 } 117 } 118 119 /** 22 120 * Calculates the rotation angle depending on the primitive to be displayed. 23 121 * @param p primitive … … 32 130 */ 33 131 static RotationAngle buildStaticRotation(final double angle) { 34 return new RotationAngle() { 35 @Override 36 public double getRotationAngle(OsmPrimitive p) { 37 return angle; 38 } 39 40 @Override 41 public String toString() { 42 return angle + "rad"; 43 } 44 }; 132 return new StaticRotationAngle(angle); 45 133 } 46 134 … … 102 190 */ 103 191 static RotationAngle buildWayDirectionRotation() { 104 return new RotationAngle() { 105 @Override 106 public double getRotationAngle(OsmPrimitive p) { 107 if (!(p instanceof Node)) { 108 return 0; 109 } 110 final Node n = (Node) p; 111 final SubclassFilteredCollection<OsmPrimitive, Way> ways = Utils.filteredCollection(n.getReferrers(), Way.class); 112 if (ways.isEmpty()) { 113 return 0; 114 } 115 final Way w = ways.iterator().next(); 116 final int idx = w.getNodes().indexOf(n); 117 if (idx == 0) { 118 return -Geometry.getSegmentAngle(n.getEastNorth(), w.getNode(idx + 1).getEastNorth()); 119 } else { 120 return -Geometry.getSegmentAngle(w.getNode(idx - 1).getEastNorth(), n.getEastNorth()); 121 } 122 } 123 124 @Override 125 public String toString() { 126 return "way-direction"; 127 } 128 }; 192 return new WayDirectionRotationAngle(); 129 193 } 130 194 }
Note:
See TracChangeset
for help on using the changeset viewer.