class GeoTreeModule::DataPoint

Represents a point to be stored in a GeoTree.

A point has these fields.


A name, which is a unique integer identifier. This could be, e.g.,

the id of a larger database record associated with the point.

A position, stored as a Loc object (two integers, x and y).

A weight. This is an integer, and is unused by the GeoTree except that

the MultiTree class assumes that the lower 4 bits hold the point's
detail level (a lower value means the point is less likely to show
up at lower detail levels).

Attributes

loc[RW]
name[RW]
weight[RW]

Public Class Methods

match(a, b) click to toggle source
# File lib/geotree/datapoint.rb, line 61
def self.match(a, b)
  a.name == b.name && a.loc.x == b.loc.x && a.loc.y == b.loc.y
end
name_list(dp_list) click to toggle source
# File lib/geotree/datapoint.rb, line 57
def self.name_list(dp_list)
  dp_list.map{|x| x.name}.sort
end
new(name,weight,loc) click to toggle source
# File lib/geotree/datapoint.rb, line 22
def initialize(name,weight,loc)
  @name = name
  @loc = loc
  @weight = weight
end
rnd() click to toggle source

Construct a random point, one with a unique name (assumes no other process is generating point names)

# File lib/geotree/datapoint.rb, line 43
def self.rnd
  wt = (rand() * rand() * MAX_POINT_WEIGHT).to_i
  x = rand(1000)
  y = rand(1000)
  @@nextRndName += 1
  DataPoint.new(@@nextRndName, wt, Loc.new(x,y))
end
rnd_many(count) click to toggle source
# File lib/geotree/datapoint.rb, line 51
def self.rnd_many(count)
  a = []
  count.times{a << self.rnd}
  a
end

Public Instance Methods

flip() click to toggle source
# File lib/geotree/datapoint.rb, line 28
def flip
  DataPoint.new(@name,@weight,@loc.flip)
end
inspect() click to toggle source
# File lib/geotree/datapoint.rb, line 36
def inspect
  to_s
end
to_s() click to toggle source
# File lib/geotree/datapoint.rb, line 32
def to_s
  "[##{name}: #{loc} w#{weight}]"
end