Changeset 1186 in josm for trunk/src


Ignore:
Timestamp:
2008-12-28T14:01:59+01:00 (11 years ago)
Author:
stoecker
Message:

fixed bug #1442. Patch by Matthew W. S. Bell

File:
1 edited

Legend:

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

    r1169 r1186  
    149149        if (selectedSegment != null) {
    150150            Node n1 = selectedSegment.way.nodes.get(selectedSegment.lowerIndex);
    151             Node n2 = selectedSegment.way.nodes.get(selectedSegment.lowerIndex+1);
     151            Node n2 = selectedSegment.way.nodes.get(selectedSegment.lowerIndex + 1);
    152152
    153153            EastNorth en1 = n1.eastNorth;
    154154            EastNorth en2 = n2.eastNorth;
    155             if (en1.east() < en2.east()) { en2 = en1; en1 = n2.eastNorth; }
    156155            EastNorth en3 = mv.getEastNorth(mousePos.x, mousePos.y);
    157156
    158             double u = ((en3.east()-en1.east())*(en2.east()-en1.east()) + (en3.north()-en1.north())*(en2.north()-en1.north()))/en2.distanceSq(en1);
     157            double u = ((en3.east() - en1.east()) * (en2.east() - en1.east()) +
     158                        (en3.north() - en1.north()) * (en2.north() - en1.north())) /
     159                       en2.distanceSq(en1);
    159160            // the point on the segment from which the distance to mouse pos is shortest
    160             EastNorth base = new EastNorth(en1.east()+u*(en2.east()-en1.east()), en1.north()+u*(en2.north()-en1.north()));
    161 
    162             // the distance, in projection units, between the base point and the mouse cursor
    163             double len = base.distance(en3);
     161            EastNorth base = new EastNorth(en1.east() + u * (en2.east() - en1.east()),
     162                                           en1.north() + u * (en2.north() - en1.north()));
    164163
    165164            // find out the distance, in metres, between the base point and the mouse cursor
     
    168167            updateStatusLine();
    169168
    170             // compute the angle at which the segment is drawn
    171             // and use it to compute the x and y offsets for the
    172             // corner points.
    173             double sin_alpha = (en2.north()-en1.north())/en2.distance(en1);
    174 
    175             // this is a kludge because sometimes extrusion just goes the wrong direction
    176             if ((en3.east()>base.east()) ^ (sin_alpha < 0)) len=-len;
    177             xoff = sin_alpha * len;
    178             yoff = Math.sqrt(1-sin_alpha*sin_alpha) * len;
    179 
    180             Graphics2D g2 = (Graphics2D) g;
     169            // compute vertical and horizontal components.
     170            xoff = en3.east() - base.east();
     171            yoff = en3.north() - base.north();
     172
     173            Graphics2D g2 = (Graphics2D)g;
    181174            g2.setColor(selectedColor);
    182175            g2.setStroke(new BasicStroke(3, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));
    183176            GeneralPath b = new GeneralPath();
    184             Point p1=mv.getPoint(en1);
    185             Point p2=mv.getPoint(en2);
    186             Point p3=mv.getPoint(en1.add(-xoff, -yoff));
    187             Point p4=mv.getPoint(en2.add(-xoff, -yoff));
    188 
    189             b.moveTo(p1.x,p1.y); b.lineTo(p3.x, p3.y);
     177            Point p1 = mv.getPoint(en1);
     178            Point p2 = mv.getPoint(en2);
     179            Point p3 = mv.getPoint(en1.add(xoff, yoff));
     180            Point p4 = mv.getPoint(en2.add(xoff, yoff));
     181
     182            b.moveTo(p1.x, p1.y); b.lineTo(p3.x, p3.y);
    190183            b.lineTo(p4.x, p4.y); b.lineTo(p2.x, p2.y);
    191             b.lineTo(p1.x,p1.y);
     184            b.lineTo(p1.x, p1.y);
    192185            g2.draw(b);
    193186            g2.setStroke(new BasicStroke(1));
     
    230223            Node n1 = selectedSegment.way.nodes.get(selectedSegment.lowerIndex);
    231224            Node n2 = selectedSegment.way.nodes.get(selectedSegment.lowerIndex+1);
    232             EastNorth en3 = n2.eastNorth.add(-xoff, -yoff);
     225            EastNorth en3 = n2.eastNorth.add(xoff, yoff);
    233226            Node n3 = new Node(Main.proj.eastNorth2latlon(en3));
    234             EastNorth en4 = n1.eastNorth.add(-xoff, -yoff);
     227            EastNorth en4 = n1.eastNorth.add(xoff, yoff);
    235228            Node n4 = new Node(Main.proj.eastNorth2latlon(en4));
    236229            Way wnew = new Way(selectedSegment.way);
Note: See TracChangeset for help on using the changeset viewer.