astronoby 0.2.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +93 -2
- data/Gemfile.lock +3 -3
- data/README.md +107 -9
- data/UPGRADING.md +74 -0
- data/lib/astronoby/aberration.rb +12 -7
- data/lib/astronoby/angle.rb +42 -54
- data/lib/astronoby/bodies/sun.rb +146 -129
- data/lib/astronoby/constants.rb +25 -0
- data/lib/astronoby/coordinates/ecliptic.rb +18 -7
- data/lib/astronoby/coordinates/equatorial.rb +6 -5
- data/lib/astronoby/coordinates/horizontal.rb +8 -4
- data/lib/astronoby/epoch.rb +0 -2
- data/lib/astronoby/equinox_solstice.rb +8 -21
- data/lib/astronoby/events/observation_events.rb +319 -0
- data/lib/astronoby/events/twilight_events.rb +121 -0
- data/lib/astronoby/geocentric_parallax.rb +2 -2
- data/lib/astronoby/mean_obliquity.rb +4 -4
- data/lib/astronoby/nutation.rb +9 -7
- data/lib/astronoby/observer.rb +33 -14
- data/lib/astronoby/precession.rb +6 -6
- data/lib/astronoby/refraction.rb +4 -4
- data/lib/astronoby/time/greenwich_sidereal_time.rb +18 -29
- data/lib/astronoby/time/local_sidereal_time.rb +4 -4
- data/lib/astronoby/util/astrodynamics.rb +2 -2
- data/lib/astronoby/util/maths.rb +72 -0
- data/lib/astronoby/util/time.rb +88 -0
- data/lib/astronoby/util/trigonometry.rb +4 -4
- data/lib/astronoby/version.rb +1 -1
- data/lib/astronoby.rb +5 -1
- metadata +8 -4
- data/lib/astronoby/body.rb +0 -155
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3c65785b0c459ba8add86fcceb906205caa79a80f47b7f33c0b7ee008173fd14
|
4
|
+
data.tar.gz: 66478c6055d84e34f560490f225ae3e3d5020972e729b37e8f6f0a6566ae173e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4bae651aabaec62d258a768952eb3cd830d99639acf33f02b9f0ab6fd2eeff8215d9a30087a5818736b777c1a86344918f98f33f987f65829a8712cb20477c55
|
7
|
+
data.tar.gz: 401659e2d49599246ad2ea1a455a6d60b9797c49e730cacf8a614f4235929263c9318644373a96ea496969fcb814cc93144a8dbfffd0a0318e1628500bb1c8e8
|
data/CHANGELOG.md
CHANGED
@@ -1,10 +1,99 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
-
## 0.
|
3
|
+
## 0.4.0 - 2024-04-29
|
4
|
+
|
5
|
+
_If you are upgrading: please see [UPGRADING.md]._
|
6
|
+
|
7
|
+
[UPGRADING.md]: https://github.com/rhannequin/astronoby/blob/main/UPGRADING.md
|
8
|
+
|
9
|
+
### Bug fixes
|
10
|
+
|
11
|
+
* Fix ecliptic to equatorial epoch ([#56])
|
12
|
+
|
13
|
+
[#56]: https://github.com/rhannequin/astronoby/pull/56
|
14
|
+
|
15
|
+
### Features
|
16
|
+
|
17
|
+
* Add twilight times ([#49])
|
18
|
+
* Add interpolation method ([#52])
|
19
|
+
* Add decimal_hour_to_time util ([#53])
|
20
|
+
* Calculate leap seconds for an instant ([#54])
|
21
|
+
* Add `Angle#-@` ([#55])
|
22
|
+
* Enable equivalence and hash equality to `Observer` ([#57])
|
23
|
+
* Twilight events dedicated class ([#61])
|
24
|
+
|
25
|
+
[#49]: https://github.com/rhannequin/astronoby/pull/49
|
26
|
+
[#52]: https://github.com/rhannequin/astronoby/pull/52
|
27
|
+
[#53]: https://github.com/rhannequin/astronoby/pull/53
|
28
|
+
[#54]: https://github.com/rhannequin/astronoby/pull/54
|
29
|
+
[#55]: https://github.com/rhannequin/astronoby/pull/55
|
30
|
+
[#57]: https://github.com/rhannequin/astronoby/pull/57
|
31
|
+
[#61]: https://github.com/rhannequin/astronoby/pull/61
|
32
|
+
|
33
|
+
### Improvements
|
34
|
+
|
35
|
+
* Upgrade bundler from 2.3.11 to 2.5.7 by @dorianmariecom ([#45])
|
36
|
+
* Drop `BigDecimal` ([#46])
|
37
|
+
* Bump rake from 13.1.0 to 13.2.0 ([#47])
|
38
|
+
* Increase Ruby versions support ([#48])
|
39
|
+
* Bump rake from 13.2.0 to 13.2.1 ([#51])
|
40
|
+
* Dedicated constants class ([#62])
|
41
|
+
* Improve accuracy of equation of time ([#63])
|
42
|
+
* Twilight times better accuracy ([#65])
|
43
|
+
* Update UPGRADING.md ([#66])
|
44
|
+
* release: Bump version to 0.4.0 ([#67])
|
45
|
+
|
46
|
+
[#45]: https://github.com/rhannequin/astronoby/pull/45
|
47
|
+
[#46]: https://github.com/rhannequin/astronoby/pull/46
|
48
|
+
[#47]: https://github.com/rhannequin/astronoby/pull/47
|
49
|
+
[#48]: https://github.com/rhannequin/astronoby/pull/48
|
50
|
+
[#51]: https://github.com/rhannequin/astronoby/pull/51
|
51
|
+
[#62]: https://github.com/rhannequin/astronoby/pull/62
|
52
|
+
[#63]: https://github.com/rhannequin/astronoby/pull/63
|
53
|
+
[#65]: https://github.com/rhannequin/astronoby/pull/65
|
54
|
+
[#66]: https://github.com/rhannequin/astronoby/pull/66
|
55
|
+
[#67]: https://github.com/rhannequin/astronoby/pull/67
|
56
|
+
|
57
|
+
### Backward-incompatible changes
|
58
|
+
|
59
|
+
* More accurate rising, transit and setting times ([#50])
|
60
|
+
* Observation events dedicated and centralized class ([#60])
|
61
|
+
* Change `Astronoby::Sun` constructor ([#64])
|
62
|
+
|
63
|
+
[#50]: https://github.com/rhannequin/astronoby/pull/50
|
64
|
+
[#60]: https://github.com/rhannequin/astronoby/pull/60
|
65
|
+
[#64]: https://github.com/rhannequin/astronoby/pull/64
|
66
|
+
|
67
|
+
### New Contributors
|
68
|
+
|
69
|
+
* @dorianmariecom made their first contribution in [#45]
|
70
|
+
|
71
|
+
[#45]: https://github.com/rhannequin/astronoby/pull/45
|
72
|
+
|
73
|
+
**Full Changelog**: https://github.com/rhannequin/astronoby/compare/v0.3.0...v0.4.0
|
74
|
+
|
75
|
+
## 0.3.0 - 2024-03-29
|
4
76
|
|
5
77
|
_If you are upgrading: please see [`UPGRADING.md`]._
|
6
78
|
|
7
|
-
|
79
|
+
### Improvements
|
80
|
+
|
81
|
+
* Drop `Angle#==` ([#42])
|
82
|
+
* Improved accuracy with Sun's location predictions ([#41])
|
83
|
+
|
84
|
+
### Breaking changes
|
85
|
+
|
86
|
+
* **breaking:** Difference between true and apparent ecliptic and equatorial
|
87
|
+
coordinates ([#41])
|
88
|
+
* **breaking:** Rename `Angle::as_*` into `Angle::from_*` ([#43])
|
89
|
+
|
90
|
+
[#41]: https://github.com/rhannequin/astronoby/pull/41
|
91
|
+
[#42]: https://github.com/rhannequin/astronoby/pull/42
|
92
|
+
[#43]: https://github.com/rhannequin/astronoby/pull/43
|
93
|
+
|
94
|
+
## 0.2.0 - 2024-03-24
|
95
|
+
|
96
|
+
_If you are upgrading: please see [`UPGRADING.md`]._
|
8
97
|
|
9
98
|
### Features
|
10
99
|
|
@@ -74,3 +163,5 @@ _If you are upgrading: please see [`UPGRADING.md`]._
|
|
74
163
|
|
75
164
|
* Add `Astronoby::Angle`
|
76
165
|
* Support angles in degrees and radians
|
166
|
+
|
167
|
+
[`UPGRADING.md`]: https://github.com/rhannequin/astronoby/blob/main/UPGRADING.md
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
astronoby (0.
|
4
|
+
astronoby (0.4.0)
|
5
5
|
matrix (~> 0.4.2)
|
6
6
|
rake (~> 13.0)
|
7
7
|
rspec (~> 3.0)
|
@@ -21,7 +21,7 @@ GEM
|
|
21
21
|
racc
|
22
22
|
racc (1.7.3)
|
23
23
|
rainbow (3.1.1)
|
24
|
-
rake (13.1
|
24
|
+
rake (13.2.1)
|
25
25
|
regexp_parser (2.9.0)
|
26
26
|
rexml (3.2.6)
|
27
27
|
rspec (3.13.0)
|
@@ -77,4 +77,4 @@ DEPENDENCIES
|
|
77
77
|
standard (~> 1.3)
|
78
78
|
|
79
79
|
BUNDLED WITH
|
80
|
-
2.
|
80
|
+
2.5.7
|
data/README.md
CHANGED
@@ -28,27 +28,125 @@ This library is still in heavy development. The public is not stable, please
|
|
28
28
|
be aware new minor versions will probably lead to breaking changes until a
|
29
29
|
major one is released.
|
30
30
|
|
31
|
+
### Angle manipulation
|
32
|
+
|
33
|
+
```rb
|
34
|
+
angle1 = Astronoby::Angle.from_degrees(90)
|
35
|
+
angle2 = Astronoby::Angle.from_radians(Math::PI / 2)
|
36
|
+
angle3 = Astronoby::Angle.from_hours(12)
|
37
|
+
|
38
|
+
angle1 == angle2
|
39
|
+
# => true
|
40
|
+
|
41
|
+
angle1 < angle3
|
42
|
+
# => true
|
43
|
+
|
44
|
+
angle = angle1 + angle2 + angle3
|
45
|
+
angle.cos
|
46
|
+
# => 1.0
|
47
|
+
```
|
48
|
+
|
49
|
+
### Coordinates conversion
|
50
|
+
|
51
|
+
```rb
|
52
|
+
equatorial = Astronoby::Coordinates::Equatorial.new(
|
53
|
+
right_ascension: Astronoby::Angle.from_hms(17, 43, 54),
|
54
|
+
declination: Astronoby::Angle.from_dms(-22, 10, 0)
|
55
|
+
)
|
56
|
+
|
57
|
+
horizontal = equatorial.to_horizontal(
|
58
|
+
time: Time.new(2016, 1, 21, 21, 30, 0, "-05:00"),
|
59
|
+
latitude: Astronoby::Angle.from_degrees(38),
|
60
|
+
longitude: Astronoby::Angle.from_degrees(-78)
|
61
|
+
)
|
62
|
+
|
63
|
+
horizontal.altitude.str(:dms)
|
64
|
+
# => "-73° 27′ 19.1557″"
|
65
|
+
|
66
|
+
horizontal.azimuth.str(:dms)
|
67
|
+
# => "+341° 33′ 21.587″"
|
68
|
+
```
|
69
|
+
|
31
70
|
### Sun's location in the sky
|
32
71
|
|
33
72
|
```rb
|
34
73
|
time = Time.utc(2023, 2, 17, 11, 0, 0)
|
35
|
-
epoch = Astronoby::Epoch.from_time(time)
|
36
74
|
|
37
|
-
latitude = Astronoby::Angle.
|
38
|
-
longitude = Astronoby::Angle.
|
75
|
+
latitude = Astronoby::Angle.from_degrees(48.8566)
|
76
|
+
longitude = Astronoby::Angle.from_degrees(2.3522)
|
39
77
|
|
40
|
-
sun = Astronoby::Sun.new(
|
78
|
+
sun = Astronoby::Sun.new(time: time)
|
41
79
|
|
42
80
|
horizontal_coordinates = sun.horizontal_coordinates(
|
43
81
|
latitude: latitude,
|
44
82
|
longitude: longitude
|
45
83
|
)
|
46
84
|
|
47
|
-
horizontal_coordinates.altitude.degrees
|
48
|
-
# => 27.
|
85
|
+
horizontal_coordinates.altitude.degrees
|
86
|
+
# => 27.500082409271247
|
49
87
|
|
50
88
|
horizontal_coordinates.altitude.str(:dms)
|
51
|
-
# => "+27° 30′
|
89
|
+
# => "+27° 30′ 0.2966″"
|
90
|
+
```
|
91
|
+
|
92
|
+
### Sunrise and sunset times and azimuths
|
93
|
+
|
94
|
+
```rb
|
95
|
+
time = Time.new(2015, 2, 5)
|
96
|
+
observer = Astronoby::Observer.new(
|
97
|
+
latitude: Astronoby::Angle.from_degrees(38),
|
98
|
+
longitude: Astronoby::Angle.from_degrees(-78)
|
99
|
+
)
|
100
|
+
sun = Astronoby::Sun.new(time: time)
|
101
|
+
observation_events = sun.observation_events(observer: observer)
|
102
|
+
|
103
|
+
observation_events.rising_time
|
104
|
+
# => 2015-02-05 12:12:59 UTC
|
105
|
+
|
106
|
+
observation_events.rising_azimuth.str(:dms)
|
107
|
+
# => "+109° 46′ 43.145″"
|
108
|
+
|
109
|
+
observation_events.transit_time
|
110
|
+
# => 2015-02-05 17:25:59 UTC
|
111
|
+
|
112
|
+
observation_events.transit_altitude.str(:dms)
|
113
|
+
# => "+36° 8′ 15.7638″"
|
114
|
+
|
115
|
+
observation_events.setting_time
|
116
|
+
# => 2015-02-05 22:39:27 UTC
|
117
|
+
|
118
|
+
observation_events.setting_azimuth.str(:dms)
|
119
|
+
# => "+250° 23′ 33.614″"
|
120
|
+
```
|
121
|
+
|
122
|
+
### Twilight times
|
123
|
+
|
124
|
+
```rb
|
125
|
+
time = Time.new(2024, 1, 1)
|
126
|
+
sun = Astronoby::Sun.new(time: time)
|
127
|
+
observer = Astronoby::Observer.new(
|
128
|
+
latitude: Astronoby::Angle.from_degrees(48.8566),
|
129
|
+
longitude: Astronoby::Angle.from_degrees(2.3522)
|
130
|
+
)
|
131
|
+
twilight_events = sun.twilight_events(observer: observer)
|
132
|
+
|
133
|
+
twilight_events.morning_astronomical_twilight_time
|
134
|
+
# => 2024-01-01 05:49:25 UTC
|
135
|
+
|
136
|
+
twilight_events.morning_nautical_twilight_time
|
137
|
+
# => 2024-01-01 06:27:42 UTC
|
138
|
+
|
139
|
+
twilight_events.morning_civil_twilight_time
|
140
|
+
# => 2024-01-01 07:07:50 UTC
|
141
|
+
|
142
|
+
twilight_events.evening_civil_twilight_time
|
143
|
+
# => 2024-01-01 16:40:01 UTC
|
144
|
+
|
145
|
+
twilight_events.evening_nautical_twilight_time
|
146
|
+
# => 2024-01-01 17:20:10 UTC
|
147
|
+
|
148
|
+
twilight_events.evening_astronomical_twilight_time
|
149
|
+
# => 2024-01-01 17:58:26 UTC
|
52
150
|
```
|
53
151
|
|
54
152
|
### Solstice and Equinox times
|
@@ -57,10 +155,10 @@ horizontal_coordinates.altitude.str(:dms)
|
|
57
155
|
year = 2024
|
58
156
|
|
59
157
|
Astronoby::EquinoxSolstice.march_equinox(year)
|
60
|
-
# => 2024-03-20 03:05:
|
158
|
+
# => 2024-03-20 03:05:08 UTC
|
61
159
|
|
62
160
|
Astronoby::EquinoxSolstice.june_solstice(year)
|
63
|
-
# => 2024-06-20 20:50:
|
161
|
+
# => 2024-06-20 20:50:18 UTC
|
64
162
|
```
|
65
163
|
|
66
164
|
## Precision
|
data/UPGRADING.md
CHANGED
@@ -7,6 +7,80 @@ changes to it as long as a major version has not been released.
|
|
7
7
|
If you are already using Astronoby and wish to follow the changes to its
|
8
8
|
public API, please read the upgrading notes for each release.
|
9
9
|
|
10
|
+
## Upgrading from 0.3.0 to 0.4.0
|
11
|
+
|
12
|
+
### `Body` class removed ([#50])
|
13
|
+
|
14
|
+
The different behaviors from `Body` have been moved to other classes like
|
15
|
+
`Events::ObservationEvents`.
|
16
|
+
|
17
|
+
[#50]: https://github.com/rhannequin/astronoby/pull/50
|
18
|
+
|
19
|
+
### Rising and setting times and azimuths removed from `Sun` ([#60])
|
20
|
+
|
21
|
+
`#rising_time`, `#rising_azimuth`, `#setting_time` and `#setting_azimuth`
|
22
|
+
have been removed from `Astronoby::Sun` and moved to
|
23
|
+
`Astronoby::Events::ObservationEvents`.
|
24
|
+
|
25
|
+
[#60]: https://github.com/rhannequin/astronoby/pull/60
|
26
|
+
|
27
|
+
### `Sun` constructor changed ([#64])
|
28
|
+
|
29
|
+
The `Sun` constructor now doesn't accept the `epoch` key argument anymore,
|
30
|
+
but only a new `time` key argument.
|
31
|
+
|
32
|
+
[#64]: https://github.com/rhannequin/astronoby/pull/64
|
33
|
+
|
34
|
+
## Upgrading from 0.2.0 to 0.3.0
|
35
|
+
|
36
|
+
### `Sun#ecliptic_coordinates` method removed (#41)
|
37
|
+
|
38
|
+
Removed in favor of `#true_ecliptic_coordinates` and
|
39
|
+
`#apparent_ecliptic_coordinates`.
|
40
|
+
|
41
|
+
### `Coordinates::Ecliptic#to_horizontal` method removed (#41)
|
42
|
+
|
43
|
+
Removed in favor of `#to_true_horizontal` and
|
44
|
+
`#to_apparent_horizontal`.
|
45
|
+
|
46
|
+
### `Sun#true_ecliptic_coordinates` method added (#41)
|
47
|
+
|
48
|
+
Returns the true ecliptic coordinates for the date's epoch.
|
49
|
+
|
50
|
+
### `Sun#apparent_ecliptic_coordinates` method added (#41)
|
51
|
+
|
52
|
+
Returns the apparent ecliptic coordinates for the date's epoch, including
|
53
|
+
corrections for the nutation and aberration.
|
54
|
+
|
55
|
+
### `Coordinates::Ecliptic#to_true_horizontal` method added (#41)
|
56
|
+
|
57
|
+
Returns the true equatorial coordinates for ths date's epoch.
|
58
|
+
|
59
|
+
### `Coordinates::Ecliptic#to_apparent_horizontal` method added (#41)
|
60
|
+
|
61
|
+
Returns the apparent equatorial coordinates for the date's epoch, including
|
62
|
+
corrections for the obliquity.
|
63
|
+
|
64
|
+
### `Angle::as_radians` renamed into `Angle::from_radians` (#43)
|
65
|
+
|
66
|
+
Behaviour not changed.
|
67
|
+
|
68
|
+
### `Angle::as_degrees` renamed into `Angle::from_degrees` (#43)
|
69
|
+
|
70
|
+
Behaviour not changed.
|
71
|
+
|
72
|
+
### `Angle::as_hours` renamed into `Angle::from_hours` (#43)
|
73
|
+
|
74
|
+
Behaviour not changed.
|
75
|
+
|
76
|
+
### `Angle::as_dms` renamed into `Angle::from_dms` (#43)
|
77
|
+
|
78
|
+
Behaviour not changed.
|
79
|
+
|
80
|
+
### `Angle::as_hms` renamed into `Angle::from_hms` (#43)
|
81
|
+
|
82
|
+
Behaviour not changed.
|
83
|
+
|
10
84
|
## Upgrading from 0.1.0 to 0.2.0
|
11
85
|
|
12
86
|
### `Observer` class added (#29)
|
data/lib/astronoby/aberration.rb
CHANGED
@@ -2,6 +2,8 @@
|
|
2
2
|
|
3
3
|
module Astronoby
|
4
4
|
class Aberration
|
5
|
+
MAXIMUM_SHIFT = Angle.from_degrees(20.5)
|
6
|
+
|
5
7
|
def self.for_ecliptic_coordinates(coordinates:, epoch:)
|
6
8
|
new(coordinates, epoch).apply
|
7
9
|
end
|
@@ -17,16 +19,16 @@ module Astronoby
|
|
17
19
|
# Edition: Cambridge University Press
|
18
20
|
# Chapter: 36 - Aberration
|
19
21
|
def apply
|
20
|
-
delta_longitude = Angle.
|
21
|
-
-
|
22
|
+
delta_longitude = Angle.from_degrees(
|
23
|
+
-MAXIMUM_SHIFT.degrees * (
|
22
24
|
sun_longitude - @coordinates.longitude
|
23
|
-
).cos / @coordinates.latitude.cos /
|
25
|
+
).cos / @coordinates.latitude.cos / Constants::SECONDS_PER_DEGREE
|
24
26
|
)
|
25
27
|
|
26
|
-
delta_latitude = Angle.
|
27
|
-
-
|
28
|
+
delta_latitude = Angle.from_degrees(
|
29
|
+
-MAXIMUM_SHIFT.degrees *
|
28
30
|
(sun_longitude - @coordinates.longitude).sin *
|
29
|
-
@coordinates.latitude.sin /
|
31
|
+
@coordinates.latitude.sin / Constants::SECONDS_PER_DEGREE
|
30
32
|
)
|
31
33
|
|
32
34
|
Coordinates::Ecliptic.new(
|
@@ -36,7 +38,10 @@ module Astronoby
|
|
36
38
|
end
|
37
39
|
|
38
40
|
def sun_longitude
|
39
|
-
@_sun_longitude ||= Sun
|
41
|
+
@_sun_longitude ||= Sun
|
42
|
+
.new(time: Epoch.to_utc(@epoch))
|
43
|
+
.true_ecliptic_coordinates
|
44
|
+
.longitude
|
40
45
|
end
|
41
46
|
end
|
42
47
|
end
|
data/lib/astronoby/angle.rb
CHANGED
@@ -1,23 +1,10 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require "bigdecimal/math"
|
4
|
-
|
5
3
|
module Astronoby
|
6
4
|
class Angle
|
7
5
|
include Comparable
|
8
6
|
|
9
|
-
|
10
|
-
PI = BigMath.PI(PRECISION)
|
11
|
-
PI_IN_DEGREES = BigDecimal("180")
|
12
|
-
|
13
|
-
FULL_CIRCLE_IN_RADIANS = (2 * PI)
|
14
|
-
|
15
|
-
RADIAN_PER_HOUR = PI / BigDecimal("12")
|
16
|
-
MINUTES_PER_DEGREE = BigDecimal("60")
|
17
|
-
MINUTES_PER_HOUR = BigDecimal("60")
|
18
|
-
SECONDS_PER_MINUTE = BigDecimal("60")
|
19
|
-
SECONDS_PER_HOUR = MINUTES_PER_HOUR * SECONDS_PER_MINUTE
|
20
|
-
|
7
|
+
MIN_PRECISION = 10
|
21
8
|
FORMATS = %i[dms hms].freeze
|
22
9
|
|
23
10
|
class << self
|
@@ -25,73 +12,77 @@ module Astronoby
|
|
25
12
|
new(0)
|
26
13
|
end
|
27
14
|
|
28
|
-
def
|
29
|
-
normalized_radians = radians.remainder(
|
15
|
+
def from_radians(radians)
|
16
|
+
normalized_radians = radians.remainder(Constants::RADIANS_PER_CIRCLE)
|
30
17
|
new(normalized_radians)
|
31
18
|
end
|
32
19
|
|
33
|
-
def
|
34
|
-
radians = degrees / PI_IN_DEGREES * PI
|
35
|
-
|
20
|
+
def from_degrees(degrees)
|
21
|
+
radians = degrees / Constants::PI_IN_DEGREES * Math::PI
|
22
|
+
from_radians(radians)
|
36
23
|
end
|
37
24
|
|
38
|
-
def
|
39
|
-
radians = hours * RADIAN_PER_HOUR
|
40
|
-
|
25
|
+
def from_hours(hours)
|
26
|
+
radians = hours * Constants::RADIAN_PER_HOUR
|
27
|
+
from_radians(radians)
|
41
28
|
end
|
42
29
|
|
43
|
-
def
|
44
|
-
hours = hour +
|
45
|
-
|
30
|
+
def from_hms(hour, minute, second)
|
31
|
+
hours = hour +
|
32
|
+
minute / Constants::MINUTES_PER_HOUR +
|
33
|
+
second / Constants::SECONDS_PER_HOUR
|
34
|
+
from_hours(hours)
|
46
35
|
end
|
47
36
|
|
48
|
-
def
|
37
|
+
def from_dms(degree, minute, second)
|
49
38
|
sign = degree.negative? ? -1 : 1
|
50
|
-
degrees = degree.abs +
|
51
|
-
|
39
|
+
degrees = degree.abs +
|
40
|
+
minute / Constants::MINUTES_PER_HOUR +
|
41
|
+
second / Constants::SECONDS_PER_HOUR
|
42
|
+
from_degrees(sign * degrees)
|
52
43
|
end
|
53
44
|
|
54
45
|
def asin(ratio)
|
55
46
|
radians = Math.asin(ratio)
|
56
|
-
|
47
|
+
from_radians(radians)
|
57
48
|
end
|
58
49
|
|
59
50
|
def acos(ratio)
|
60
51
|
radians = Math.acos(ratio)
|
61
|
-
|
52
|
+
from_radians(radians)
|
62
53
|
end
|
63
54
|
|
64
55
|
def atan(ratio)
|
65
56
|
radians = Math.atan(ratio)
|
66
|
-
|
57
|
+
from_radians(radians)
|
67
58
|
end
|
68
59
|
end
|
69
60
|
|
70
61
|
attr_reader :radians
|
71
62
|
|
72
63
|
def initialize(radians)
|
73
|
-
@radians =
|
74
|
-
BigDecimal(radians)
|
75
|
-
else
|
76
|
-
BigDecimal(radians, PRECISION)
|
77
|
-
end
|
64
|
+
@radians = radians
|
78
65
|
freeze
|
79
66
|
end
|
80
67
|
|
81
68
|
def degrees
|
82
|
-
@radians * PI_IN_DEGREES / PI
|
69
|
+
@radians * Constants::PI_IN_DEGREES / Math::PI
|
83
70
|
end
|
84
71
|
|
85
72
|
def hours
|
86
|
-
@radians / RADIAN_PER_HOUR
|
73
|
+
@radians / Constants::RADIAN_PER_HOUR
|
87
74
|
end
|
88
75
|
|
89
76
|
def +(other)
|
90
|
-
self.class.
|
77
|
+
self.class.from_radians(radians + other.radians)
|
91
78
|
end
|
92
79
|
|
93
80
|
def -(other)
|
94
|
-
self.class.
|
81
|
+
self.class.from_radians(@radians - other.radians)
|
82
|
+
end
|
83
|
+
|
84
|
+
def -@
|
85
|
+
self.class.from_radians(-@radians)
|
95
86
|
end
|
96
87
|
|
97
88
|
def sin
|
@@ -118,20 +109,16 @@ module Astronoby
|
|
118
109
|
radians.zero?
|
119
110
|
end
|
120
111
|
|
121
|
-
def ==(other)
|
122
|
-
other.is_a?(self.class) && radians == other.radians
|
123
|
-
end
|
124
|
-
alias_method :eql?, :==
|
125
|
-
|
126
112
|
def hash
|
127
113
|
[radians, self.class].hash
|
128
114
|
end
|
129
115
|
|
130
116
|
def <=>(other)
|
131
|
-
return
|
117
|
+
return unless other.is_a?(self.class)
|
132
118
|
|
133
119
|
radians <=> other.radians
|
134
120
|
end
|
121
|
+
alias_method :eql?, :==
|
135
122
|
|
136
123
|
def str(format)
|
137
124
|
case format
|
@@ -148,31 +135,32 @@ module Astronoby
|
|
148
135
|
sign = deg.negative? ? "-" : "+"
|
149
136
|
absolute_degrees = deg.abs
|
150
137
|
degrees = absolute_degrees.floor
|
151
|
-
decimal_minutes = MINUTES_PER_DEGREE *
|
138
|
+
decimal_minutes = Constants::MINUTES_PER_DEGREE *
|
139
|
+
(absolute_degrees - degrees)
|
152
140
|
absolute_decimal_minutes = (
|
153
|
-
MINUTES_PER_DEGREE * (absolute_degrees - degrees)
|
141
|
+
Constants::MINUTES_PER_DEGREE * (absolute_degrees - degrees)
|
154
142
|
).abs
|
155
143
|
minutes = decimal_minutes.floor
|
156
|
-
seconds = SECONDS_PER_MINUTE * (
|
144
|
+
seconds = Constants::SECONDS_PER_MINUTE * (
|
157
145
|
absolute_decimal_minutes - absolute_decimal_minutes.floor
|
158
146
|
)
|
159
147
|
|
160
|
-
Dms.new(sign, degrees, minutes, seconds.
|
148
|
+
Dms.new(sign, degrees, minutes, seconds.floor(4))
|
161
149
|
end
|
162
150
|
|
163
151
|
def to_hms(hrs)
|
164
152
|
absolute_hours = hrs.abs
|
165
153
|
hours = absolute_hours.floor
|
166
|
-
decimal_minutes = MINUTES_PER_HOUR * (absolute_hours - hours)
|
154
|
+
decimal_minutes = Constants::MINUTES_PER_HOUR * (absolute_hours - hours)
|
167
155
|
absolute_decimal_minutes = (
|
168
|
-
MINUTES_PER_HOUR * (absolute_hours - hours)
|
156
|
+
Constants::MINUTES_PER_HOUR * (absolute_hours - hours)
|
169
157
|
).abs
|
170
158
|
minutes = decimal_minutes.floor
|
171
|
-
seconds = SECONDS_PER_MINUTE * (
|
159
|
+
seconds = Constants::SECONDS_PER_MINUTE * (
|
172
160
|
absolute_decimal_minutes - absolute_decimal_minutes.floor
|
173
161
|
)
|
174
162
|
|
175
|
-
Hms.new(hours, minutes, seconds.
|
163
|
+
Hms.new(hours, minutes, seconds.floor(4))
|
176
164
|
end
|
177
165
|
end
|
178
166
|
end
|