class Draught::CubicBezier

Attributes

control_point_1[R]
control_point_2[R]
end_point[R]

Public Class Methods

new(args = {}) click to toggle source
# File lib/draught/cubic_bezier.rb, line 9
def initialize(args = {})
  @end_point = args.fetch(:end_point)
  @control_point_1 = args.fetch(:control_point_1)
  @control_point_2 = args.fetch(:control_point_2)
end

Public Instance Methods

==(other) click to toggle source
# File lib/draught/cubic_bezier.rb, line 23
def ==(other)
  other.point_type == point_type &&
    comparison_array(other).all? { |a, b| a == b }
end
approximates?(other, delta) click to toggle source
# File lib/draught/cubic_bezier.rb, line 32
def approximates?(other, delta)
  other.point_type == point_type &&
    comparison_array(other).all? { |a, b|
      a.approximates?(b, delta)
    }
end
point_type() click to toggle source
# File lib/draught/cubic_bezier.rb, line 28
def point_type
  :cubic_bezier
end
transform(transformer) click to toggle source
# File lib/draught/cubic_bezier.rb, line 43
def transform(transformer)
  new_args = Hash[args_hash.map { |k, point|
    [k, point.transform(transformer)]
  }]
  self.class.new(new_args)
end
translate(vector) click to toggle source
# File lib/draught/cubic_bezier.rb, line 39
def translate(vector)
  transform(vector.to_transform)
end
x() click to toggle source
# File lib/draught/cubic_bezier.rb, line 15
def x
  end_point.x
end
y() click to toggle source
# File lib/draught/cubic_bezier.rb, line 19
def y
  end_point.y
end

Private Instance Methods

args_hash() click to toggle source
# File lib/draught/cubic_bezier.rb, line 52
def args_hash
  {end_point: end_point, control_point_1: control_point_1, control_point_2: control_point_2}
end
comparison_array(other) click to toggle source
# File lib/draught/cubic_bezier.rb, line 56
def comparison_array(other)
  args_hash.map { |arg, point|
    [other.send(arg), point]
  }
end