Changeset 3184 in josm for trunk/src/org/openstreetmap


Ignore:
Timestamp:
2010-04-14T23:06:53+02:00 (15 years ago)
Author:
bastiK
Message:

fixed #4256 - Extrude snaps to a sparse grid (Changed the geometrical calculations back to how they were before [2429])

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/actions/mapmode/ExtrudeAction.java

    r3177 r3184  
    8181    private EastNorth lastTranslatedN1en;
    8282    /**
    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 position
    92      * of point 1 of the selectedSegment.
    93      */
    94     private AffineTransform normalTransform;
    95 
    96     /**
    9783     * Create a new SelectAction
    9884     * @param mapFrame The MapFrame this action belongs to.
     
    156142            // Just sit tight and wait for mouse to be released.
    157143        } 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);
    165169
    166170            // find out the distance, in metres, between the initial position of N1 and the new one.
     
    260264                    g2.draw(oldline);
    261265
     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
    262272                    // Draw a guideline along the normal.
    263273                    Line2D normline;
     
    335345            // Make note of mouse position
    336346            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 mouse
    344             // points is actually a purely affine mapping. So the majority of the maths
    345             // can be done once, on mousePress, by building an AffineTransform which
    346             // 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 node1
    352             // 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()));
    357347
    358348            // Switch mode.
Note: See TracChangeset for help on using the changeset viewer.