Class: Geometry::Triangle Abstract

Inherits:
Object
  • Object
show all
Includes:
ClusterFactory
Defined in:
lib/geometry/triangle.rb

Overview

This class is abstract.

Factory class that instantiates the appropriate subclasses

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from ClusterFactory

included

Instance Attribute Details

#closed?Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/geometry/triangle.rb', line 41

def closed?
    true
end

Class Method Details

.new(point0, point1, point2) ⇒ Object .new(point, length) ⇒ Object

Overloads:



31
32
33
34
35
36
37
# File 'lib/geometry/triangle.rb', line 31

def self.new(*args)
     if args.size == 3
	ScaleneTriangle.new *args
     elsif args.size == 2
	RightTriangle.new args[0], args[1], args[1]
     end
end

Instance Method Details

#maxPoint

Returns The upper-right corner of the bounding rectangle that encloses the Polyline.

Returns:

  • (Point)

    The upper-right corner of the bounding rectangle that encloses the Polyline



46
47
48
# File 'lib/geometry/triangle.rb', line 46

def max
    points.reduce {|memo, vertex| Point[[memo.x, vertex.x].max, [memo.y, vertex.y].max] }
end

#minPoint

Returns The lower-left corner of the bounding rectangle that encloses the Polyline.

Returns:

  • (Point)

    The lower-left corner of the bounding rectangle that encloses the Polyline



51
52
53
# File 'lib/geometry/triangle.rb', line 51

def min
    points.reduce {|memo, vertex| Point[[memo.x, vertex.x].min, [memo.y, vertex.y].min] }
end

#minmaxArray<Point>

Returns The lower-left and upper-right corners of the enclosing bounding rectangle.

Returns:

  • (Array<Point>)

    The lower-left and upper-right corners of the enclosing bounding rectangle



56
57
58
# File 'lib/geometry/triangle.rb', line 56

def minmax
    points.reduce([points.first, points.first]) {|memo, vertex| [Point[[memo.first.x, vertex.x].min, [memo.first.y, vertex.y].min], Point[[memo.last.x, vertex.x].max, [memo.last.y, vertex.y].max]] }
end