Class: TrianglePoints
- Inherits:
-
Object
- Object
- TrianglePoints
- Extended by:
- Forwardable
- Includes:
- Enumerable
- Defined in:
- lib/math_demo/t_points.rb
Overview
includes a collinearity test using Vec2D positions
Instance Attribute Summary collapse
-
#points ⇒ Object
readonly
Returns the value of attribute points.
Instance Method Summary collapse
- #<<(pt) ⇒ Object
- #collinear? ⇒ Boolean
- #full? ⇒ Boolean
-
#initialize ⇒ TrianglePoints
constructor
A new instance of TrianglePoints.
-
#positions ⇒ Object
returns positions as an array of Vec2D.
Constructor Details
#initialize ⇒ TrianglePoints
Returns a new instance of TrianglePoints.
13 14 15 |
# File 'lib/math_demo/t_points.rb', line 13 def initialize @points = [] end |
Instance Attribute Details
#points ⇒ Object (readonly)
Returns the value of attribute points.
11 12 13 |
# File 'lib/math_demo/t_points.rb', line 11 def points @points end |
Instance Method Details
#<<(pt) ⇒ Object
17 18 19 20 |
# File 'lib/math_demo/t_points.rb', line 17 def <<(pt) points << pt shift if size > MAX_POINT end |
#collinear? ⇒ Boolean
22 23 24 25 |
# File 'lib/math_demo/t_points.rb', line 22 def collinear? first, second, third = positions full? ? (first - second).cross(second - third).zero? : false end |
#full? ⇒ Boolean
32 33 34 |
# File 'lib/math_demo/t_points.rb', line 32 def full? points.length == MAX_POINT end |
#positions ⇒ Object
returns positions as an array of Vec2D
28 29 30 |
# File 'lib/math_demo/t_points.rb', line 28 def positions points.map(&:pos) end |