Class: Geospatial::Dimension
- Inherits:
-
Object
- Object
- Geospatial::Dimension
- 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
-
#origin ⇒ Object
readonly
Returns the value of attribute origin.
-
#scale ⇒ Object
readonly
Returns the value of attribute scale.
-
#size ⇒ Object
readonly
Returns the value of attribute size.
Class Method Summary collapse
Instance Method Summary collapse
- #*(factor) ⇒ Object
-
#initialize(origin, size, scale = 1.0) ⇒ Dimension
constructor
A new instance of Dimension.
-
#map(value) ⇒ Object
Normalize the value into the range 0..1 and then multiply by scale.
- #max ⇒ Object
- #min ⇒ Object
- #to_s ⇒ Object
- #unmap(value) ⇒ Object
Constructor Details
#initialize(origin, size, scale = 1.0) ⇒ Dimension
Returns a new instance of Dimension.
30 31 32 33 34 |
# File 'lib/geospatial/dimensions.rb', line 30 def initialize(origin, size, scale = 1.0) @origin = origin @size = size @scale = scale end |
Instance Attribute Details
#origin ⇒ Object (readonly)
Returns the value of attribute origin.
48 49 50 |
# File 'lib/geospatial/dimensions.rb', line 48 def origin @origin end |
#scale ⇒ Object (readonly)
Returns the value of attribute scale.
50 51 52 |
# File 'lib/geospatial/dimensions.rb', line 50 def scale @scale end |
#size ⇒ Object (readonly)
Returns the value of attribute size.
49 50 51 |
# File 'lib/geospatial/dimensions.rb', line 49 def size @size end |
Class Method Details
.map(min, max, steps) ⇒ Object
26 27 28 |
# File 'lib/geospatial/dimensions.rb', line 26 def self.map(min, max, steps) self.new(min, max-min, steps) end |
Instance Method Details
#*(factor) ⇒ Object
44 45 46 |
# File 'lib/geospatial/dimensions.rb', line 44 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.
61 62 63 |
# File 'lib/geospatial/dimensions.rb', line 61 def map(value) ((value - @origin).to_f / @size) * @scale end |
#max ⇒ Object
56 57 58 |
# File 'lib/geospatial/dimensions.rb', line 56 def max @origin + @size end |
#min ⇒ Object
52 53 54 |
# File 'lib/geospatial/dimensions.rb', line 52 def min @origin end |
#to_s ⇒ Object
36 37 38 39 40 41 42 |
# File 'lib/geospatial/dimensions.rb', line 36 def to_s if @scale != 1.0 "(#{min}..#{max} * #{@scale})" else "(#{min}..#{max})" end end |
#unmap(value) ⇒ Object
65 66 67 |
# File 'lib/geospatial/dimensions.rb', line 65 def unmap(value) @origin + (value / @scale) * @size end |