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.
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.
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
#origin ⇒ Object (readonly)
Returns the value of attribute origin.
44 45 46 |
# File 'lib/geospatial/dimensions.rb', line 44 def origin @origin end |
#scale ⇒ Object (readonly)
Returns the value of attribute scale.
46 47 48 |
# File 'lib/geospatial/dimensions.rb', line 46 def scale @scale end |
#size ⇒ Object (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 |
#max ⇒ Object
52 53 54 |
# File 'lib/geospatial/dimensions.rb', line 52 def max @origin + @size end |
#min ⇒ Object
48 49 50 |
# File 'lib/geospatial/dimensions.rb', line 48 def min @origin end |
#to_s ⇒ Object
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 |