Class: DYI::Shape::Path::CurveCommandBase

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

Overview

Since:

  • 0.0.0

Direct Known Subclasses

CurveCommand, QuadraticCurveCommand

Instance Attribute Summary

Attributes inherited from CommandBase

#point, #preceding_command

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from CommandBase

#absolute?, absolute_commands, #last_point, #preceding_point, #relative?, relative_commands, #start_point, #to_compatible_commands, #used_same_command?

Constructor Details

#initialize(relative, preceding_command, *points) ⇒ CurveCommandBase

Returns a new instance of CurveCommandBase.

Raises:

  • (ArgumentError)

Since:

  • 0.0.0



793
794
795
796
797
798
799
800
# File 'lib/dyi/shape/path.rb', line 793

def initialize(relative, preceding_command, *points)
  raise ArgumentError, "wrong number of arguments (2 for #{pt_cnt + 2})" if points.size != pt_cnt
  raise ArgumentError, 'preceding_command is nil' if preceding_command.nil?
  @relative = relative
  @preceding_command = preceding_command
  @point = Coordinate.new(points.last)
  @control_points = points[0..-2].map{|pt| Coordinate.new(pt)}
end

Class Method Details

.commands(relative, preceding_command, *points) ⇒ Object

Raises:

  • (ArgumentError)

Since:

  • 0.0.0



823
824
825
826
827
828
829
# File 'lib/dyi/shape/path.rb', line 823

def commands(relative, preceding_command, *points)
  raise ArgumentError, "number of points must be a multipule of #{pt_cnt}" if points.size % pt_cnt != 0
  cmd = preceding_command
  points.each_slice(pt_cnt).inject([]) do |cmds, pts|
    cmds << (cmd = new(relative, cmd, *pts))
  end
end

Instance Method Details

#last_control_pointObject

Since:

  • 0.0.0



802
803
804
# File 'lib/dyi/shape/path.rb', line 802

def last_control_point
  relative? ? (preceding_point + @control_points.last) : @control_points.last
end

#to_concise_syntax_fragmentsObject

Since:

  • 0.0.0



806
807
808
# File 'lib/dyi/shape/path.rb', line 806

def to_concise_syntax_fragments
  used_same_command? ? @point.to_s : (instructions_char + @point.to_s)
end