Class: Vedeu::IndexPosition

Inherits:
Object
  • Object
show all
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

Constructor Details

#initialize(iy, ix, oy = 1, ox = 1) ⇒ Vedeu::IndexPosition

Returns a new instance of Vedeu::IndexPosition.

Parameters:

  • iy (Fixnum)
  • ix (Fixnum)
  • oy (Fixnum) (defaults to: 1)
  • ox (Fixnum) (defaults to: 1)


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

Parameters:

  • iy (Fixnum)
  • ix (Fixnum)
  • oy (Fixnum) (defaults to: 1)
  • ox (Fixnum) (defaults to: 1)

Returns:



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

Returns:



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.

Parameters:

Returns:

  • (Boolean)


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

#ixFixnum (private)

Returns:

  • (Fixnum)


67
68
69
# File 'lib/vedeu/geometry/index_position.rb', line 67

def ix
  @_ix ||= (@ix <= 0) ? 0 : @ix
end

#iyFixnum (private)

Returns:

  • (Fixnum)


62
63
64
# File 'lib/vedeu/geometry/index_position.rb', line 62

def iy
  @_iy ||= (@iy <= 0) ? 0 : @iy
end

#oxFixnum (private)

Returns:

  • (Fixnum)


77
78
79
# File 'lib/vedeu/geometry/index_position.rb', line 77

def ox
  @_ox ||= (@ox <= 1) ? 1 : @ox
end

#oyFixnum (private)

Returns:

  • (Fixnum)


72
73
74
# File 'lib/vedeu/geometry/index_position.rb', line 72

def oy
  @_oy ||= (@oy <= 1) ? 1 : @oy
end

#xFixnum Also known as: last

Returns the x coordinate.

Returns:

  • (Fixnum)


54
55
56
# File 'lib/vedeu/geometry/index_position.rb', line 54

def x
  (ix <= 0) ? ox : (ix + ox)
end

#yFixnum Also known as: first

Returns the y coordinate.

Returns:

  • (Fixnum)


46
47
48
# File 'lib/vedeu/geometry/index_position.rb', line 46

def y
  (iy <= 0) ? oy : (iy + oy)
end