Class: Vedeu::Coordinate
- Inherits:
-
Object
- Object
- Vedeu::Coordinate
- Defined in:
- lib/vedeu/geometry/coordinate.rb
Overview
Crudely corrects out of range values.
Instance Attribute Summary collapse
-
#height ⇒ Object
readonly
private
Returns the value of attribute height.
-
#width ⇒ Object
readonly
private
Returns the value of attribute width.
-
#x ⇒ Object
readonly
Returns the value of attribute x.
-
#y ⇒ Object
readonly
Returns the value of attribute y.
Instance Method Summary collapse
- #initialize(height, width, x, y) ⇒ Vedeu::Coordinate constructor
-
#x_index(position = x) ⇒ Fixnum
Returns the index for a given x position.
-
#x_indices ⇒ Array
private
Returns the same as #x_range, except as indices of an array.
-
#x_position(index = 0) ⇒ Fixnum
Returns the x coordinate for a given index.
-
#x_range ⇒ Array
private
Returns an array with all coordinates from x to xn.
-
#xn ⇒ Fixnum
Returns the maximum x coordinate for an area.
-
#xn_index ⇒ Fixnum
private
Returns the maximum x index for an area.
-
#y_index(position = y) ⇒ Fixnum
Returns the index for a given y position.
-
#y_indices ⇒ Array
private
Returns the same as #y_range, except as indices of an array.
-
#y_position(index = 0) ⇒ Fixnum
Returns the y coordinate for a given index.
-
#y_range ⇒ Array
private
Returns an array with all coordinates from y to yn.
-
#yn ⇒ Fixnum
Returns the maximum y coordinate for an area.
-
#yn_index ⇒ Fixnum
private
Returns the maximum y index for an area.
Constructor Details
#initialize(height, width, x, y) ⇒ Vedeu::Coordinate
17 18 19 20 21 22 |
# File 'lib/vedeu/geometry/coordinate.rb', line 17 def initialize(height, width, x, y) @height = height @width = width @x = x @y = y end |
Instance Attribute Details
#height ⇒ Object (readonly, private)
Returns the value of attribute height.
7 8 9 |
# File 'lib/vedeu/geometry/coordinate.rb', line 7 def height @height end |
#width ⇒ Object (readonly, private)
Returns the value of attribute width.
7 8 9 |
# File 'lib/vedeu/geometry/coordinate.rb', line 7 def width @width end |
#x ⇒ Object (readonly)
Returns the value of attribute x.
7 8 9 |
# File 'lib/vedeu/geometry/coordinate.rb', line 7 def x @x end |
#y ⇒ Object (readonly)
Returns the value of attribute y.
7 8 9 |
# File 'lib/vedeu/geometry/coordinate.rb', line 7 def y @y end |
Instance Method Details
#x_index(position = x) ⇒ Fixnum
Returns the index for a given x position.
97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/vedeu/geometry/coordinate.rb', line 97 def x_index(position = x) if width <= 0 || position <= x 0 elsif position >= xn xn_index else x_range.index(position) end end |
#x_indices ⇒ Array (private)
Returns the same as #x_range, except as indices of an array.
206 207 208 |
# File 'lib/vedeu/geometry/coordinate.rb', line 206 def x_indices (0...width).to_a end |
#x_position(index = 0) ⇒ Fixnum
Returns the x coordinate for a given index.
145 146 147 148 149 150 151 152 153 154 155 156 |
# File 'lib/vedeu/geometry/coordinate.rb', line 145 def x_position(index = 0) if index <= 0 x elsif index > xn_index xn else x_range[index] end end |
#x_range ⇒ Array (private)
Returns an array with all coordinates from x to xn.
219 220 221 |
# File 'lib/vedeu/geometry/coordinate.rb', line 219 def x_range (x...xn).to_a end |
#xn ⇒ Fixnum
Returns the maximum x coordinate for an area.
50 51 52 53 54 55 56 57 58 |
# File 'lib/vedeu/geometry/coordinate.rb', line 50 def xn if width <= 0 0 else x + width end end |
#xn_index ⇒ Fixnum (private)
Returns the maximum x index for an area.
182 183 184 185 186 |
# File 'lib/vedeu/geometry/coordinate.rb', line 182 def xn_index return 0 if x_indices.empty? x_indices.last end |
#y_index(position = y) ⇒ Fixnum
Returns the index for a given y position.
72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/vedeu/geometry/coordinate.rb', line 72 def y_index(position = y) if height <= 0 || position <= y 0 elsif position >= yn yn_index else y_range.index(position) end end |
#y_indices ⇒ Array (private)
Returns the same as #y_range, except as indices of an array.
195 196 197 |
# File 'lib/vedeu/geometry/coordinate.rb', line 195 def y_indices (0...height).to_a end |
#y_position(index = 0) ⇒ Fixnum
Returns the y coordinate for a given index.
121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'lib/vedeu/geometry/coordinate.rb', line 121 def y_position(index = 0) if index <= 0 y elsif index > yn_index yn else y_range[index] end end |
#y_range ⇒ Array (private)
Returns an array with all coordinates from y to yn.
232 233 234 |
# File 'lib/vedeu/geometry/coordinate.rb', line 232 def y_range (y...yn).to_a end |
#yn ⇒ Fixnum
Returns the maximum y coordinate for an area.
32 33 34 35 36 37 38 39 40 |
# File 'lib/vedeu/geometry/coordinate.rb', line 32 def yn if height <= 0 0 else y + height end end |
#yn_index ⇒ Fixnum (private)
Returns the maximum y index for an area.
169 170 171 172 173 |
# File 'lib/vedeu/geometry/coordinate.rb', line 169 def yn_index return 0 if y_indices.empty? y_indices.last end |