Class: Vedeu::IndexPosition
- Inherits:
-
Object
- Object
- Vedeu::IndexPosition
- Defined in:
- lib/vedeu/geometry/index_position.rb
Overview
Converts an index into a position for the terminal.
When the optional offset ‘oy` and `ox` params are given, the they are used for the starting position.
Class Method Summary collapse
Instance Method Summary collapse
- #[] ⇒ Vedeu::Position
-
#eql?(other) ⇒ Boolean
(also: #==)
An object is equal when its values are the same.
-
#initialize(iy, ix, oy = 1, ox = 1) ⇒ Vedeu::IndexPosition
constructor
Returns a new instance of Vedeu::IndexPosition.
- #ix ⇒ Fixnum private
- #iy ⇒ Fixnum private
- #ox ⇒ Fixnum private
- #oy ⇒ Fixnum private
-
#x ⇒ Fixnum
(also: #last)
Returns the x coordinate.
-
#y ⇒ Fixnum
(also: #first)
Returns the y coordinate.
Constructor Details
#initialize(iy, ix, oy = 1, ox = 1) ⇒ Vedeu::IndexPosition
Returns a new instance of Vedeu::IndexPosition.
22 23 24 25 26 27 |
# File 'lib/vedeu/geometry/index_position.rb', line 22 def initialize(iy, ix, oy = 1, ox = 1) @iy = iy @ix = ix @oy = oy @ox = ox end |
Class Method Details
.[](iy, ix, oy = 1, ox = 1) ⇒ Vedeu::Position
11 12 13 |
# File 'lib/vedeu/geometry/index_position.rb', line 11 def self.[](iy, ix, oy = 1, ox = 1) new(iy, ix, oy, ox).[] end |
Instance Method Details
#[] ⇒ Vedeu::Position
30 31 32 |
# File 'lib/vedeu/geometry/index_position.rb', line 30 def [] Vedeu::Position.new(y, x) end |
#eql?(other) ⇒ Boolean Also known as: ==
An object is equal when its values are the same.
38 39 40 |
# File 'lib/vedeu/geometry/index_position.rb', line 38 def eql?(other) self.class == other.class && (x == other.x && y == other.y) end |
#ix ⇒ Fixnum (private)
67 68 69 |
# File 'lib/vedeu/geometry/index_position.rb', line 67 def ix @_ix ||= (@ix <= 0) ? 0 : @ix end |
#iy ⇒ Fixnum (private)
62 63 64 |
# File 'lib/vedeu/geometry/index_position.rb', line 62 def iy @_iy ||= (@iy <= 0) ? 0 : @iy end |
#ox ⇒ Fixnum (private)
77 78 79 |
# File 'lib/vedeu/geometry/index_position.rb', line 77 def ox @_ox ||= (@ox <= 1) ? 1 : @ox end |
#oy ⇒ Fixnum (private)
72 73 74 |
# File 'lib/vedeu/geometry/index_position.rb', line 72 def oy @_oy ||= (@oy <= 1) ? 1 : @oy end |
#x ⇒ Fixnum Also known as: last
Returns the x coordinate.
54 55 56 |
# File 'lib/vedeu/geometry/index_position.rb', line 54 def x (ix <= 0) ? ox : (ix + ox) end |
#y ⇒ Fixnum Also known as: first
Returns the y coordinate.
46 47 48 |
# File 'lib/vedeu/geometry/index_position.rb', line 46 def y (iy <= 0) ? oy : (iy + oy) end |