Class: Geospatial::Dimension

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

Overview

An integral dimension which maps a continuous space into an integral space. The scale is the maximum integral unit.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(origin, size, scale = 1.0) ⇒ Dimension

Returns a new instance of Dimension.



26
27
28
29
30
# File 'lib/geospatial/dimensions.rb', line 26

def initialize(origin, size, scale = 1.0)
	@origin = origin
	@size = size
	@scale = scale
end

Instance Attribute Details

#originObject (readonly)

Returns the value of attribute origin.



44
45
46
# File 'lib/geospatial/dimensions.rb', line 44

def origin
  @origin
end

#scaleObject (readonly)

Returns the value of attribute scale.



46
47
48
# File 'lib/geospatial/dimensions.rb', line 46

def scale
  @scale
end

#sizeObject (readonly)

Returns the value of attribute size.



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

def size
  @size
end

Instance Method Details

#*(factor) ⇒ Object



40
41
42
# File 'lib/geospatial/dimensions.rb', line 40

def * factor
	self.class.new(@origin, @size, @scale * factor)
end

#map(value) ⇒ Object

Normalize the value into the range 0..1 and then multiply by scale.



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

def map(value)
	((value - @origin).to_f / @size) * @scale
end

#maxObject



52
53
54
# File 'lib/geospatial/dimensions.rb', line 52

def max
	@origin + @size
end

#minObject



48
49
50
# File 'lib/geospatial/dimensions.rb', line 48

def min
	@origin
end

#to_sObject



32
33
34
35
36
37
38
# File 'lib/geospatial/dimensions.rb', line 32

def to_s
	if @scale != 1.0
		"(#{min}..#{max} * #{@scale})"
	else
		"(#{min}..#{max})"
	end
end

#unmap(value) ⇒ Object



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

def unmap(value)
	@origin + (value / @scale) * @size
end