module Tsuga::Model::Cluster::ClassMethods
Public Instance Methods
build_from(depth, other)
click to toggle source
Cluster
factory. other
is either a Cluster
or a Record
FIXME: there's a potential for overflow here on large datasets on the sum- and sum-of-squares fields. it can be mitigated by using double-precision fields, or calculating sums only on the children (instead of the subtree)
# File lib/tsuga/model/cluster.rb, line 97 def build_from(depth, other) c = new() c.depth = depth c.lat = other.lat c.lng = other.lng c.children_ids = [other.id] c.children_type = other.class.name case other when Cluster c.weight = other.weight c.sum_lng = other.sum_lng c.sum_lat = other.sum_lat c.ssq_lng = other.ssq_lng c.ssq_lat = other.ssq_lat else c.weight = 1 c.sum_lng = other.lng c.sum_lat = other.lat c.ssq_lng = other.lng ** 2 c.ssq_lat = other.lat ** 2 end c.geohash # force geohash calculation return c end