Class: Mindee::Geometry::Quadrilateral

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

Overview

Contains exactly 4 relative vertices coordinates (Points).

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(top_left, top_right, bottom_right, bottom_left) ⇒ Quadrilateral

Returns a new instance of Quadrilateral.

Parameters:



21
22
23
24
25
26
# File 'lib/mindee/geometry/quadrilateral.rb', line 21

def initialize(top_left, top_right, bottom_right, bottom_left)
  @top_left = top_left
  @top_right = top_right
  @bottom_right = bottom_right
  @bottom_left = bottom_left
end

Instance Attribute Details

#bottom_leftMindee::Geometry::Point



15
16
17
# File 'lib/mindee/geometry/quadrilateral.rb', line 15

def bottom_left
  @bottom_left
end

#bottom_rightMindee::Geometry::Point



13
14
15
# File 'lib/mindee/geometry/quadrilateral.rb', line 13

def bottom_right
  @bottom_right
end

#top_leftMindee::Geometry::Point



9
10
11
# File 'lib/mindee/geometry/quadrilateral.rb', line 9

def top_left
  @top_left
end

#top_rightMindee::Geometry::Point



11
12
13
# File 'lib/mindee/geometry/quadrilateral.rb', line 11

def top_right
  @top_right
end

Instance Method Details

#[](key) ⇒ Mindee::Geometry::Point



29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/mindee/geometry/quadrilateral.rb', line 29

def [](key)
  case key
  when 0
    @top_left
  when 1
    @top_right
  when 2
    @bottom_right
  when 3
    @bottom_left
  else
    throw '0, 1, 2, 3 only'
  end
end

#sizeObject

A quadrilateral has four corners, always.



45
46
47
# File 'lib/mindee/geometry/quadrilateral.rb', line 45

def size
  4
end