Skip to content

Commit

Permalink
Add Angle#-
Browse files Browse the repository at this point in the history
  • Loading branch information
rhannequin committed Feb 20, 2024
1 parent 82c8c63 commit 6b689f1
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 3 deletions.
4 changes: 2 additions & 2 deletions lib/astronoby/aberration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ def apply
delta_longitude = Astronoby::Angle.as_degrees(
-20.5 *
Math.cos(
@sun_longitude.radians - @coordinates.longitude.radians
(@sun_longitude - @coordinates.longitude).radians
) / Math.cos(@coordinates.latitude.radians) / 3600
)

delta_latitude = Astronoby::Angle.as_degrees(
-20.5 *
Math.sin(@sun_longitude.radians - @coordinates.longitude.radians) *
Math.sin((@sun_longitude - @coordinates.longitude).radians) *
Math.sin(@coordinates.latitude.radians) / 3600
)

Expand Down
4 changes: 4 additions & 0 deletions lib/astronoby/angle.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ def +(other)
self.class.as_radians(radians + other.radians)
end

def -(other)
self.class.as_radians(@radians - other.radians)
end

def str(format)
case format
when :dms then to_dms(degrees).format
Expand Down
2 changes: 1 addition & 1 deletion lib/astronoby/bodies/sun.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def horizontal_coordinates(latitude:, longitude:)

def mean_anomaly
Angle.as_degrees(
(longitude_at_base_epoch.degrees - longitude_at_perigee.degrees) % 360
(longitude_at_base_epoch - longitude_at_perigee).degrees % 360
)
end

Expand Down
11 changes: 11 additions & 0 deletions spec/astronoby/angle_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,17 @@
end
end

describe "#-" do
it "returns a new angle with a value of the two angles substracted" do
angle_1 = described_class.as_radians(described_class::PI)
angle_2 = described_class.as_degrees(45)

new_angle = angle_1 - angle_2

expect(new_angle.degrees).to eq 135
end
end

describe "#str" do
it "returns a String" do
angle = described_class.as_degrees(180)
Expand Down

0 comments on commit 6b689f1

Please sign in to comment.