Class: DYI::Shape::Line

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

Overview

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 included from Markable

#has_marker?, #marker, #set_marker

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(start_point, end_point, options = {}) ⇒ Line

Returns a new instance of Line.

Parameters:

  • start_point (Coordinate)

    a start coordinate of the line

  • end_point (Coordinate)

    an end coordinate of the line

  • 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



628
629
630
631
632
633
# File 'lib/dyi/shape/base.rb', line 628

def initialize(start_point, end_point, options={})
  @start_point = Coordinate.new(start_point)
  @end_point = Coordinate.new(end_point)
  @attributes = init_attributes(options)
  @marker = {}
end

Class Method Details

.create_on_direction(start_point, direction_x, direction_y, options = {}) ⇒ Object

Since:

  • 0.0.0



663
664
665
666
667
# File 'lib/dyi/shape/base.rb', line 663

def create_on_direction(start_point, direction_x, direction_y, options={})
  start_point = Coordinate.new(start_point)
  end_point = start_point + Coordinate.new(direction_x, direction_y)
  new(start_point, end_point, options)
end

.create_on_start_end(start_point, end_point, options = {}) ⇒ Object

Since:

  • 0.0.0



659
660
661
# File 'lib/dyi/shape/base.rb', line 659

def create_on_start_end(start_point, end_point, options={})
  new(start_point, end_point, options)
end

Instance Method Details

#bottomObject

Since:

  • 0.0.0



647
648
649
# File 'lib/dyi/shape/base.rb', line 647

def bottom
  [@start_point.y, @end_point.y].max
end

#leftObject

Since:

  • 0.0.0



635
636
637
# File 'lib/dyi/shape/base.rb', line 635

def left
  [@start_point.x, @end_point.x].min
end

#rightObject

Since:

  • 0.0.0



639
640
641
# File 'lib/dyi/shape/base.rb', line 639

def right
  [@start_point.x, @end_point.x].max
end

#topObject

Since:

  • 0.0.0



643
644
645
# File 'lib/dyi/shape/base.rb', line 643

def top
  [@start_point.y, @end_point.y].min
end

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

Since:

  • 0.0.0



651
652
653
# File 'lib/dyi/shape/base.rb', line 651

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