Class: DYI::Shape::Path::CurveCommandBase
Overview
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.
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
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_point ⇒ Object
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_fragments ⇒ Object
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
|