Class: Savage::Directions::CubicCurveTo

Inherits:
QuadraticCurveTo show all
Defined in:
lib/savage/directions/cubic_curve_to.rb

Instance Attribute Summary collapse

Attributes inherited from QuadraticCurveTo

#control

Attributes inherited from PointTarget

#target

Instance Method Summary collapse

Methods inherited from Savage::Direction

#absolute?, #to_command

Methods included from Utils

#bool_to_int

Constructor Details

#initialize(*args) ⇒ CubicCurveTo

Returns a new instance of CubicCurveTo.

Raises:

  • (ArgumentError)


6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/savage/directions/cubic_curve_to.rb', line 6

def initialize(*args)
  raise ArgumentError if args.length < 4
  case args.length
  when 4
    super(args[0],args[1],args[2],args[3],true)
  when 5
    raise ArgumentError if args[4].kind_of?(Numeric)
    super(args[0],args[1],args[2],args[3],args[4])
  when 6
    @control_1 = Point.new(args[0],args[1])
    super(args[2],args[3],args[4],args[5],true)
  when 7
    @control_1 = Point.new(args[0],args[1])
    super(args[2],args[3],args[4],args[5],args[6])
  end
end

Instance Attribute Details

#control_1Object

Returns the value of attribute control_1.



4
5
6
# File 'lib/savage/directions/cubic_curve_to.rb', line 4

def control_1
  @control_1
end

Instance Method Details

#command_codeObject



34
35
36
37
# File 'lib/savage/directions/cubic_curve_to.rb', line 34

def command_code
  return (absolute?) ? 'C' : 'c' if @control_1
  (absolute?) ? 'S' : 's'
end

#control_2Object



31
# File 'lib/savage/directions/cubic_curve_to.rb', line 31

def control_2; @control; end

#control_2=(value) ⇒ Object



32
# File 'lib/savage/directions/cubic_curve_to.rb', line 32

def control_2=(value); @control = value; end

#to_aObject



23
24
25
26
27
28
29
# File 'lib/savage/directions/cubic_curve_to.rb', line 23

def to_a
  if @control_1
    [command_code, @control_1.x, @control_1.y, @control.x, @control.y, @target.x, @target.y]
  else
    [command_code, @control.x, @control.y, @target.x, @target.y]
  end
end