class DYI::Shape::Path::CurveCommandBase

Public Class Methods

new(relative, preceding_command, *points) click to toggle source
# File lib/dyi/shape/path.rb, line 792
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

Private Class Methods

commands(relative, preceding_command, *points) click to toggle source
# File lib/dyi/shape/path.rb, line 822
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

Public Instance Methods

last_control_point() click to toggle source
# File lib/dyi/shape/path.rb, line 801
def last_control_point
  relative? ? (preceding_point + @control_points.last) : @control_points.last
end
to_concise_syntax_fragments() click to toggle source
# File lib/dyi/shape/path.rb, line 805
def to_concise_syntax_fragments
  used_same_command? ? @point.to_s : (instructions_char + @point.to_s)
end

Private Instance Methods

pt_cnt() click to toggle source
# File lib/dyi/shape/path.rb, line 817
def pt_cnt
  self.class.pt_cnt
end