class PerfectShape::Circle
Constants
- MESSAGE_RADIUS_X_AND_RADIUS_Y_AND_RADIUS_NOT_EQUAL
- MESSAGE_WIDTH_AND_HEIGHT_AND_DIAMETER_NOT_EQUAL
Public Class Methods
new(x: 0, y: 0, width: nil, height: nil, diameter: nil, center_x: nil, center_y: nil, radius_x: nil, radius_y: nil, radius: nil)
click to toggle source
Calls superclass method
# 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
Public Instance Methods
diameter()
click to toggle source
# File lib/perfect_shape/circle.rb, line 43 def diameter @radius ? @radius * BigDecimal('2.0') : @diameter end
diameter=(value)
click to toggle source
Sets length, normalizing to BigDecimal
# 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)
click to toggle source
Calls superclass method
# 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()
click to toggle source
# File lib/perfect_shape/circle.rb, line 47 def radius @diameter ? @diameter / BigDecimal('2.0') : @radius end
radius=(value)
click to toggle source
Sets radius, normalizing to BigDecimal
# 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)
click to toggle source
Calls superclass method
# 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)
click to toggle source
Calls superclass method
# 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)
click to toggle source
Calls superclass method
# 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