Ignore:
Timestamp:
2016-08-29T17:44:50+02:00 (8 years ago)
Author:
michael2402
Message:

Use Utils.clamp in LatLon. Document public methods.

File:
1 edited

Legend:

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

    r10334 r10914  
    131131    }
    132132
     133    /**
     134     * Clamp the lat value to be inside the world.
     135     * @param value The value
     136     * @return The value clamped to the world.
     137     */
    133138    public static double toIntervalLat(double value) {
    134         if (value < -90)
    135             return -90;
    136         if (value > 90)
    137             return 90;
    138         return value;
     139        return Utils.clamp(value, -90, 90);
    139140    }
    140141
     
    419420    }
    420421
     422    /**
     423     * Interpolate between this and a other latlon
     424     * @param ll2 The other lat/lon object
     425     * @param proportion The proportion to interpolate
     426     * @return a new latlon at this position if proportion is 0, at the other position it proportion is 1 and lineary interpolated otherwise.
     427     */
    421428    public LatLon interpolate(LatLon ll2, double proportion) {
    422429        return new LatLon(this.lat() + proportion * (ll2.lat() - this.lat()),
     
    424431    }
    425432
     433    /**
     434     * Get the center between two lat/lon points
     435     * @param ll2 The other {@link LatLon}
     436     * @return The center at the average coordinates of the two points. Does not take the 180° meridian into account.
     437     */
    426438    public LatLon getCenter(LatLon ll2) {
    427         return new LatLon((this.lat() + ll2.lat())/2.0, (this.lon() + ll2.lon())/2.0);
     439        return interpolate(ll2, .5);
    428440    }
    429441
Note: See TracChangeset for help on using the changeset viewer.