Class: Draught::Curve
- Inherits:
-
Object
- Object
- Draught::Curve
- Includes:
- Pointlike
- Defined in:
- lib/draught/curve.rb
Overview
An abstract representation of a curve in a pointlike fashion, in the way a CubicBezier is pointlike
Instance Method Summary collapse
- #==(other) ⇒ Object
- #approximates?(other, delta) ⇒ Boolean
- #as_cubic_beziers ⇒ Object
-
#initialize(args = {}) ⇒ Curve
constructor
A new instance of Curve.
- #point_type ⇒ Object
- #transform(transformer) ⇒ Object
- #translate(vector) ⇒ Object
- #x ⇒ Object
- #y ⇒ Object
Methods included from Pointlike
Constructor Details
#initialize(args = {}) ⇒ Curve
Returns a new instance of Curve.
12 13 14 15 |
# File 'lib/draught/curve.rb', line 12 def initialize(args = {}) @point = args.fetch(:point) @cubic_beziers = args.fetch(:cubic_beziers).dup.freeze end |
Instance Method Details
#==(other) ⇒ Object
33 34 35 36 |
# File 'lib/draught/curve.rb', line 33 def ==(other) other.point_type == point_type && other.point == point && other.as_cubic_beziers == as_cubic_beziers end |
#approximates?(other, delta) ⇒ Boolean
38 39 40 41 42 43 44 45 |
# File 'lib/draught/curve.rb', line 38 def approximates?(other, delta) other.point_type == point_type && point.approximates?(other.point, delta) && number_of_segments == other.number_of_segments && as_cubic_beziers.zip(other.as_cubic_beziers).all? { |a, b| a.approximates?(b, delta) } end |
#as_cubic_beziers ⇒ Object
29 30 31 |
# File 'lib/draught/curve.rb', line 29 def as_cubic_beziers @cubic_beziers end |
#point_type ⇒ Object
25 26 27 |
# File 'lib/draught/curve.rb', line 25 def point_type :curve end |
#transform(transformer) ⇒ Object
59 60 61 62 63 64 |
# File 'lib/draught/curve.rb', line 59 def transform(transformer) self.class.new({ point: @point.transform(transformer), cubic_beziers: @cubic_beziers.map { |c| c.transform(transformer) } }) end |
#translate(vector) ⇒ Object
52 53 54 55 56 57 |
# File 'lib/draught/curve.rb', line 52 def translate(vector) self.class.new({ point: @point.translate(vector), cubic_beziers: @cubic_beziers.map { |c| c.translate(vector) } }) end |
#x ⇒ Object
17 18 19 |
# File 'lib/draught/curve.rb', line 17 def x @point.x end |
#y ⇒ Object
21 22 23 |
# File 'lib/draught/curve.rb', line 21 def y @point.y end |