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 positions

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
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

Returns:

  • (Boolean)


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

def full?
  points.length == MAX_POINT
end

#positionsObject

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