Changeset 11601 in josm
- Timestamp:
- 2017-02-23T01:03:15+01:00 (8 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/mapmode/DrawAction.java
r11495 r11601 1005 1005 1006 1006 /** 1007 * Adjusts the position of a node to lie on a segment (or a segment 1008 * intersection). 1007 * Adjusts the position of a node to lie on a segment (or a segment intersection). 1009 1008 * 1010 1009 * If one or more than two segments are passed, the node is adjusted 1011 1010 * to lie on the first segment that is passed. 1012 1011 * 1013 * If two segments are passed, the node is adjusted to be at their 1014 * intersection. 1012 * If two segments are passed, the node is adjusted to be at their intersection. 1015 1013 * 1016 1014 * No action is taken if no segments are passed. … … 1020 1018 */ 1021 1019 private static void adjustNode(Collection<Pair<Node, Node>> segs, Node n) { 1022 1023 1020 switch (segs.size()) { 1024 1021 case 0: 1025 1022 return; 1026 1023 case 2: 1027 // This computes the intersection between the two segments and adjusts the node position. 1028 Iterator<Pair<Node, Node>> i = segs.iterator(); 1029 Pair<Node, Node> seg = i.next(); 1030 EastNorth pA = seg.a.getEastNorth(); 1031 EastNorth pB = seg.b.getEastNorth(); 1032 seg = i.next(); 1033 EastNorth pC = seg.a.getEastNorth(); 1034 EastNorth pD = seg.b.getEastNorth(); 1035 1036 double u = det(pB.east() - pA.east(), pB.north() - pA.north(), pC.east() - pD.east(), pC.north() - pD.north()); 1037 1038 // Check for parallel segments and do nothing if they are 1039 // In practice this will probably only happen when a way has been duplicated 1040 1041 if (u == 0) 1042 return; 1043 1044 // q is a number between 0 and 1 1045 // It is the point in the segment where the intersection occurs 1046 // if the segment is scaled to lenght 1 1047 1048 double q = det(pB.north() - pC.north(), pB.east() - pC.east(), pD.north() - pC.north(), pD.east() - pC.east()) / u; 1049 EastNorth intersection = new EastNorth( 1050 pB.east() + q * (pA.east() - pB.east()), 1051 pB.north() + q * (pA.north() - pB.north())); 1052 1053 1054 // only adjust to intersection if within snapToIntersectionThreshold pixel of mouse click; otherwise 1055 // fall through to default action. 1056 // (for semi-parallel lines, intersection might be miles away!) 1057 if (Main.map.mapView.getPoint2D(n).distance(Main.map.mapView.getPoint2D(intersection)) < SNAP_TO_INTERSECTION_THRESHOLD.get()) { 1058 n.setEastNorth(intersection); 1059 return; 1060 } 1024 adjustNodeTwoSegments(segs, n); 1025 break; 1061 1026 default: 1062 EastNorth p = n.getEastNorth(); 1063 seg = segs.iterator().next(); 1064 pA = seg.a.getEastNorth(); 1065 pB = seg.b.getEastNorth(); 1066 double a = p.distanceSq(pB); 1067 double b = p.distanceSq(pA); 1068 double c = pA.distanceSq(pB); 1069 q = (a - b + c) / (2*c); 1070 n.setEastNorth(new EastNorth(pB.east() + q * (pA.east() - pB.east()), pB.north() + q * (pA.north() - pB.north()))); 1071 } 1027 adjustNodeDefault(segs, n); 1028 } 1029 } 1030 1031 private static void adjustNodeTwoSegments(Collection<Pair<Node, Node>> segs, Node n) { 1032 // This computes the intersection between the two segments and adjusts the node position. 1033 Iterator<Pair<Node, Node>> i = segs.iterator(); 1034 Pair<Node, Node> seg = i.next(); 1035 EastNorth pA = seg.a.getEastNorth(); 1036 EastNorth pB = seg.b.getEastNorth(); 1037 seg = i.next(); 1038 EastNorth pC = seg.a.getEastNorth(); 1039 EastNorth pD = seg.b.getEastNorth(); 1040 1041 double u = det(pB.east() - pA.east(), pB.north() - pA.north(), pC.east() - pD.east(), pC.north() - pD.north()); 1042 1043 // Check for parallel segments and do nothing if they are 1044 // In practice this will probably only happen when a way has been duplicated 1045 1046 if (u == 0) 1047 return; 1048 1049 // q is a number between 0 and 1 1050 // It is the point in the segment where the intersection occurs 1051 // if the segment is scaled to length 1 1052 1053 double q = det(pB.north() - pC.north(), pB.east() - pC.east(), pD.north() - pC.north(), pD.east() - pC.east()) / u; 1054 EastNorth intersection = new EastNorth( 1055 pB.east() + q * (pA.east() - pB.east()), 1056 pB.north() + q * (pA.north() - pB.north())); 1057 1058 1059 // only adjust to intersection if within snapToIntersectionThreshold pixel of mouse click; otherwise 1060 // fall through to default action. 1061 // (for semi-parallel lines, intersection might be miles away!) 1062 if (Main.map.mapView.getPoint2D(n).distance(Main.map.mapView.getPoint2D(intersection)) < SNAP_TO_INTERSECTION_THRESHOLD.get()) { 1063 n.setEastNorth(intersection); 1064 return; 1065 } 1066 1067 adjustNodeDefault(segs, n); 1068 } 1069 1070 private static void adjustNodeDefault(Collection<Pair<Node, Node>> segs, Node n) { 1071 EastNorth p = n.getEastNorth(); 1072 Pair<Node, Node> seg = segs.iterator().next(); 1073 EastNorth pA = seg.a.getEastNorth(); 1074 EastNorth pB = seg.b.getEastNorth(); 1075 double a = p.distanceSq(pB); 1076 double b = p.distanceSq(pA); 1077 double c = pA.distanceSq(pB); 1078 double q = (a - b + c) / (2*c); 1079 n.setEastNorth(new EastNorth(pB.east() + q * (pA.east() - pB.east()), pB.north() + q * (pA.north() - pB.north()))); 1072 1080 } 1073 1081 -
trunk/src/org/openstreetmap/josm/data/osm/QuadBuckets.java
r11452 r11601 241 241 if (nw != null) 242 242 return nw; 243 if (se != null) 244 return se; 245 return ne; 243 246 case NW_INDEX: 244 247 if (se != null) 245 248 return se; 249 return ne; 246 250 case SE_INDEX: 247 251 return ne; 248 } 249 return null; 252 default: 253 return null; 254 } 250 255 } 251 256 -
trunk/src/org/openstreetmap/josm/data/projection/proj/LambertAzimuthalEqualArea.java
r10378 r11601 183 183 @Override 184 184 public double[] invproject(double x, double y) { 185 final double lambda, phi;186 185 switch (mode) { 187 186 case EQUATORIAL: // Fall through 188 case OBLIQUE: { 189 x /= dd; 190 y *= dd; 191 final double rho = Math.hypot(x, y); 192 if (rho < FINE_EPSILON) { 193 lambda = 0.0; 194 phi = latitudeOfOrigin; 195 } else { 196 double sCe, cCe, ab; 197 sCe = 2.0 * Math.asin(0.5 * rho / rq); 198 cCe = Math.cos(sCe); 199 sCe = Math.sin(sCe); 200 x *= sCe; 201 if (mode == Mode.OBLIQUE) { 202 ab = cCe * sinb1 + y * sCe * cosb1 / rho; 203 y = rho * cosb1 * cCe - y * sinb1 * sCe; 204 } else { 205 ab = y * sCe / rho; 206 y = rho * cCe; 207 } 208 lambda = Math.atan2(x, y); 209 phi = authlat(Math.asin(ab)); 210 } 211 break; 187 case OBLIQUE: 188 return invprojectEO(x, y); 189 case NORTH_POLE: 190 return invprojectNS(x, -y); 191 case SOUTH_POLE: 192 return invprojectNS(x, y); 193 default: 194 throw new AssertionError(mode); 195 } 196 } 197 198 private double[] invprojectEO(double x, double y) { 199 final double lambda; 200 final double phi; 201 x /= dd; 202 y *= dd; 203 final double rho = Math.hypot(x, y); 204 if (rho < FINE_EPSILON) { 205 lambda = 0.0; 206 phi = latitudeOfOrigin; 207 } else { 208 final double ab; 209 double sCe = 2.0 * Math.asin(0.5 * rho / rq); 210 double cCe = Math.cos(sCe); 211 sCe = Math.sin(sCe); 212 x *= sCe; 213 if (mode == Mode.OBLIQUE) { 214 ab = cCe * sinb1 + y * sCe * cosb1 / rho; 215 y = rho * cosb1 * cCe - y * sinb1 * sCe; 216 } else { 217 ab = y * sCe / rho; 218 y = rho * cCe; 212 219 } 213 case NORTH_POLE: { 214 y = -y; 215 // Fall through 220 lambda = Math.atan2(x, y); 221 phi = authlat(Math.asin(ab)); 222 } 223 return new double[] {phi, lambda}; 224 } 225 226 private double[] invprojectNS(double x, double y) { 227 final double lambda; 228 final double phi; 229 final double q = x*x + y*y; 230 if (q == 0) { 231 lambda = 0.; 232 phi = latitudeOfOrigin; 233 } else { 234 double ab = 1.0 - q / qp; 235 if (mode == Mode.SOUTH_POLE) { 236 ab = -ab; 216 237 } 217 case SOUTH_POLE: { 218 final double q = x*x + y*y; 219 if (q == 0) { 220 lambda = 0.; 221 phi = latitudeOfOrigin; 222 } else { 223 double ab = 1.0 - q / qp; 224 if (mode == Mode.SOUTH_POLE) { 225 ab = -ab; 226 } 227 lambda = Math.atan2(x, y); 228 phi = authlat(Math.asin(ab)); 229 } 230 break; 231 } 232 default: { 233 throw new AssertionError(mode); 234 } 238 lambda = Math.atan2(x, y); 239 phi = authlat(Math.asin(ab)); 235 240 } 236 241 return new double[] {phi, lambda}; 237 242 } 238 239 243 240 244 /** -
trunk/src/org/openstreetmap/josm/gui/conflict/tags/RelationMemberConflictResolverModel.java
r11463 r11601 385 385 if (relation.getMember(i).getMember() != newPrimitive) 386 386 return true; 387 break; 387 388 case UNDECIDED: 388 389 // FIXME: handle error
Note:
See TracChangeset
for help on using the changeset viewer.