Class SexagesimalConverter.Inverse

All Implemented Interfaces:
Serializable, javax.measure.UnitConverter
Enclosing class:
SexagesimalConverter

private static final class SexagesimalConverter.Inverse extends SexagesimalConverter
The inverse of SexagesimalConverter, i.e. the converter from sexagesimal degrees to decimal degrees.
  • Field Details

    • serialVersionUID

      private static final long serialVersionUID
      Serial number for compatibility with different versions.
      See Also:
  • Constructor Details

  • Method Details

    • fixRoundingError

      private static double fixRoundingError(double remainder, double magnitude)
      After calculation of the remaining seconds or minutes, trims the rounding errors presumably caused by rounding errors in floating point arithmetic. This is required for avoiding the following conversion issue:
      1. Sexagesimal value: 46.570866 (from 46°57'8.66"N in EPSG:2056 projected CRS)
      2. value * 10000 = 465708.66000000003
      3. deg = 46, min = 57, deg = 8.660000000032596
      We perform a rounding based on the representation in base 10 because extractions of degrees and minutes fields from the sexagesimal value themselves use arithmetic in base 10. This conversion is used in contexts where the sexagesimal value, as shown in a number in base 10, is definitive.
      Parameters:
      remainder - the value to fix, after other fields (degrees and/or minutes) have been subtracted.
      magnitude - value of remainder before the degrees and/or minutes were subtracted.
    • convert

      public double convert(double angle) throws IllegalArgumentException
      Performs a conversion from sexagesimal degrees to fractional degrees.
      Specified by:
      convert in interface javax.measure.UnitConverter
      Overrides:
      convert in class SexagesimalConverter
      Throws:
      IllegalArgumentException - If the given angle cannot be converted.
    • illegalField

      private static IllegalArgumentException illegalField(double value, double field, int unit)
      Creates an exception for an illegal field.
      Parameters:
      value - the user supplied angle value.
      field - the value of the illegal field.
      unit - 0 for minutes or 1 for seconds.
      Returns:
      the exception to throw.