Class: DYI::Shape::Circle

Inherits:
Base show all
Defined in:
lib/dyi/shape/base.rb

Overview

The circle in the vector image

Since:

  • 0.0.0

Constant Summary

Constants inherited from GraphicalElement

GraphicalElement::CLASS_REGEXP

Constants inherited from Element

Element::ID_REGEXP

Instance Attribute Summary

Attributes inherited from Base

#anchor_href, #anchor_target, #attributes, #clipping, #parent

Attributes inherited from GraphicalElement

#css_class

Attributes inherited from Element

#description, #title

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#add_animation, #add_painting_animation, #add_transform_animation, #animate?, #animations, #clear_clipping, #draw_on, #has_marker?, #has_uri_reference?, #root_element?, #root_node?, #rotate, #scale, #set_clipping, #set_clipping_shapes, #set_event, #skew_x, #skew_y, #transform, #translate

Methods inherited from GraphicalElement

#add_css_class, #add_event_listener, #css_classes, #event_listeners, #event_target?, #remove_css_class, #remove_event_listener, #set_event, #to_reused_source

Methods inherited from Element

#canvas, #child_elements, #has_uri_reference?, #id, #id=, #include_external_file?, #inner_id

Constructor Details

#initialize(center, radius, options = {}) ⇒ Circle

Returns a new instance of Circle.

Parameters:

  • center (Coordinate)

    a center coordinate of the circle

  • radius (Length)

    a radius length of the circle

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • :painting (Painting)

    painting status of this shape

  • :description (String)

    the description of this shape

  • :title (String)

    the title of this shape

Since:

  • 0.0.0



520
521
522
523
524
# File 'lib/dyi/shape/base.rb', line 520

def initialize(center, radius, options={})
  @center = Coordinate.new(center)
  @radius = Length.new(radius).abs
  @attributes = init_attributes(options)
end

Class Method Details

.create_on_center_radius(center, radius, options = {}) ⇒ Object

Since:

  • 0.0.0



558
559
560
# File 'lib/dyi/shape/base.rb', line 558

def create_on_center_radius(center, radius, options={})
  new(center, radius, options)
end

Instance Method Details

#bottomObject

Since:

  • 0.0.0



538
539
540
# File 'lib/dyi/shape/base.rb', line 538

def bottom
  @center.y + @radius
end

#heightObject

Since:

  • 0.0.0



546
547
548
# File 'lib/dyi/shape/base.rb', line 546

def height
  @radius * 2
end

#leftObject

Since:

  • 0.0.0



526
527
528
# File 'lib/dyi/shape/base.rb', line 526

def left
  @center.x - @radius
end

#rightObject

Since:

  • 0.0.0



530
531
532
# File 'lib/dyi/shape/base.rb', line 530

def right
  @center.x + @radius
end

#topObject

Since:

  • 0.0.0



534
535
536
# File 'lib/dyi/shape/base.rb', line 534

def top
  @center.y - @radius
end

#widthObject

Since:

  • 0.0.0



542
543
544
# File 'lib/dyi/shape/base.rb', line 542

def width
  @radius * 2
end

#write_as(formatter, io = $>) ⇒ Object

Since:

  • 0.0.0



550
551
552
# File 'lib/dyi/shape/base.rb', line 550

def write_as(formatter, io=$>)
  formatter.write_circle(self, io, &(block_given? ? Proc.new : nil))
end