Class: Knot::Point
- Inherits:
-
Vector
- Object
- Vector
- Knot::Point
- Defined in:
- lib/knot/point.rb
Overview
Each point is modelled in the Cartesian plane as a vector.
Class Method Summary collapse
-
.distance(a, b) ⇒ Object
Calculates the distance between two points.
-
.midpoint(a, b) ⇒ Object
Calculates the midpoint between two points.
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
#x ⇒ Object
8 9 10 |
# File 'lib/knot/point.rb', line 8 def x self[0] end |
#y ⇒ Object
12 13 14 |
# File 'lib/knot/point.rb', line 12 def y self[1] end |