Class: Geometry::Circle
- Inherits:
-
Object
- Object
- Geometry::Circle
- Includes:
- ClusterFactory
- Defined in:
- lib/geometry/circle.rb
Overview
Direct Known Subclasses
Accessors collapse
- #closed? ⇒ Boolean
- #diameter ⇒ Object readonly
Instance Attribute Summary collapse
-
#center ⇒ Point
readonly
The Circle‘s center point.
-
#radius ⇒ Number
readonly
The Circle‘s radius.
Accessors collapse
-
#bounds ⇒ Rectangle
The smallest axis-aligned Rectangle that bounds the receiver.
-
#max ⇒ Point
The upper right corner of the bounding Rectangle.
-
#min ⇒ Point
The lower left corner of the bounding Rectangle.
-
#minmax ⇒ Array<Point>
The lower left and upper right corners of the bounding Rectangle.
Class Method Summary collapse
Instance Method Summary collapse
- #eql?(other) ⇒ Boolean (also: #==)
-
#initialize(center, radius) ⇒ Circle
constructor
Construct a new Circle from a centerpoint and radius.
Methods included from ClusterFactory
Constructor Details
#initialize(center, radius) ⇒ Circle
Construct a new Geometry::Circle from a centerpoint and radius
58 59 60 61 |
# File 'lib/geometry/circle.rb', line 58 def initialize(center, radius) @center = Point[center] @radius = radius end |
Instance Attribute Details
#center ⇒ Point (readonly)
Returns The Geometry::Circle‘s center point.
20 21 22 |
# File 'lib/geometry/circle.rb', line 20 def center @center end |
#closed? ⇒ Boolean
76 77 78 |
# File 'lib/geometry/circle.rb', line 76 def closed? true end |
#diameter ⇒ Object (readonly)
82 83 84 |
# File 'lib/geometry/circle.rb', line 82 def diameter @radius*2 end |
#radius ⇒ Number (readonly)
Returns The Geometry::Circle‘s radius.
23 24 25 |
# File 'lib/geometry/circle.rb', line 23 def radius @radius end |
Class Method Details
.new(center, radius) ⇒ Object .new(center, radius) ⇒ Object .new(center, diameter) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/geometry/circle.rb', line 37 def self.new(*args, &block) , args = args.partition {|a| a.is_a? Hash} = .reduce({}, :merge) center, radius = args[0..1] center ||= ([:center] || PointZero.new) radius ||= [:radius] if radius self.allocate.tap {|circle| circle.send :initialize, center, radius, &block } elsif .has_key?(:diameter) CenterDiameterCircle.new center, [:diameter], &block else raise ArgumentError, "Circle.new requires a radius or a diameter" end end |
Instance Method Details
#bounds ⇒ Rectangle
Returns The smallest axis-aligned Rectangle that bounds the receiver.
70 71 72 |
# File 'lib/geometry/circle.rb', line 70 def bounds return Rectangle.new(self.min, self.max) end |
#eql?(other) ⇒ Boolean Also known as: ==
63 64 65 |
# File 'lib/geometry/circle.rb', line 63 def eql?(other) (self.center == other.center) && (self.radius == other.radius) end |
#max ⇒ Point
Returns The upper right corner of the bounding Rectangle.
87 88 89 |
# File 'lib/geometry/circle.rb', line 87 def max @center+radius end |