Ignore:
Timestamp:
2022-06-15T20:10:48+02:00 (2 years ago)
Author:
taylor.smock
Message:

See #22115: Extract methods from LatLon into ILatLon where they are generally applicable

This uses the extracted methods where possible, and removes unnecessary
Node#getCoor calls.

Location:
applications/editors/josm/plugins/measurement/src/org/openstreetmap/josm/plugins/measurement
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/measurement/src/org/openstreetmap/josm/plugins/measurement/MeasurementDialog.java

    r35976 r35978  
    204204            } else {
    205205                for (Node n : nodes) {
    206                     if (n.getCoor() != null) {
     206                    if (n.isLatLonKnown()) {
    207207                        if (lastNode == null) {
    208208                            lastNode = n;
    209209                        } else {
    210                             length += lastNode.getCoor().greatCircleDistance(n.getCoor());
     210                            length += lastNode.greatCircleDistance(n);
    211211                            segAngle = MeasurementLayer.angleBetween(lastNode, n);
    212212                            lastNode = n;
     
    223223                boolean isCircle = true;
    224224                for (Node n: w.getNodes()) {
    225                     if (lastN != null && lastN.getCoor() != null && n.getCoor() != null) {
    226                         final double segLength = lastN.getCoor().greatCircleDistance(n.getCoor());
     225                    if (lastN != null && lastN.isLatLonKnown() && n.isLatLonKnown()) {
     226                        final double segLength = lastN.greatCircleDistance(n);
    227227                        if (firstSegLength == null) {
    228228                            firstSegLength = segLength;
     
    233233                        length += segLength;
    234234                        //http://local.wasp.uwa.edu.au/~pbourke/geometry/polyarea/
    235                         wayArea += (MeasurementLayer.calcX(n.getCoor()) * MeasurementLayer.calcY(lastN.getCoor()))
    236                                 - (MeasurementLayer.calcY(n.getCoor()) * MeasurementLayer.calcX(lastN.getCoor()));
     235                        wayArea += (MeasurementLayer.calcX(n) * MeasurementLayer.calcY(lastN))
     236                                - (MeasurementLayer.calcY(n) * MeasurementLayer.calcX(lastN));
    237237                        segAngle = MeasurementLayer.angleBetween(lastN, n);
    238238                    }
  • applications/editors/josm/plugins/measurement/src/org/openstreetmap/josm/plugins/measurement/MeasurementLayer.java

    r35976 r35978  
    157157     * https://stackoverflow.com/questions/4681737/how-to-calculate-the-area-of-a-polygon-on-the-earths-surface-using-python
    158158     */
    159     public static double calcX(LatLon p1){
     159    public static double calcX(ILatLon p1){
    160160        return p1.lat() * Math.PI * 6367000 / 180;
    161161    }
    162162
    163     public static double calcY(LatLon p1){
     163    public static double calcY(ILatLon p1){
    164164        return p1.lon() * ( Math.PI * 6367000 / 180) * Math.cos(p1.lat() * Math.PI / 180);
    165165    }
    166166
    167167    public static double calcDistance(WayPoint p1, WayPoint p2){
    168         return p1.getCoor().greatCircleDistance(p2.getCoor());
     168        return p1.greatCircleDistance(p2);
    169169    }
    170170
Note: See TracChangeset for help on using the changeset viewer.