Class: Svgcode::SVG::Circle
- Inherits:
-
BaseCommand
- Object
- BaseCommand
- Svgcode::SVG::Circle
- Defined in:
- lib/svgcode/svg/circle.rb
Constant Summary
Constants inherited from BaseCommand
Instance Attribute Summary collapse
-
#centre_x ⇒ Object
readonly
Returns the value of attribute centre_x.
-
#centre_y ⇒ Object
readonly
Returns the value of attribute centre_y.
-
#radius ⇒ Object
readonly
Returns the value of attribute radius.
Attributes inherited from BaseCommand
Instance Method Summary collapse
- #apply_transforms!(transforms) ⇒ Object
- #divide_points_by!(amount) ⇒ Object
-
#initialize(element_or_x, y = nil, r = nil) ⇒ Circle
constructor
A new instance of Circle.
- #start_x ⇒ Object
Methods inherited from BaseCommand
#==, #absolute!, #absolute?, #flip_points_y!, #name_str, name_str, #negate_points_y, #negate_points_y!, #relative?, #to_s
Constructor Details
#initialize(element_or_x, y = nil, r = nil) ⇒ Circle
Returns a new instance of Circle.
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/svgcode/svg/circle.rb', line 11 def initialize(element_or_x, y = nil, r = nil) @name = :circle @absolute = true if element_or_x.is_a?(Nokogiri::XML::Element) @centre_x = Utility.x_to_f(element_or_x.attributes['cx'].value) @centre_y = Utility.x_to_f(element_or_x.attributes['cy'].value) @radius = Utility.x_to_f(element_or_x.attributes['r'].value) else @centre_x = Utility.x_to_f(element_or_x) @centre_y = Utility.x_to_f(y) @radius = Utility.x_to_f(r) end @points = [ Point.new(@centre_x, @centre_y) ] end |
Instance Attribute Details
#centre_x ⇒ Object (readonly)
Returns the value of attribute centre_x.
9 10 11 |
# File 'lib/svgcode/svg/circle.rb', line 9 def centre_x @centre_x end |
#centre_y ⇒ Object (readonly)
Returns the value of attribute centre_y.
9 10 11 |
# File 'lib/svgcode/svg/circle.rb', line 9 def centre_y @centre_y end |
#radius ⇒ Object (readonly)
Returns the value of attribute radius.
9 10 11 |
# File 'lib/svgcode/svg/circle.rb', line 9 def radius @radius end |
Instance Method Details
#apply_transforms!(transforms) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/svgcode/svg/circle.rb', line 32 def apply_transforms!(transforms) super(transforms) transforms.reverse.each do |transform| r_start = transform.apply(Point.new(start_x, 0)) r_end = transform.apply(Point.new(@centre_x, 0)) @centre_x = r_end.x @radius = @centre_x - r_start.x end @centre_x = @points.first.x @centre_y = @points.first.y end |
#divide_points_by!(amount) ⇒ Object
46 47 48 49 50 51 |
# File 'lib/svgcode/svg/circle.rb', line 46 def divide_points_by!(amount) super(amount) @centre_x = @points.first.x @centre_y = @points.first.y @radius /= amount end |
#start_x ⇒ Object
28 29 30 |
# File 'lib/svgcode/svg/circle.rb', line 28 def start_x @centre_x - @radius end |