Class: Geospatial::Index

Inherits:
Object
  • Object
show all
Defined in:
lib/geospatial/index.rb

Overview

This class represents a n-dimentional index.

Direct Known Subclasses

HilbertIndex, OrdinalIndex

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(axes, bits) ⇒ Index

Returns a new instance of Index.



29
30
31
32
# File 'lib/geospatial/index.rb', line 29

def initialize(axes, bits)
	@axes = axes
	@bits = bits
end

Instance Attribute Details

#axesObject (readonly)

Returns the value of attribute axes.



38
39
40
# File 'lib/geospatial/index.rb', line 38

def axes
  @axes
end

#bitsObject (readonly)

Returns the value of attribute bits.



39
40
41
# File 'lib/geospatial/index.rb', line 39

def bits
  @bits
end

Class Method Details

.from_integral(integral, width, bits) ⇒ Object



34
35
36
# File 'lib/geospatial/index.rb', line 34

def self.from_integral(integral, width, bits)
	self.new(Interleave.unmap(integral, width), bits)
end

Instance Method Details

#&(mask) ⇒ Object



41
42
43
# File 'lib/geospatial/index.rb', line 41

def & mask
	self.class.new(axes.collect{|axis| axis & mask}, @bits)
end

#bit_lengthObject



57
58
59
# File 'lib/geospatial/index.rb', line 57

def bit_length
	@axes.size * @bits
end

#eql?(other) ⇒ Boolean

Returns:

  • (Boolean)


49
50
51
# File 'lib/geospatial/index.rb', line 49

def eql?(other)
	self.class.eql?(other.class) and @axes.eql?(other.axes) and @bits.eql?(other.bits)
end

#hashObject



45
46
47
# File 'lib/geospatial/index.rb', line 45

def hash
	@axes.hash
end

#inspectObject



61
62
63
64
# File 'lib/geospatial/index.rb', line 61

def inspect
	i = self.to_i
	"\#<#{self.class}[#{@bits}] 0b#{i.to_s(2).rjust(bit_length, '0')} (#{i}) #{@axes.inspect}>"
end

#to_iObject



53
54
55
# File 'lib/geospatial/index.rb', line 53

def to_i
	Interleave.map(@axes, @bits)
end