Changeset 3184 in josm for trunk/src/org/openstreetmap
- Timestamp:
- 2010-04-14T23:06:53+02:00 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/mapmode/ExtrudeAction.java
r3177 r3184 81 81 private EastNorth lastTranslatedN1en; 82 82 /** 83 * Normal unit vector of the selected segment.84 */85 private EastNorth normalUnitVector;86 /**87 * Vector of node2 from node1.88 */89 private EastNorth segmentVector;90 /**91 * Transforms the mouse point (in EastNorth space) to the normal-shifted position92 * of point 1 of the selectedSegment.93 */94 private AffineTransform normalTransform;95 96 /**97 83 * Create a new SelectAction 98 84 * @param mapFrame The MapFrame this action belongs to. … … 156 142 // Just sit tight and wait for mouse to be released. 157 143 } else { 158 // This may be ugly, but I can't see any other way of getting a mapview from here. 159 EastNorth mouseen = Main.map.mapView.getEastNorth(e.getPoint().x, e.getPoint().y); 160 161 Point2D newN1point = normalTransform.transform(mouseen, null); 162 163 newN1en = new EastNorth(newN1point.getX(), newN1point.getY()); 164 newN2en = newN1en.add(segmentVector.getX(), segmentVector.getY()); 144 Node nd1 = selectedSegment.way.getNode(selectedSegment.lowerIndex); 145 Node nd2 = selectedSegment.way.getNode(selectedSegment.lowerIndex + 1); 146 147 EastNorth en1 = nd1.getEastNorth(); 148 EastNorth en2 = nd2.getEastNorth(); 149 EastNorth en3 = Main.map.mapView.getEastNorth(e.getPoint().x, e.getPoint().y); 150 151 double u = ((en3.east() - en1.east()) * (en2.east() - en1.east()) + 152 (en3.north() - en1.north()) * (en2.north() - en1.north())) / 153 en2.distanceSq(en1); 154 // the point on the segment from which the distance to mouse pos is shortest 155 EastNorth base = new EastNorth(en1.east() + u * (en2.east() - en1.east()), 156 en1.north() + u * (en2.north() - en1.north())); 157 158 // find out the distance, in metres, between the base point and the mouse cursor 159 double distance = Main.proj.eastNorth2latlon(base).greatCircleDistance(Main.proj.eastNorth2latlon(en3)); 160 Main.map.statusLine.setDist(distance); 161 updateStatusLine(); 162 163 // compute vertical and horizontal components. 164 double xoff = en3.east() - base.east(); 165 double yoff = en3.north() - base.north(); 166 167 newN1en = new EastNorth(en1.getX() + xoff, en1.getY() + yoff); 168 newN2en = new EastNorth(en2.getX() + xoff, en2.getY() + yoff); 165 169 166 170 // find out the distance, in metres, between the initial position of N1 and the new one. … … 260 264 g2.draw(oldline); 261 265 266 EastNorth segmentVector = new EastNorth(initialN2en.getX()-initialN1en.getX(), initialN2en.getY()-initialN1en.getY()); 267 268 double fac = 1.0 / Math.hypot(segmentVector.getX(), segmentVector.getY()); 269 // swap coords to get normal, mult by factor to get unit vector. 270 EastNorth normalUnitVector = new EastNorth(segmentVector.getY() * fac, segmentVector.getX() * fac); 271 262 272 // Draw a guideline along the normal. 263 273 Line2D normline; … … 335 345 // Make note of mouse position 336 346 initialMousePos = e.getPoint(); 337 338 segmentVector = new EastNorth(initialN2en.getX()-initialN1en.getX(), initialN2en.getY()-initialN1en.getY());339 double factor = 1.0 / Math.hypot(segmentVector.getX(), segmentVector.getY());340 // swap coords to get normal, mult by factor to get unit vector.341 normalUnitVector = new EastNorth(segmentVector.getY() * factor, segmentVector.getX() * factor);342 343 // The calculation of points along the normal of the segment from mouse344 // points is actually a purely affine mapping. So the majority of the maths345 // can be done once, on mousePress, by building an AffineTransform which346 // we can use in the other functions.347 double r = 1.0 / ( (normalUnitVector.getX()*normalUnitVector.getX()) + (normalUnitVector.getY()*normalUnitVector.getY()) );348 double s = (normalUnitVector.getX()*initialN1en.getX()) - (normalUnitVector.getY()*initialN1en.getY());349 double compcoordcoeff = -r*normalUnitVector.getX()*normalUnitVector.getY();350 351 // Build the matrix. Takes a mouse position in EastNorth-space and returns the new position of node1352 // based on that.353 normalTransform = new AffineTransform(354 r*normalUnitVector.getX()*normalUnitVector.getX(), compcoordcoeff,355 compcoordcoeff, r*normalUnitVector.getY()*normalUnitVector.getY(),356 initialN1en.getX()-(s*r*normalUnitVector.getX()), initialN1en.getY()+(s*r*normalUnitVector.getY()));357 347 358 348 // Switch mode.
Note:
See TracChangeset
for help on using the changeset viewer.