Class: TrianglePoints

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Enumerable
Defined in:
lib/math_demo/t_points.rb

Overview

includes a collinearity test using Vec2D

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeTrianglePoints

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

#pointsObject (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

Returns:

  • (Boolean)


22
23
24
# File 'lib/math_demo/t_points.rb', line 22

def collinear?
  full? ? (positions[0] - positions[1]).cross(positions[1] - positions[2]).zero? : false
end

#full?Boolean

Returns:

  • (Boolean)


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

def full?
  points.length == MAX_POINT
end

#positionsObject

returns positions as an array of Vec2D



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

def positions
  points.map(&:pos)
end