Class: Knot::Point

Inherits:
Vector
  • Object
show all
Defined in:
lib/knot/point.rb

Overview

Each point is modelled in the Cartesian plane as a vector.

ruby-doc.org/stdlib-3.0.2/libdoc/matrix/rdoc/Vector.html

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.distance(a, b) ⇒ Object

Calculates the distance between two points. Used for calculating radii for arc curves.



25
26
27
# File 'lib/knot/point.rb', line 25

def self.distance(a, b)
  (a - b).magnitude
end

.midpoint(a, b) ⇒ Object

Calculates the midpoint between two points. Used where a desired point has not been pre-calculated but can instead be derived from another pair of points that are pre-calculated.



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

def self.midpoint(a, b)
  (a + b) / 2
end

Instance Method Details

#xObject



8
9
10
# File 'lib/knot/point.rb', line 8

def x
  self[0]
end

#yObject



12
13
14
# File 'lib/knot/point.rb', line 12

def y
  self[1]
end