Class: DYI::Shape::Path::PathData

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/dyi/shape/path.rb

Overview

Since:

  • 0.0.0

Instance Method Summary collapse

Constructor Details

#initialize(*points) ⇒ PathData

Returns a new instance of PathData.

Raises:

  • (ArgumentError)

Since:

  • 0.0.0



493
494
495
496
# File 'lib/dyi/shape/path.rb', line 493

def initialize(*points)
  raise ArgumentError, 'wrong number of arguments (0 for 1)' if points.empty?
  @commands = MoveCommand.absolute_commands(nil, *points)
end

Instance Method Details

#close?Boolean

Returns:

  • (Boolean)

Since:

  • 0.0.0



582
583
584
# File 'lib/dyi/shape/path.rb', line 582

def close?
  @commands.last.is_a?(CloseCommand)
end

#compatible_path_dataObject

Since:

  • 0.0.0



555
556
557
558
559
# File 'lib/dyi/shape/path.rb', line 555

def compatible_path_data
  new_instance = clone
  new_instance.commands = compatible_path_commands
  new_instance
end

#compatible_path_data!Object

Since:

  • 0.0.0



561
562
563
564
# File 'lib/dyi/shape/path.rb', line 561

def compatible_path_data!
  @commands = compatible_path_commands
  self
end

#current_pointObject

Since:

  • 0.0.0



570
571
572
# File 'lib/dyi/shape/path.rb', line 570

def current_point
  @commands.last.last_point
end

#current_start_pointObject

Since:

  • 0.0.0



574
575
576
# File 'lib/dyi/shape/path.rb', line 574

def current_start_point
  @commands.last.start_point
end

#eachObject

Since:

  • 0.0.0



498
499
500
501
502
503
504
# File 'lib/dyi/shape/path.rb', line 498

def each
  if block_given?
    @commands.each{|command| yield command}
  else
    @commands.each
  end
end

#path_pointsObject

Since:

  • 0.0.0



578
579
580
# File 'lib/dyi/shape/path.rb', line 578

def path_points
  @commands.map{|command| command.points}.flatten
end

#pop_commandObject

Since:

  • 0.0.0



551
552
553
# File 'lib/dyi/shape/path.rb', line 551

def pop_command
  @commands.pop
end

#push_command(command_type, *args) ⇒ Object

Since:

  • 0.0.0



506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
# File 'lib/dyi/shape/path.rb', line 506

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_pointObject

Since:

  • 0.0.0



566
567
568
# File 'lib/dyi/shape/path.rb', line 566

def start_point
  @commands.first.start_point
end

#to_concise_syntaxObject

Since:

  • 0.0.0



586
587
588
# File 'lib/dyi/shape/path.rb', line 586

def to_concise_syntax
  @commands.map{|command| command.to_concise_syntax_fragments}.join(' ')
end