Skip to content

Commit 31b3e9d

Browse files
committed
Add Angle#positive?, Angle#negative? and Angle#zero?
1 parent f335827 commit 31b3e9d

File tree

3 files changed

+56
-2
lines changed

3 files changed

+56
-2
lines changed

lib/astronoby/angle.rb

+12
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,18 @@ def tan
100100
Math.tan(radians)
101101
end
102102

103+
def positive?
104+
radians > 0
105+
end
106+
107+
def negative?
108+
radians < 0
109+
end
110+
111+
def zero?
112+
radians.zero?
113+
end
114+
103115
def str(format)
104116
case format
105117
when :dms then to_dms(degrees).format

lib/astronoby/util/trigonometry.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ class << self
1212
# Edition: MIT Press
1313
# Chapter: 4 - Orbits and Coordinate Systems
1414
def adjustement_for_arctangent(y, x, angle)
15-
return angle if y.degrees.positive? && x.degrees.positive?
15+
return angle if y.positive? && x.positive?
1616

17-
if y.degrees.negative? && x.degrees.positive?
17+
if y.negative? && x.positive?
1818
return Angle.as_degrees(angle.degrees + 360)
1919
end
2020

spec/astronoby/angle_spec.rb

+42
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,48 @@
193193
end
194194
end
195195

196+
describe "#positive?" do
197+
it "returns true when the angle is positive" do
198+
expect(described_class.as_degrees(90).positive?).to be true
199+
end
200+
201+
it "returns false when the angle is negative" do
202+
expect(described_class.as_degrees(-90).positive?).to be false
203+
end
204+
205+
it "returns famse when the angle has a zero value" do
206+
expect(described_class.as_degrees(0).positive?).to be false
207+
end
208+
end
209+
210+
describe "#negative?" do
211+
it "returns false when the angle is positive" do
212+
expect(described_class.as_degrees(90).negative?).to be false
213+
end
214+
215+
it "returns true when the angle is negative" do
216+
expect(described_class.as_degrees(-90).negative?).to be true
217+
end
218+
219+
it "returns false when the angle has a zero value" do
220+
expect(described_class.as_degrees(0).negative?).to be false
221+
end
222+
end
223+
224+
describe "#zero?" do
225+
it "returns false when the angle is positive" do
226+
expect(described_class.as_degrees(90).zero?).to be false
227+
end
228+
229+
it "returns false when the angle is negative" do
230+
expect(described_class.as_degrees(-90).zero?).to be false
231+
end
232+
233+
it "returns true when the angle has a zero value" do
234+
expect(described_class.as_degrees(0).zero?).to be true
235+
end
236+
end
237+
196238
describe "#str" do
197239
it "returns a String" do
198240
angle = described_class.as_degrees(180)

0 commit comments

Comments
 (0)