Changeset 4846 in josm for trunk


Ignore:
Timestamp:
2012-01-22T11:50:28+01:00 (12 years ago)
Author:
simon04
Message:

see #7184 - Added ImproveWayAccuracy plugin to josm core. This plugin was initially written by Alexander Kachkaev (kachkaev).

Location:
trunk
Files:
8 added
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/MapFrame.java

    r4840 r4846  
    4242import org.openstreetmap.josm.actions.mapmode.DrawAction;
    4343import org.openstreetmap.josm.actions.mapmode.ExtrudeAction;
     44import org.openstreetmap.josm.actions.mapmode.ImproveWayAccuracyAction;
    4445import org.openstreetmap.josm.actions.mapmode.MapMode;
    4546import org.openstreetmap.josm.actions.mapmode.ParallelWayAction;
     
    145146        addMapMode(new IconToggleButton(new ExtrudeAction(this), true));
    146147        addMapMode(new IconToggleButton(new ParallelWayAction(this), true));
     148        addMapMode(new IconToggleButton(new ImproveWayAccuracyAction(Main.map), true));
    147149
    148150        toolGroup.setSelected(((AbstractButton)toolBarActions.getComponent(0)).getModel(), true);
  • trunk/src/org/openstreetmap/josm/plugins/PluginHandler.java

    r4737 r4846  
    106106            new DeprecatedPlugin("ParallelWay", IN_CORE),
    107107            new DeprecatedPlugin("dumbutils", tr("replaced by new {0} plugin","utilsplugin2")),
     108            new DeprecatedPlugin("ImproveWayAccuracy", IN_CORE),
    108109        });
    109110    }
  • trunk/src/org/openstreetmap/josm/tools/Geometry.java

    r4344 r4846  
    551551        return area2 < 0;
    552552    }
     553
     554    /**
     555     * Returns angle of a segment defined with 2 point coordinates.
     556     *
     557     * @param p1
     558     * @param p2
     559     * @return Angle in radians (-pi, pi]
     560     */
     561    public static double getSegmentAngle(EastNorth p1, EastNorth p2) {
     562        return Math.atan2(p2.north() - p1.north(), p2.east() - p1.east());
     563    }
     564
     565    /**
     566     * Returns angle of a corner defined with 3 point coordinates.
     567     *
     568     * @param p1
     569     * @param p2 Common endpoint
     570     * @param p3
     571     * @return Angle in radians (-pi, pi]
     572     */
     573    public static double getCornerAngle(EastNorth p1, EastNorth p2, EastNorth p3) {
     574        Double result = getSegmentAngle(p2, p1) - getSegmentAngle(p2, p3);
     575        if (result <= -Math.PI) {
     576            result += 2 * Math.PI;
     577        }
     578
     579        if (result > Math.PI) {
     580            result -= 2 * Math.PI;
     581        }
     582
     583        return result;
     584    }
     585
     586    /**
     587     * Returns the coordinate of intersection of segment sp1-sp2 and an altitude
     588     * to it starting at point ap. If the line defined with sp1-sp2 intersects
     589     * its altitude out of sp1-sp2, null is returned.
     590     *
     591     * @param sp1
     592     * @param sp2
     593     * @param ap
     594     * @return Intersection coordinate or null
     595     */
     596    public static EastNorth getSegmentAltituteIntersection(EastNorth sp1,
     597            EastNorth sp2, EastNorth ap) {
     598        Double segmentLenght = sp1.distance(sp2);
     599        Double altitudeAngle = getSegmentAngle(sp1, sp2) + Math.PI / 2;
     600
     601        // Taking a random point on the altitude line (angle is known).
     602        EastNorth ap2 = new EastNorth(ap.east() + 1000
     603                * Math.cos(altitudeAngle), ap.north() + 1000
     604                * Math.sin(altitudeAngle));
     605
     606        // Finding the intersection of two lines
     607        EastNorth resultCandidate = Geometry.getLineLineIntersection(sp1, sp2,
     608                ap, ap2);
     609
     610        // Filtering result
     611        if (resultCandidate != null
     612                && resultCandidate.distance(sp1) * .999 < segmentLenght
     613                && resultCandidate.distance(sp2) * .999 < segmentLenght) {
     614            return resultCandidate;
     615        } else {
     616            return null;
     617        }
     618    }
    553619}
Note: See TracChangeset for help on using the changeset viewer.