Class: GeoTreeModule::DataPoint
- Inherits:
-
Object
- Object
- GeoTreeModule::DataPoint
- Defined in:
- lib/geotree/datapoint.rb
Overview
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).
Constant Summary collapse
- @@nextRndName =
200
Instance Attribute Summary collapse
-
#loc ⇒ Object
Returns the value of attribute loc.
-
#name ⇒ Object
Returns the value of attribute name.
-
#weight ⇒ Object
Returns the value of attribute weight.
Class Method Summary collapse
- .match(a, b) ⇒ Object
- .name_list(dp_list) ⇒ Object
-
.rnd ⇒ Object
Construct a random point, one with a unique name (assumes no other process is generating point names).
- .rnd_many(count) ⇒ Object
Instance Method Summary collapse
- #flip ⇒ Object
-
#initialize(name, weight, loc) ⇒ DataPoint
constructor
A new instance of DataPoint.
- #inspect ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(name, weight, loc) ⇒ DataPoint
Returns a new instance of DataPoint.
22 23 24 25 26 |
# File 'lib/geotree/datapoint.rb', line 22 def initialize(name,weight,loc) @name = name @loc = loc @weight = weight end |
Instance Attribute Details
#loc ⇒ Object
Returns the value of attribute loc.
20 21 22 |
# File 'lib/geotree/datapoint.rb', line 20 def loc @loc end |
#name ⇒ Object
Returns the value of attribute name.
20 21 22 |
# File 'lib/geotree/datapoint.rb', line 20 def name @name end |
#weight ⇒ Object
Returns the value of attribute weight.
20 21 22 |
# File 'lib/geotree/datapoint.rb', line 20 def weight @weight end |
Class Method Details
.match(a, b) ⇒ Object
61 62 63 |
# 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) ⇒ Object
57 58 59 |
# File 'lib/geotree/datapoint.rb', line 57 def self.name_list(dp_list) dp_list.map{|x| x.name}.sort end |
.rnd ⇒ Object
Construct a random point, one with a unique name (assumes no other process is generating point names)
43 44 45 46 47 48 49 |
# 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) ⇒ Object
51 52 53 54 55 |
# File 'lib/geotree/datapoint.rb', line 51 def self.rnd_many(count) a = [] count.times{a << self.rnd} a end |
Instance Method Details
#flip ⇒ Object
28 29 30 |
# File 'lib/geotree/datapoint.rb', line 28 def flip DataPoint.new(@name,@weight,@loc.flip) end |
#inspect ⇒ Object
36 37 38 |
# File 'lib/geotree/datapoint.rb', line 36 def inspect to_s end |
#to_s ⇒ Object
32 33 34 |
# File 'lib/geotree/datapoint.rb', line 32 def to_s "[##{name}: #{loc} w#{weight}]" end |