Changeset 1076 in josm


Ignore:
Timestamp:
2008-11-13T19:41:48+01:00 (15 years ago)
Author:
framm
Message:
  • replaced he align-in-rectangle function with a more general method that will make all angles in the selected shape orthogonal. if, in addition to one or more ways, exactly two nodes are also selected, then these two nodes determine the orientation of each resulting segment, otherwise a best match is chosen. Patch by Harald Kucharek.
Location:
trunk
Files:
2 added
2 deleted
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/coor/EastNorth.java

    r655 r1076  
    2828       
    2929        public EastNorth interpolate(EastNorth en2, double proportion) {
    30                 return new EastNorth(this.x + proportion * (en2.x - this.x),this.y + proportion * (en2.y - this.y));
     30                return new EastNorth(this.x + proportion * (en2.x - this.x),
     31            this.y + proportion * (en2.y - this.y));
    3132        }
     33   
     34    /**
     35     * Returns the heading, in radians, that you have to use to get from
     36     * this EastNorth to another. Heading is mapped into [0, 2pi)
     37     *
     38     * @param other the "destination" position
     39     * @return heading
     40     */
     41    public double heading(EastNorth other) {
     42        double hd = Math.atan2(other.east() - east(), other.north() - north());
     43        if(hd < 0) hd = 2 * Math.PI + hd;
     44        return hd;       
     45    }
     46   
     47    public EastNorth sub(EastNorth en) {
     48        return new EastNorth(en.east() - east(), en.north() - north());
     49    }
     50 
     51    /**
     52     * Returns an EastNorth representing the this EastNorth rotatedaround
     53     * a given EastNorth by a given angle
     54     * @param pivot the center of the rotation
     55     * @param angle the angle of the rotation
     56     * @return EastNorth rotated object
     57     */
     58    public EastNorth rotate(EastNorth pivot, double angle) {
     59        double cosPhi = Math.cos(angle);
     60        double sinPhi = Math.sin(angle);
     61        double x = east() - pivot.east();
     62        double y = north() - pivot.north();
     63        double nx =  cosPhi * x + sinPhi * y + pivot.east();
     64        double ny = -sinPhi * x + cosPhi * y + pivot.north();
     65        return new EastNorth(nx, ny);
     66    }
    3267       
    3368        @Override public String toString() {
    3469                return "EastNorth[e="+x+", n="+y+"]";
    3570        }
     71
     72    /**
     73     * Compares two EastNorth values
     74     *
     75     * @return true if "x" and "y" values are within 1E-6 of each other
     76     */
     77    public boolean equalsEpsilon(EastNorth other, double e) {
     78        return (Math.abs(x - other.x) < e && Math.abs(y - other.y) < e);
     79    }
    3680}
  • trunk/src/org/openstreetmap/josm/gui/MainMenu.java

    r1054 r1076  
    1919import org.openstreetmap.josm.actions.AlignInCircleAction;
    2020import org.openstreetmap.josm.actions.AlignInLineAction;
    21 import org.openstreetmap.josm.actions.AlignInRectangleAction;
     21import org.openstreetmap.josm.actions.OrthogonalizeAction;
    2222import org.openstreetmap.josm.actions.AutoScaleAction;
    2323import org.openstreetmap.josm.actions.CombineWayAction;
     
    106106        public final JosmAction alignInCircle = new AlignInCircleAction();
    107107        public final JosmAction alignInLine = new AlignInLineAction();
    108         public final JosmAction alignInRect = new AlignInRectangleAction();
     108    public final JosmAction ortho = new OrthogonalizeAction();
    109109        public final JosmAction createCircle = new CreateCircleAction();
    110110        public final JosmAction mergeNodes = new MergeNodesAction();
     
    223223                add(toolsMenu, alignInCircle);
    224224                add(toolsMenu, alignInLine);
    225                 add(toolsMenu, alignInRect);
     225                add(toolsMenu, ortho);
    226226                toolsMenu.addSeparator();
    227227                add(toolsMenu, createCircle);
Note: See TracChangeset for help on using the changeset viewer.