class DYI::Shape::Path::PathData

Public Class Methods

new(*points) click to toggle source
# File lib/dyi/shape/path.rb, line 492
def initialize(*points)
  raise ArgumentError, 'wrong number of arguments (0 for 1)' if points.empty?
  @commands = MoveCommand.absolute_commands(nil, *points)
end

Public Instance Methods

close?() click to toggle source
# File lib/dyi/shape/path.rb, line 581
def close?
  @commands.last.is_a?(CloseCommand)
end
compatible_path_data() click to toggle source
# File lib/dyi/shape/path.rb, line 554
def compatible_path_data
  new_instance = clone
  new_instance.commands = compatible_path_commands
  new_instance
end
compatible_path_data!() click to toggle source
# File lib/dyi/shape/path.rb, line 560
def compatible_path_data!
  @commands = compatible_path_commands
  self
end
current_point() click to toggle source
# File lib/dyi/shape/path.rb, line 569
def current_point
  @commands.last.last_point
end
current_start_point() click to toggle source
# File lib/dyi/shape/path.rb, line 573
def current_start_point
  @commands.last.start_point
end
each() { |command| ... } click to toggle source
# File lib/dyi/shape/path.rb, line 497
def each
  if block_given?
    @commands.each{|command| yield command}
  else
    @commands.each
  end
end
path_points() click to toggle source
# File lib/dyi/shape/path.rb, line 577
def path_points
  @commands.map{|command| command.points}.flatten
end
pop_command() click to toggle source
# File lib/dyi/shape/path.rb, line 550
def pop_command
  @commands.pop
end
push_command(command_type, *args) click to toggle source
# File lib/dyi/shape/path.rb, line 505
def push_command(command_type, *args)
  case command_type
  when :move_to
    @commands.push(*MoveCommand.absolute_commands(@commands.last, *args))
  when :rmove_to
    @commands.push(*MoveCommand.relative_commands(@commands.last, *args))
  when :close_path
    @commands.push(*CloseCommand.commands(@commands.last))
  when :line_to
    @commands.push(*LineCommand.absolute_commands(@commands.last, *args))
  when :rline_to
    @commands.push(*LineCommand.relative_commands(@commands.last, *args))
  when :horizontal_lineto_to
    @commands.push(*HorizontalLineCommand.absolute_commands(@commands.last, *args))
  when :rhorizontal_lineto_to
    @commands.push(*HorizontalLineCommand.relative_commands(@commands.last, *args))
  when :vertical_lineto_to
    @commands.push(*VerticalLineCommand.absolute_commands(@commands.last, *args))
  when :rvertical_lineto_to
    @commands.push(*VerticalLineCommand.relative_commands(@commands.last, *args))
  when :curve_to
    @commands.push(*CurveCommand.absolute_commands(@commands.last, *args))
  when :rcurve_to
    @commands.push(*CurveCommand.relative_commands(@commands.last, *args))
  when :shorthand_curve_to
    @commands.push(*ShorthandCurveCommand.absolute_commands(@commands.last, *args))
  when :rshorthand_curve_to
    @commands.push(*ShorthandCurveCommand.relative_commands(@commands.last, *args))
  when :quadratic_curve_to
    @commands.push(*QuadraticCurveCommand.absolute_commands(@commands.last, *args))
  when :rquadratic_curve_to
    @commands.push(*QuadraticCurveCommand.relative_commands(@commands.last, *args))
  when :shorthand_quadratic_curve_to
    @commands.push(*ShorthandQuadraticCurveCommand.absolute_commands(@commands.last, *args))
  when :rshorthand_quadratic_curve_to
    @commands.push(*ShorthandQuadraticCurveCommand.relative_commands(@commands.last, *args))
  when :arc_to
    @commands.push(*ArcCommand.absolute_commands(@commands.last, *args))
  when :rarc_to
    @commands.push(*ArcCommand.relative_commands(@commands.last, *args))
  else
    raise ArgumentError, "unknown command type `#{command_type}'"
  end
end
start_point() click to toggle source
# File lib/dyi/shape/path.rb, line 565
def start_point
  @commands.first.start_point
end
to_concise_syntax() click to toggle source
# File lib/dyi/shape/path.rb, line 585
def to_concise_syntax
  @commands.map{|command| command.to_concise_syntax_fragments}.join(' ')
end

Protected Instance Methods

commands=(value) click to toggle source
# File lib/dyi/shape/path.rb, line 591
def commands=(value)
  @commands = value
end

Private Instance Methods

compatible_path_commands() click to toggle source
# File lib/dyi/shape/path.rb, line 597
def compatible_path_commands
  @commands.inject([]) do |compat_cmds, command|
    compat_cmds.push(*command.to_compatible_commands(compat_cmds.last))
  end
end