Class: Vedeu::BoundingArea
- Inherits:
-
Object
- Object
- Vedeu::BoundingArea
- Defined in:
- lib/vedeu/geometry/bounding_area.rb
Overview
Provides coordinates based on the height and width provided. Coordinates always start from 1, 1.
Instance Attribute Summary collapse
-
#height ⇒ Object
readonly
Returns the value of attribute height.
-
#width ⇒ Object
readonly
Returns the value of attribute width.
Instance Method Summary collapse
-
#bottom(offset = 0) ⇒ Fixnum
(also: #yn)
Returns the bottom line (yn) coordinate for the console.
-
#initialize(height, width) ⇒ Vedeu::BoundingArea
constructor
Returns an instance of BoundingArea.
-
#left(offset = 0) ⇒ Fixnum
(also: #x)
Returns the leftmost column (x) coordinate for the console.
-
#right(offset = 0) ⇒ Fixnum
(also: #xn)
Returns the rightmost column (yn) coordinate for the console.
-
#top(offset = 0) ⇒ Fixnum
(also: #y)
Returns the top line (y) coordinate for the console.
Constructor Details
#initialize(height, width) ⇒ Vedeu::BoundingArea
Returns an instance of BoundingArea.
16 17 18 19 |
# File 'lib/vedeu/geometry/bounding_area.rb', line 16 def initialize(height, width) @height = height @width = width end |
Instance Attribute Details
#height ⇒ Object (readonly)
Returns the value of attribute height.
8 9 10 |
# File 'lib/vedeu/geometry/bounding_area.rb', line 8 def height @height end |
#width ⇒ Object (readonly)
Returns the value of attribute width.
8 9 10 |
# File 'lib/vedeu/geometry/bounding_area.rb', line 8 def width @width end |
Instance Method Details
#bottom(offset = 0) ⇒ Fixnum Also known as: yn
Returns the bottom line (yn) coordinate for the console.
61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/vedeu/geometry/bounding_area.rb', line 61 def bottom(offset = 0) if offset >= height 1 elsif offset < 0 height else height - offset end end |
#left(offset = 0) ⇒ Fixnum Also known as: x
Returns the leftmost column (x) coordinate for the console.
88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/vedeu/geometry/bounding_area.rb', line 88 def left(offset = 0) if offset >= width width elsif offset <= 1 1 else 1 + offset end end |
#right(offset = 0) ⇒ Fixnum Also known as: xn
Returns the rightmost column (yn) coordinate for the console.
115 116 117 118 119 120 121 122 123 124 125 126 |
# File 'lib/vedeu/geometry/bounding_area.rb', line 115 def right(offset = 0) if offset >= width 1 elsif offset < 0 width else width - offset end end |
#top(offset = 0) ⇒ Fixnum Also known as: y
Returns the top line (y) coordinate for the console.
34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/vedeu/geometry/bounding_area.rb', line 34 def top(offset = 0) if offset >= height height elsif offset <= 1 1 else 1 + offset end end |