Module: StairCar::Indicies

Included in:
PMatrix, UMatrix
Defined in:
lib/stair_car/shared/indicies.rb

Instance Method Summary collapse

Instance Method Details

#convert_indicies(index, max_index) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/stair_car/shared/indicies.rb', line 4

def convert_indicies(index, max_index)
  if index.is_a?(Fixnum)
    if index < 0
      return [max_index + index]
    else
      return [index]
    end
  elsif index.is_a?(Array)
    # Map to indicies and convert into one array
    return index.map {|i| convert_indicies(i, max_index) }.flatten
  elsif index.is_a?(Range)
    if index.end < 0
      start = index.begin
      new_end = max_index + index.end

      # Recreate with the end value
      if index.exclude_end?
        index = (start...new_end)
      else
        index = (start..new_end)
      end
    end

    return index.to_a
  elsif index.is_a?(NilClass)
    return nil.to_java#convert_indicies(0...max_index, max_index)
  end
end