Class: Bezier::ControlPoint

Inherits:
Object
  • Object
show all
Defined in:
lib/beziercurve.rb

Direct Known Subclasses

CurvePoint

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(x, y) ⇒ ControlPoint

Creates a new control point for the Bézier curve

Parameters:

  • x (Numeric)
  • y (Numeric)

11
12
13
14
# File 'lib/beziercurve.rb', line 11

def initialize(x,y)
	@x = x
	@y = y
end

Instance Attribute Details

#xObject

Returns the value of attribute x


5
6
7
# File 'lib/beziercurve.rb', line 5

def x
  @x
end

#yObject

Returns the value of attribute y


5
6
7
# File 'lib/beziercurve.rb', line 5

def y
  @y
end

Instance Method Details

#+(b) ⇒ Object


19
20
21
# File 'lib/beziercurve.rb', line 19

def + (b)
	self.class.new(self.x + b.x, self.y + b.y)
end

#-(b) ⇒ Object


16
17
18
# File 'lib/beziercurve.rb', line 16

def - (b)
	self.class.new(self.x - b.x, self.y - b.y)
end

#inspectObject


31
32
33
# File 'lib/beziercurve.rb', line 31

def inspect
	return @x, @y
end

#movepoint(point) ⇒ ControlPoint

Moves a controlpoint with relative distance

Returns:


27
28
29
# File 'lib/beziercurve.rb', line 27

def movepoint (point)
	self.class.new(self.x + point.x, self.y + point.y)
end

#to_aArray

Returns the control point as an array => [x, y]. The Array is fit to be as argument for ControlPoint.new

Returns:

  • (Array)

42
43
44
# File 'lib/beziercurve.rb', line 42

def to_a
	[self.x, self.y]
end

#to_curvepointCurvePoint

Returns a ControlPoint, converted to CurvePoint (this is only a naming difference).

Returns:

  • (CurvePoint)

    Returns a ControlPoint, converted to CurvePoint (this is only a naming difference).


36
37
38
# File 'lib/beziercurve.rb', line 36

def to_curvepoint
	CurvePoint.new(self.x, self.y)
end