Class: Svgcode::SVG::Circle

Inherits:
BaseCommand show all
Defined in:
lib/svgcode/svg/circle.rb

Constant Summary

Constants inherited from BaseCommand

BaseCommand::NAMES

Instance Attribute Summary collapse

Attributes inherited from BaseCommand

#absolute, #name, #points

Instance Method Summary collapse

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_xObject (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_yObject (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

#radiusObject (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_xObject



28
29
30
# File 'lib/svgcode/svg/circle.rb', line 28

def start_x
  @centre_x - @radius
end