Class: PerfectShape::Circle
- Defined in:
- lib/perfect_shape/circle.rb
Constant Summary collapse
- MESSAGE_WIDTH_AND_HEIGHT_AND_DIAMETER_NOT_EQUAL =
'Circle width, height, and diameter must all be equal if more than one is specified; or otherwise keep only one of them in arguments!'
- MESSAGE_RADIUS_X_AND_RADIUS_Y_AND_RADIUS_NOT_EQUAL =
'Circle radius_x, radius_y, and radius must all be equal if more than one is specified; or otherwise keep only one of them in arguments!'
Constants inherited from Ellipse
Ellipse::MESSAGE_CANNOT_UPDATE_ATTRIUBTE
Constants inherited from Arc
Arc::DEFAULT_OUTLINE_RADIUS, Arc::TYPES
Instance Attribute Summary
Attributes inherited from Arc
Attributes included from RectangularShape
Attributes included from PointLocation
Instance Method Summary collapse
- #diameter ⇒ Object
-
#diameter=(value) ⇒ Object
Sets length, normalizing to BigDecimal.
- #height=(value) ⇒ Object
-
#initialize(x: 0, y: 0, width: nil, height: nil, diameter: nil, center_x: nil, center_y: nil, radius_x: nil, radius_y: nil, radius: nil) ⇒ Circle
constructor
A new instance of Circle.
- #radius ⇒ Object
-
#radius=(value) ⇒ Object
Sets radius, normalizing to BigDecimal.
- #radius_x=(value) ⇒ Object
- #radius_y=(value) ⇒ Object
- #width=(value) ⇒ Object
Methods inherited from Ellipse
#contain?, #extent=, #start=, #type=
Methods inherited from Arc
#btan, #center_x, #center_x=, #center_y, #center_y=, #contain?, #contain_angle?, #end_point, #height, #intersect?, #radius_x, #radius_y, #start_point, #to_path_shapes, #width, #x, #x=, #y, #y=
Methods included from RectangularShape
Methods included from PointLocation
Methods inherited from Shape
#==, #bounding_box, #center_point, #center_x, #center_y, #contain?, #height, #max_x, #max_y, #min_x, #min_y, #width
Constructor Details
#initialize(x: 0, y: 0, width: nil, height: nil, diameter: nil, center_x: nil, center_y: nil, radius_x: nil, radius_y: nil, radius: nil) ⇒ Circle
Returns a new instance of Circle.
29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/perfect_shape/circle.rb', line 29 def initialize(x: 0, y: 0, width: nil, height: nil, diameter: nil, center_x: nil, center_y: nil, radius_x: nil, radius_y: nil, radius: nil) raise MESSAGE_WIDTH_AND_HEIGHT_AND_DIAMETER_NOT_EQUAL if (diameter && width && diameter != width) || (diameter && height && diameter != height) || (width && height && width != height) raise MESSAGE_RADIUS_X_AND_RADIUS_Y_AND_RADIUS_NOT_EQUAL if (radius && radius_x && radius != radius_x) || (radius && radius_y && radius != radius_y) || (radius_x && radius_y && radius_x != radius_y) if center_x && center_y && (radius || radius_x || radius_y) radius ||= radius_x || radius_y self.radius = radius super(center_x: center_x, center_y: center_y, radius_x: self.radius_x, radius_y: self.radius_y) else diameter ||= width || height || 1 self.diameter = diameter super(x: x, y: y, width: self.width, height: self.height) end end |
Instance Method Details
#diameter ⇒ Object
43 44 45 |
# File 'lib/perfect_shape/circle.rb', line 43 def diameter @radius ? @radius * BigDecimal('2.0') : @diameter end |
#diameter=(value) ⇒ Object
Sets length, normalizing to BigDecimal
52 53 54 55 56 57 |
# File 'lib/perfect_shape/circle.rb', line 52 def diameter=(value) @diameter = BigDecimal(value.to_s) @radius = nil self.width = @diameter unless width == @diameter self.height = @diameter unless height == @diameter end |
#height=(value) ⇒ Object
73 74 75 76 77 |
# File 'lib/perfect_shape/circle.rb', line 73 def height=(value) super self.diameter = @height unless diameter == @height self.width = @height unless width == @height end |
#radius ⇒ Object
47 48 49 |
# File 'lib/perfect_shape/circle.rb', line 47 def radius @diameter ? @diameter / BigDecimal('2.0') : @radius end |
#radius=(value) ⇒ Object
Sets radius, normalizing to BigDecimal
60 61 62 63 64 65 |
# File 'lib/perfect_shape/circle.rb', line 60 def radius=(value) @radius = BigDecimal(value.to_s) @diameter = nil self.radius_x = @radius unless @width == @radius self.radius_y = @radius unless @height == @radius end |
#radius_x=(value) ⇒ Object
79 80 81 82 83 |
# File 'lib/perfect_shape/circle.rb', line 79 def radius_x=(value) super self.radius = @radius_x unless radius == @radius_x self.radius_y = @radius_x unless radius_y == @radius_x end |
#radius_y=(value) ⇒ Object
85 86 87 88 89 |
# File 'lib/perfect_shape/circle.rb', line 85 def radius_y=(value) super self.radius = @radius_y unless radius == @radius_y self.radius_x = @radius_y unless radius_x == @radius_y end |
#width=(value) ⇒ Object
67 68 69 70 71 |
# File 'lib/perfect_shape/circle.rb', line 67 def width=(value) super self.diameter = @width unless diameter == @width self.height = @width unless height == @width end |