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 ⇒ Fixnum readonly
- #name ⇒ String readonly protected
- #width ⇒ Fixnum readonly
- #x ⇒ Fixnum readonly
- #y ⇒ Fixnum readonly
Instance Method Summary collapse
-
#initialize(height, width, x, y) ⇒ Vedeu::Coordinate
constructor
Returns a new instance of Vedeu::Coordinate.
-
#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_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
Returns a new instance of Vedeu::Coordinate.
29 30 31 32 33 34 |
# File 'lib/vedeu/geometry/coordinate.rb', line 29 def initialize(height, width, x, y) @height = height @width = width @x = x @y = y end |
Instance Attribute Details
#height ⇒ Fixnum (readonly)
8 9 10 |
# File 'lib/vedeu/geometry/coordinate.rb', line 8 def height @height end |
#name ⇒ String (readonly, protected)
124 125 126 |
# File 'lib/vedeu/geometry/coordinate.rb', line 124 def name @name end |
#width ⇒ Fixnum (readonly)
12 13 14 |
# File 'lib/vedeu/geometry/coordinate.rb', line 12 def width @width end |
#x ⇒ Fixnum (readonly)
16 17 18 |
# File 'lib/vedeu/geometry/coordinate.rb', line 16 def x @x end |
#y ⇒ Fixnum (readonly)
20 21 22 |
# File 'lib/vedeu/geometry/coordinate.rb', line 20 def y @y end |
Instance Method Details
#x_indices ⇒ Array (private)
Returns the same as #x_range, except as indices of an array.
172 173 174 |
# File 'lib/vedeu/geometry/coordinate.rb', line 172 def x_indices (0...width).to_a end |
#x_position(index = 0) ⇒ Fixnum
Returns the x coordinate for a given index.
107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/vedeu/geometry/coordinate.rb', line 107 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.
185 186 187 |
# File 'lib/vedeu/geometry/coordinate.rb', line 185 def x_range (x...xn).to_a end |
#xn ⇒ Fixnum
Returns the maximum x coordinate for an area.
62 63 64 65 66 67 68 69 70 |
# File 'lib/vedeu/geometry/coordinate.rb', line 62 def xn if width <= 0 0 else x + width end end |
#xn_index ⇒ Fixnum (private)
Returns the maximum x index for an area.
148 149 150 151 152 |
# File 'lib/vedeu/geometry/coordinate.rb', line 148 def xn_index return 0 if x_indices.empty? x_indices.last end |
#y_indices ⇒ Array (private)
Returns the same as #y_range, except as indices of an array.
161 162 163 |
# File 'lib/vedeu/geometry/coordinate.rb', line 161 def y_indices (0...height).to_a end |
#y_position(index = 0) ⇒ Fixnum
Returns the y coordinate for a given index.
83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/vedeu/geometry/coordinate.rb', line 83 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.
198 199 200 |
# File 'lib/vedeu/geometry/coordinate.rb', line 198 def y_range (y...yn).to_a end |
#yn ⇒ Fixnum
Returns the maximum y coordinate for an area.
44 45 46 47 48 49 50 51 52 |
# File 'lib/vedeu/geometry/coordinate.rb', line 44 def yn if height <= 0 0 else y + height end end |
#yn_index ⇒ Fixnum (private)
Returns the maximum y index for an area.
135 136 137 138 139 |
# File 'lib/vedeu/geometry/coordinate.rb', line 135 def yn_index return 0 if y_indices.empty? y_indices.last end |