Skip to content

Commit 532094e

Browse files
committed
Add Angle#+
1 parent 5449e79 commit 532094e

File tree

6 files changed

+31
-24
lines changed

6 files changed

+31
-24
lines changed

lib/astronoby/aberration.rb

+2-6
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,8 @@ def apply
3333
)
3434

3535
Astronoby::Coordinates::Ecliptic.new(
36-
latitude: Astronoby::Angle.as_degrees(
37-
@coordinates.latitude.degrees + delta_latitude.degrees
38-
),
39-
longitude: Astronoby::Angle.as_degrees(
40-
@coordinates.longitude.degrees + delta_longitude.degrees
41-
)
36+
latitude: @coordinates.latitude + delta_latitude,
37+
longitude: @coordinates.longitude + delta_longitude
4238
)
4339
end
4440
end

lib/astronoby/angle.rb

+15-9
Original file line numberDiff line numberDiff line change
@@ -47,24 +47,30 @@ def as_dms(degree, minute, second)
4747
end
4848
end
4949

50+
attr_reader :value
51+
52+
def initialize(value)
53+
@value = if value.is_a?(Integer) || value.is_a?(BigDecimal)
54+
BigDecimal(value)
55+
else
56+
BigDecimal(value, PRECISION)
57+
end
58+
end
59+
5060
def radians
51-
@angle
61+
@value
5262
end
5363

5464
def degrees
55-
@angle * PI_IN_DEGREES / PI
65+
@value * PI_IN_DEGREES / PI
5666
end
5767

5868
def hours
59-
@angle / RADIAN_PER_HOUR
69+
@value / RADIAN_PER_HOUR
6070
end
6171

62-
def initialize(angle)
63-
@angle = if angle.is_a?(Integer) || angle.is_a?(BigDecimal)
64-
BigDecimal(angle)
65-
else
66-
BigDecimal(angle, PRECISION)
67-
end
72+
def +(other)
73+
self.class.new(@value + other.value)
6874
end
6975

7076
def str(format)

lib/astronoby/bodies/sun.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ def ecliptic_coordinates
1616
Coordinates::Ecliptic.new(
1717
latitude: Angle.zero,
1818
longitude: Angle.as_degrees(
19-
(true_anomaly.degrees + longitude_at_perigee.degrees) % 360
19+
(true_anomaly + longitude_at_perigee).degrees % 360
2020
)
2121
)
2222
end

lib/astronoby/refraction.rb

+1-3
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,7 @@ def refract
5454

5555
Astronoby::Coordinates::Horizontal.new(
5656
azimuth: @coordinates.azimuth,
57-
altitude: Astronoby::Angle.as_degrees(
58-
@coordinates.altitude.degrees + refraction_angle.degrees
59-
),
57+
altitude: @coordinates.altitude + refraction_angle,
6058
latitude: @coordinates.latitude,
6159
longitude: @coordinates.longitude
6260
)

lib/astronoby/true_obliquity.rb

+1-5
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,7 @@ def self.for_epoch(epoch)
1010
mean_obliquity = Astronoby::MeanObliquity.for_epoch(epoch)
1111
nutation = Astronoby::Nutation.for_obliquity_of_the_ecliptic(epoch: epoch)
1212

13-
new(
14-
Astronoby::Angle.as_degrees(
15-
mean_obliquity.value.degrees + nutation.degrees
16-
)
17-
)
13+
new(mean_obliquity.value + nutation)
1814
end
1915

2016
def value

spec/astronoby/angle_spec.rb

+11
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,17 @@
9393
end
9494
end
9595

96+
describe "#+" do
97+
it "returns a new angle with a value of the two angles added" do
98+
angle_1 = described_class.as_radians(described_class::PI)
99+
angle_2 = described_class.as_degrees(45)
100+
101+
new_angle = angle_1 + angle_2
102+
103+
expect(new_angle.degrees).to eq 225
104+
end
105+
end
106+
96107
describe "#str" do
97108
it "returns a String" do
98109
angle = described_class.as_degrees(180)

0 commit comments

Comments
 (0)