Class: Geometry::PointInPolygon

Inherits:
Struct
  • Object
show all
Extended by:
Memoist
Defined in:
lib/geometry/algorithms/point_in_polygon.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#pointObject

Returns the value of attribute point


2
3
4
# File 'lib/geometry/algorithms/point_in_polygon.rb', line 2

def point
  @point
end

#polygonObject

Returns the value of attribute polygon


2
3
4
# File 'lib/geometry/algorithms/point_in_polygon.rb', line 2

def polygon
  @polygon
end

Instance Method Details

#inside?Boolean


5
6
7
# File 'lib/geometry/algorithms/point_in_polygon.rb', line 5

def inside?
  point_location == :inside
end

#on_the_boundary?Boolean


13
14
15
# File 'lib/geometry/algorithms/point_in_polygon.rb', line 13

def on_the_boundary?
  point_location == :on_the_boundary
end

#outside?Boolean


9
10
11
# File 'lib/geometry/algorithms/point_in_polygon.rb', line 9

def outside?
  point_location == :outside
end

#point_locationObject


17
18
19
20
21
22
# File 'lib/geometry/algorithms/point_in_polygon.rb', line 17

def point_location
  return :outside unless bounding_box.contains?(point)
  return :on_the_boundary if point_is_vertex? || point_on_edge?

  intersection_count(choose_good_ray).odd? ? :inside : :outside
end