Class: Geometry::Triangle Abstract
- Inherits:
-
Object
- Object
- Geometry::Triangle
- Includes:
- ClusterFactory
- Defined in:
- lib/geometry/triangle.rb
Overview
This class is abstract.
Factory class that instantiates the appropriate subclasses
Direct Known Subclasses
EquilateralTriangle, IsoscelesTriangle, RightTriangle, ScaleneTriangle
Instance Attribute Summary collapse
Class Method Summary collapse
Instance Method Summary collapse
-
#max ⇒ Point
The upper-right corner of the bounding rectangle that encloses the Polyline.
-
#min ⇒ Point
The lower-left corner of the bounding rectangle that encloses the Polyline.
-
#minmax ⇒ Array<Point>
The lower-left and upper-right corners of the enclosing bounding rectangle.
Methods included from ClusterFactory
Instance Attribute Details
#closed? ⇒ 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
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
#max ⇒ Point
Returns 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 |
#min ⇒ Point
Returns 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 |
#minmax ⇒ Array<Point>
Returns 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 |