Class: Mindee::Geometry::Polygon

Inherits:
Array
  • Object
show all
Defined in:
lib/mindee/geometry/polygon.rb

Overview

Contains any number of vertex coordinates (Points).

Instance Method Summary collapse

Constructor Details

#initialize(server_response) ⇒ Polygon

Returns a new instance of Polygon.

Parameters:

  • server_response (Hash)

    Raw server response hash.



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

#centroidMindee::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.

Parameters:

Returns:

  • (bool)


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