Skip to content

Introduce Astronoby::Distance value object#78

Merged
rhannequin merged 4 commits intomainfrom
distance-value-object
May 27, 2024
Merged

Introduce Astronoby::Distance value object#78
rhannequin merged 4 commits intomainfrom
distance-value-object

Conversation

@rhannequin
Copy link
Owner

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.

ten_meters = Astronoby::Distance.from_meters(10)
ten_kilometers = Astronoby::Distance.from_kilometers(10)

ten_meters < ten_kilometers
# => true

sum = ten_meters + ten_kilometers
sum.meters
# => 10010

sum.au
# => 6.691271709390715e-08

@rhannequin rhannequin self-assigned this May 19, 2024
@rhannequin rhannequin force-pushed the distance-value-object branch from 75351e2 to 4b26a33 Compare May 20, 2024 13:45
@rhannequin rhannequin force-pushed the clearer-moon-coordinates-method-names branch from 2ec2670 to 5c2ad4e Compare May 20, 2024 20:13
@rhannequin rhannequin force-pushed the distance-value-object branch from 4b26a33 to c4b1617 Compare May 20, 2024 20:13
@rhannequin rhannequin force-pushed the clearer-moon-coordinates-method-names branch from 5c2ad4e to 490d264 Compare May 22, 2024 23:00
@rhannequin rhannequin force-pushed the distance-value-object branch from c4b1617 to 652a7c3 Compare May 22, 2024 23:00
@rhannequin rhannequin force-pushed the clearer-moon-coordinates-method-names branch from 490d264 to 500db51 Compare May 24, 2024 08:36
@rhannequin rhannequin force-pushed the distance-value-object branch from 652a7c3 to 1f703bd Compare May 24, 2024 08:37
Base automatically changed from clearer-moon-coordinates-method-names to main May 24, 2024 09:43
@rhannequin rhannequin force-pushed the distance-value-object branch from 1f703bd to 2326b31 Compare May 24, 2024 09:46
@rhannequin rhannequin merged commit 0577b48 into main May 27, 2024
@rhannequin rhannequin deleted the distance-value-object branch May 27, 2024 18:50
rhannequin added a commit that referenced this pull request Jun 11, 2024
 ## 0.5.0 - 2024-06-11

_If you are upgrading: please see [UPGRADING.md]._

[UPGRADING.md]: https://github.com/rhannequin/astronoby/blob/main/UPGRADING.md

 ### Features

* Make `Sun#mean_anomaly` public ([#72])
* Moon ecliptic coordinates ([#73])
* Moon apparent geocentric equatorial coordinates ([#75])
* Moon horizontal coordinates ([#76])
* Assume Moon's equatorial coordinates are geocentric ([#77])
* Use observer object for geocentric parallax ([#79])
* Moon's phase angle and illuminated fraction ([#80])
* Monthly Moon phases ([#82])
* Rationalize negative degree angles ([#83])
* Factorize Moon phases periodic terms ([#85])
* Introduce observation events for Moon ([#86])

[#72]: #72
[#73]: #73
[#75]: #75
[#76]: #76
[#77]: #77
[#79]: #79
[#80]: #80
[#82]: #82
[#83]: #83
[#85]: #85
[#86]: #86

 ### Improvements

* Create FUNDING.yml ([#70])
* Bump standard from 1.35.1 to 1.36.0 ([#71])
* Bump rexml from 3.2.6 to 3.2.8 ([#74])
* Expand the number of tested Ruby versions ([#84])
* Add Ruby 3.1.6 and 3.3.2 coverage ([#88])
* Improve and update documentation ([#87])
* Update UPGRADING.md ([#89])

[#70]: #70
[#71]: #71
[#74]: #74
[#84]: #84
[#88]: #88
[#87]: #87
[#89]: #89

 ### Backward-incompatible changes

* Use Observer in Horizontal coordinates ([#69])
* Introduce `Astronoby::Distance` value object ([#78])

[#69]: #69
[#78]: #78

**Full Changelog**: v0.4.0...v0.5.0
rhannequin added a commit that referenced this pull request Jun 11, 2024
### Features

* Make `Sun#mean_anomaly` public ([#72])
* Moon ecliptic coordinates ([#73])
* Moon apparent geocentric equatorial coordinates ([#75])
* Moon horizontal coordinates ([#76])
* Assume Moon's equatorial coordinates are geocentric ([#77])
* Use observer object for geocentric parallax ([#79])
* Moon's phase angle and illuminated fraction ([#80])
* Monthly Moon phases ([#82])
* Rationalize negative degree angles ([#83])
* Factorize Moon phases periodic terms ([#85])
* Introduce observation events for Moon ([#86])

[#72]: #72
[#73]: #73
[#75]: #75
[#76]: #76
[#77]: #77
[#79]: #79
[#80]: #80
[#82]: #82
[#83]: #83
[#85]: #85
[#86]: #86

### Improvements

* Create FUNDING.yml ([#70])
* Bump standard from 1.35.1 to 1.36.0 ([#71])
* Bump rexml from 3.2.6 to 3.2.8 ([#74])
* Expand the number of tested Ruby versions ([#84])
* Add Ruby 3.1.6 and 3.3.2 coverage ([#88])
* Improve and update documentation ([#87])
* Update UPGRADING.md ([#89])

[#70]: #70
[#71]: #71
[#74]: #74
[#84]: #84
[#88]: #88
[#87]: #87
[#89]: #89

### Backward-incompatible changes

* Use Observer in Horizontal coordinates ([#69])
* Introduce `Astronoby::Distance` value object ([#78])

[#69]: #69
[#78]: #78

**Full Changelog**: v0.4.0...v0.5.0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant