Class: Mindee::Geometry::Polygon
- Inherits:
-
Array
- Object
- Array
- Mindee::Geometry::Polygon
- Defined in:
- lib/mindee/geometry/polygon.rb
Overview
Contains any number of vertex coordinates (Points).
Instance Method Summary collapse
-
#centroid ⇒ Mindee::Geometry::Point
Get the central point (centroid) of the polygon.
-
#initialize(server_response) ⇒ Polygon
constructor
A new instance of Polygon.
-
#point_in_y?(point) ⇒ bool
Determine if the Point is in the Polygon's Y-axis.
Constructor Details
#initialize(server_response) ⇒ Polygon
Returns a new instance of Polygon.
9 10 11 12 13 14 15 |
# File 'lib/mindee/geometry/polygon.rb', line 9 def initialize(server_response) points = [] server_response.map do |point| points << Point.new(point[0], point[1]) end super(points) end |
Instance Method Details
#centroid ⇒ Mindee::Geometry::Point
Get the central point (centroid) of the polygon.
19 20 21 |
# File 'lib/mindee/geometry/polygon.rb', line 19 def centroid Geometry.get_centroid(self) end |
#point_in_y?(point) ⇒ bool
Determine if the Point is in the Polygon's Y-axis.
26 27 28 29 |
# File 'lib/mindee/geometry/polygon.rb', line 26 def point_in_y?(point) min_max = Geometry.get_min_max_y(self) point.y.between?(min_max.min, min_max.max) end |