Class: DYI::Shape::Polyline

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

Overview

Since:

  • 0.0.0

Direct Known Subclasses

Polygon

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

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, options = {}) ⇒ Polyline

Returns a new instance of Polyline.

Parameters:

  • start_point (Coordinate)

    a start coordinate of the shape

  • 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



678
679
680
681
682
# File 'lib/dyi/shape/base.rb', line 678

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

Instance Method Details

#bottomObject

Since:

  • 0.0.0



722
723
724
# File 'lib/dyi/shape/base.rb', line 722

def bottom
  @points.max {|a, b| a.y <=> b.y}.y
end

#current_pointObject

Since:

  • 0.0.0



694
695
696
# File 'lib/dyi/shape/base.rb', line 694

def current_point
  @points.last
end

#leftObject

Since:

  • 0.0.0



710
711
712
# File 'lib/dyi/shape/base.rb', line 710

def left
  @points.min {|a, b| a.x <=> b.x}.x
end

#line_to(*points) ⇒ Object

Since:

  • 0.0.0



684
685
686
# File 'lib/dyi/shape/base.rb', line 684

def line_to(*points)
  @points.push(*points.map{|pt| Coordinate.new(pt)})
end

#pointsObject

Since:

  • 0.0.0



702
703
704
# File 'lib/dyi/shape/base.rb', line 702

def points
  @points.clone
end

#rightObject

Since:

  • 0.0.0



714
715
716
# File 'lib/dyi/shape/base.rb', line 714

def right
  @points.max {|a, b| a.x <=> b.x}.x
end

#rline_to(*points) ⇒ Object

Since:

  • 1.1.0



689
690
691
692
# File 'lib/dyi/shape/base.rb', line 689

def rline_to(*points)
  current = current_point
  @points.push(*points.inject([]){|result, pt| result << (current += pt)})
end

#start_pointObject

Since:

  • 0.0.0



698
699
700
# File 'lib/dyi/shape/base.rb', line 698

def start_point
  @points.first
end

#topObject

Since:

  • 0.0.0



718
719
720
# File 'lib/dyi/shape/base.rb', line 718

def top
  @points.min {|a, b| a.y <=> b.y}.y
end

#undoObject

Since:

  • 0.0.0



706
707
708
# File 'lib/dyi/shape/base.rb', line 706

def undo
  @points.pop if @points.size > 1
end

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

Since:

  • 0.0.0



726
727
728
# File 'lib/dyi/shape/base.rb', line 726

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