Distances are used in the library here and there. To deal with different units, conversion used to be calculated in the logic itself.
This introduces a new value object for handling distances: Astronoby::Distance.
It can be initialized with meters, kilometers and astronomical units, while the distance is always stored in meters, the international unit for distances.
As a regular value object, it is immutable, handles comparison with other Astronoby::Distance objects, and can be used in some arithmetic operations with the + or - operators.
In the library, all distance notions have been converted to this new value object, with significant breaking changes:
Astronoby::Observer#elevation is now a Astronoby::Distance
Astronoby::GeocentricParallax::angle now requires a Astronoby::Distance
Astronoby::GeocentricParallax::for_equatorial_coordinates as well for elevation and distance
Astronoby::Moon#distance now returns a Astronoby::Distance
Precision
Because distances are stored in meters, floating points rounding errors are quite likely. For now, I don't think this is a problem. But if we start to see it is one, we'll have to introduce BigDecimal again.
Distances are used in the library here and there. To deal with different units, conversion used to be calculated in the logic itself.
This introduces a new value object for handling distances:
Astronoby::Distance
.It can be initialized with meters, kilometers and astronomical units, while the distance is always stored in meters, the international unit for distances.
As a regular value object, it is immutable, handles comparison with other
Astronoby::Distance
objects, and can be used in some arithmetic operations with the+
or-
operators.In the library, all distance notions have been converted to this new value object, with significant breaking changes:
Astronoby::Observer#elevation
is now aAstronoby::Distance
Astronoby::GeocentricParallax::angle
now requires aAstronoby::Distance
Astronoby::GeocentricParallax::for_equatorial_coordinates
as well forelevation
anddistance
Astronoby::Moon#distance
now returns aAstronoby::Distance
Precision
Because distances are stored in meters, floating points rounding errors are quite likely. For now, I don't think this is a problem. But if we start to see it is one, we'll have to introduce
BigDecimal
again.