class Geospatial::Histogram

This location is specifically relating to a WGS84 coordinate on Earth.

Attributes

bins[R]
count[R]
items[R]
offset[R]
scale[R]

Public Class Methods

new(min: 0, max: 1, scale: 0.1, items: true) click to toggle source
# File lib/geospatial/histogram.rb, line 10
def initialize(min: 0, max: 1, scale: 0.1, items: true)
        @min = min
        @max = max
        @scale = scale
        
        @count = 0
        
        if items
                @items = Hash.new{|h,k| h[k] = Array.new}
        end
        
        @size = ((@max - @min) / @scale).ceil
        @bins = [0] * @size
        @offset = 0
        @scale = scale
end

Public Instance Methods

[](index) click to toggle source
# File lib/geospatial/histogram.rb, line 41
def [] index
        @bins[index]
end
add(value, amount = 1, item: nil) { |index, value| ... } click to toggle source
# File lib/geospatial/histogram.rb, line 57
def add(value, amount = 1, item: nil)
        index = map(value).floor % @size
        
        if !block_given? or yield(index, value)
                @count += 1
                @bins[index] += amount
                
                if @items and item
                        @items[index] << item
                end
        end
        
        return index
end
bins=(bins) click to toggle source
# File lib/geospatial/histogram.rb, line 35
def bins= bins
        raise ArgumentError, "Incorrect length" unless bins.size == @size
        
        @bins = bins
end
each() { |unmap(index), value| ... } click to toggle source
# File lib/geospatial/histogram.rb, line 82
def each
        return to_enum unless block_given?
        
        @bins.each_with_index do |value, index|
                yield unmap(index), value
        end
end
inspect() click to toggle source
# File lib/geospatial/histogram.rb, line 72
def inspect
        buffer = String.new("\#<#{self.class}")
        
        @bins.each_with_index do |bin, index|
                buffer << " #{unmap(index)}: #{bin}"
        end
        
        buffer << ">"
end
map(value) click to toggle source
# File lib/geospatial/histogram.rb, line 49
def map(value)
        ((value - @min) / @scale)
end
peaks() click to toggle source
# File lib/geospatial/histogram.rb, line 90
def peaks
        Peaks.new(self)
end
size() click to toggle source
# File lib/geospatial/histogram.rb, line 45
def size
        @bins.size
end
unmap(index) click to toggle source
# File lib/geospatial/histogram.rb, line 53
def unmap(index)
        @min + (index * @scale)
end