Class: Geometry::ThreePointArc

Inherits:
Arc
  • Object
show all
Defined in:
lib/geometry/arc.rb

Instance Attribute Summary collapse

Attributes collapse

Instance Method Summary collapse

Methods inherited from Arc

new

Methods included from ClusterFactory

included

Constructor Details

#initialize(center_point, start_point, end_point) ⇒ ThreePointArc

Contruct a new Arc given center, start and end Points

Always assumes that the {Arc} is counter-clockwise. Reverse the order
of the start and end points to get an {Arc} that goes around the other way.

Parameters:

Raises:

  • (ArgumentError)


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

#centerObject (readonly)

Returns the value of attribute center.



78
79
80
# File 'lib/geometry/arc.rb', line 78

def center
  @center
end

#endObject (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

#startObject (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_angleObject



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

#maxPoint

Returns The upper-right corner of the bounding rectangle that encloses the Path.

Returns:

  • (Point)

    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

#minPoint

Returns The lower-left corner of the bounding rectangle that encloses the Path.

Returns:

  • (Point)

    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

#minmaxArray<Point>

Returns The lower-left and upper-right corners of the enclosing bounding rectangle.

Returns:

  • (Array<Point>)

    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

#radiusObject



154
155
156
# File 'lib/geometry/arc.rb', line 154

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

#start_angleObject



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