Skip to content

Commit

Permalink
Added end_angle, radius, and start_angle to ThreePointArc
Browse files Browse the repository at this point in the history
  • Loading branch information
bfoz committed Apr 14, 2016
1 parent bdb15ad commit 4e17e62
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
23 changes: 22 additions & 1 deletion lib/geometry/arc.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,15 @@ class Arc
include ClusterFactory

attr_reader :center

# @return [Number] the radius of the {Arc}
attr_reader :radius
attr_reader :start_angle, :end_angle

# @return [Number] the starting angle of the {Arc} as radians from the x-axis
attr_reader :start_angle

# @return [Number] the ending angle of the {Arc} as radians from the x-axis
attr_reader :end_angle

# @overload new(center, start, end)
# Create a new {Arc} given center, start and end {Point}s
Expand Down Expand Up @@ -90,5 +97,19 @@ def initialize(center_point, start_point, end_point)
# The end point of the {Arc}
# @return [Point]
alias :last :end

def end_angle
a = (self.end - self.center)
Math.atan2(a.y, a.x)
end

def radius
(self.start - self.center).magnitude
end

def start_angle
a = (self.start - self.center)
Math.atan2(a.y, a.x)
end
end
end
17 changes: 17 additions & 0 deletions test/geometry/arc.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,20 @@
end
end
end

describe Geometry::ThreePointArc do
it 'must have an ending angle' do
arc = Geometry::ThreePointArc.new([0,0], [1,0], [0,1])
arc.end_angle.must_equal Math::PI/2
end

it 'must have a radius' do
arc = Geometry::ThreePointArc.new([0,0], [1,0], [0,1])
arc.radius.must_equal 1
end

it 'must have an starting angle' do
arc = Geometry::ThreePointArc.new([0,0], [1,0], [0,1])
arc.start_angle.must_equal 0
end
end

0 comments on commit 4e17e62

Please sign in to comment.