Class: Geometry::ThreePointArc
Instance Attribute Summary collapse
-
#center ⇒ Object
readonly
Returns the value of attribute center.
-
#end ⇒ Object
(also: #last)
readonly
Returns the value of attribute end.
-
#start ⇒ Object
(also: #first)
readonly
Returns the value of attribute start.
Attributes collapse
- #end_angle ⇒ Object
-
#max ⇒ Point
The upper-right corner of the bounding rectangle that encloses the Path.
-
#min ⇒ Point
The lower-left corner of the bounding rectangle that encloses the Path.
-
#minmax ⇒ Array<Point>
The lower-left and upper-right corners of the enclosing bounding rectangle.
- #radius ⇒ Object
- #start_angle ⇒ Object
Instance Method Summary collapse
Methods inherited from Arc
Methods included from ClusterFactory
Constructor Details
#initialize(center_point, start_point, end_point) ⇒ ThreePointArc
88 89 90 91 |
# File 'lib/geometry/arc.rb', line 88 def initialize(center_point, start_point, end_point) @center, @start, @end = [center_point, start_point, end_point].map {|p| Point[p]} raise ArgumentError unless [@center, @start, @end].all? {|p| p.is_a?(Point)} end |
Instance Attribute Details
#center ⇒ Object (readonly)
Returns the value of attribute center.
78 79 80 |
# File 'lib/geometry/arc.rb', line 78 def center @center end |
#end ⇒ Object (readonly) Also known as: last
Returns the value of attribute end.
79 80 81 |
# File 'lib/geometry/arc.rb', line 79 def end @end end |
#start ⇒ Object (readonly) Also known as: first
Returns the value of attribute start.
79 80 81 |
# File 'lib/geometry/arc.rb', line 79 def start @start end |
Instance Method Details
#==(other) ⇒ Object
101 102 103 104 105 106 107 |
# File 'lib/geometry/arc.rb', line 101 def ==(other) if other.is_a?(ThreePointArc) (self.center == other.center) && (self.end == other.end) && (self.start == other.start) else super other end end |
#end_angle ⇒ Object
149 150 151 152 |
# File 'lib/geometry/arc.rb', line 149 def end_angle a = (self.end - self.center) Math.atan2(a.y, a.x) end |
#max ⇒ Point
Returns The upper-right corner of the bounding rectangle that encloses the Path.
112 113 114 |
# File 'lib/geometry/arc.rb', line 112 def max minmax.last end |
#min ⇒ Point
Returns The lower-left corner of the bounding rectangle that encloses the Path.
117 118 119 |
# File 'lib/geometry/arc.rb', line 117 def min minmax.first end |
#minmax ⇒ Array<Point>
Returns The lower-left and upper-right corners of the enclosing bounding rectangle.
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 |
# File 'lib/geometry/arc.rb', line 122 def minmax a = [self.start, self.end] quadrants = a.map(&:quadrant) # If the Arc spans more than one quadrant, then it must cross at # least one axis. Each axis-crossing is a potential extrema. if quadrants.first != quadrants.last range = (quadrants.first...quadrants.last) # If the Arc crosses the X axis... if quadrants.first > quadrants.last range = (quadrants.first..4).to_a + (1...quadrants.last).to_a end a = range.map do |q| case q when 1 then self.center + Point[0,radius] when 2 then self.center + Point[-radius, 0] when 3 then self.center + Point[0,-radius] when 4 then self.center + Point[radius,0] end end.push(*a) a.reduce([a.first, a.first]) {|memo, e| [memo.first.min(e), memo.last.max(e)] } else [a.first.min(a.last), a.first.max(a.last)] end end |
#radius ⇒ Object
154 155 156 |
# File 'lib/geometry/arc.rb', line 154 def radius (self.start - self.center).magnitude end |
#start_angle ⇒ Object
158 159 160 161 |
# File 'lib/geometry/arc.rb', line 158 def start_angle a = (self.start - self.center) Math.atan2(a.y, a.x) end |