bribera-rubyvor 0.0.6 → 0.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/History.txt CHANGED
@@ -1,3 +1,9 @@
1
+ === 0.0.7 / 2008-12-12
2
+
3
+ * Bugfix: there are cases where performing a Delaunay triangulation on a set of points will not yield a complete nearest neighbor graph. This causes computation of the minimum spanning tree and clustering to fail for these nodes (they always appear as disconnected from the main graph).
4
+
5
+ * To fix this, the nn_graph function now treats any point that is excluded from Delaunay triangulation as having *all* other points as nearest neighbors. This is a naive approach, but is a good fix while a more efficient solution is considered.
6
+
1
7
  === 0.0.6 / 2008-12-11
2
8
 
3
9
  * Implementation of cluster_by_size to partition points into N clusters.
data/Manifest.txt CHANGED
@@ -12,12 +12,13 @@ ext/output.c
12
12
  ext/rb_cComputation.c
13
13
  ext/rb_cPoint.c
14
14
  ext/rb_cPriorityQueue.c
15
- ext/ruby_vor.c
16
- ext/ruby_vor.h
15
+ ext/ruby_vor_c.c
16
+ ext/ruby_vor_c.h
17
17
  ext/vdefs.h
18
18
  ext/voronoi.c
19
19
  lib/ruby_vor.rb
20
20
  lib/ruby_vor/computation.rb
21
+ lib/ruby_vor/geo_ruby_extensions.rb
21
22
  lib/ruby_vor/point.rb
22
23
  lib/ruby_vor/priority_queue.rb
23
24
  lib/ruby_vor/version.rb
data/Rakefile CHANGED
@@ -19,7 +19,7 @@ desc "Compile extensions"
19
19
  task :compile => EXT
20
20
  task :test => :compile
21
21
 
22
- file EXT => ['ext/extconf.rb', 'ext/ruby_vor.c'] do
22
+ file EXT => ['ext/extconf.rb', 'ext/ruby_vor_c.c'] do
23
23
  Dir.chdir 'ext' do
24
24
  ruby 'extconf.rb'
25
25
  sh 'make'
data/ext/extconf.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  require 'mkmf'
2
- dir_config('ruby_vor')
3
- create_makefile('ruby_vor')
2
+ dir_config('ruby_vor_c')
3
+ create_makefile('ruby_vor_c')
@@ -1,6 +1,6 @@
1
1
  #include <ruby.h>
2
2
  #include <vdefs.h>
3
- #include <ruby_vor.h>
3
+ #include <ruby_vor_c.h>
4
4
  #include <stdio.h>
5
5
  #include <stdlib.h>
6
6
 
@@ -189,7 +189,7 @@ RubyVor_minimum_spanning_tree(int argc, VALUE *argv, VALUE self)
189
189
  VALUE
190
190
  RubyVor_nn_graph(VALUE self)
191
191
  {
192
- long i;
192
+ long i, j;
193
193
  VALUE dtRaw, graph, points, * dtPtr, * tripletPtr, * graphPtr;
194
194
 
195
195
  graph = rb_iv_get(self, "@nn_graph");
@@ -222,8 +222,20 @@ RubyVor_nn_graph(VALUE self)
222
222
  rb_ary_push(graphPtr[FIX2INT(tripletPtr[2])], tripletPtr[1]);
223
223
  }
224
224
 
225
- for (i = 0; i < RARRAY(graph)->len; i++)
226
- rb_funcall(graphPtr[i], rb_intern("uniq!"), 0);
225
+ for (i = 0; i < RARRAY(graph)->len; i++) {
226
+ if (RARRAY(graphPtr[i])->len < 1) {
227
+ // No valid triangles touched this node -- include *all* possible neighbors
228
+ for(j = 0; j < RARRAY(points)->len; j++) {
229
+ if (j != i) {
230
+ rb_ary_push(graphPtr[i], INT2FIX(j));
231
+ if (RARRAY(graphPtr[j])->len > 0 && !rb_ary_includes(graphPtr[j], INT2FIX(i)))
232
+ rb_ary_push(graphPtr[j], INT2FIX(i));
233
+ }
234
+ }
235
+ } else {
236
+ rb_funcall(graphPtr[i], rb_intern("uniq!"), 0);
237
+ }
238
+ }
227
239
 
228
240
  rb_iv_set(self, "@nn_graph", graph);
229
241
 
data/ext/rb_cPoint.c CHANGED
@@ -1,6 +1,6 @@
1
1
  #include <ruby.h>
2
2
  #include <vdefs.h>
3
- #include <ruby_vor.h>
3
+ #include <ruby_vor_c.h>
4
4
  #include <math.h>
5
5
 
6
6
  /*
@@ -1,6 +1,6 @@
1
1
  #include <ruby.h>
2
2
  #include <vdefs.h>
3
- #include <ruby_vor.h>
3
+ #include <ruby_vor_c.h>
4
4
 
5
5
  //
6
6
  // Instance methods for RubyVor::VDDT::PriorityQueue
@@ -1,12 +1,12 @@
1
1
  #include <ruby.h>
2
2
  #include <vdefs.h>
3
- #include <ruby_vor.h>
3
+ #include <ruby_vor_c.h>
4
4
 
5
5
  //
6
6
  // Extension initialization
7
7
  //
8
8
  void
9
- Init_ruby_vor(void)
9
+ Init_ruby_vor_c(void)
10
10
  {
11
11
  //
12
12
  // Set up our Modules and Class.
File without changes
@@ -0,0 +1,15 @@
1
+ if require 'geo_ruby'
2
+ # Let us call uniq on a set of Points or use one as a Hash key.
3
+ module GeoRuby
4
+ module SimpleFeatures
5
+ class Point < Geometry
6
+ def eql?(other)
7
+ self == other
8
+ end
9
+ def hash
10
+ [x,y,z,m].hash
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -1,8 +1,17 @@
1
1
  module RubyVor
2
2
  class Point
3
- attr_accessor :x, :y
3
+ attr_reader :x, :y
4
4
  def initialize(x=0.0,y=0.0)
5
5
  @x = x; @y = y
6
6
  end
7
+
8
+ def ==(p)
9
+ @x == p.x && @y == p.y
10
+ end
11
+ alias :eql? :==
12
+ def hash
13
+ [x.to_f, y.to_f].hash
14
+ end
15
+
7
16
  end
8
17
  end
@@ -1,3 +1,3 @@
1
1
  module RubyVor
2
- VERSION = '0.0.6'
2
+ VERSION = '0.0.7'
3
3
  end
data/lib/ruby_vor.rb CHANGED
@@ -5,9 +5,10 @@ require 'ruby_vor/version'
5
5
  require 'ruby_vor/point'
6
6
  require 'ruby_vor/priority_queue'
7
7
  require 'ruby_vor/computation'
8
+ require 'ruby_vor/geo_ruby_extensions'
8
9
 
9
10
  # Require ruby_vor.so last to clobber old from_points
10
- require 'ruby_vor.so'
11
+ require 'ruby_vor_c.so'
11
12
 
12
13
  # DOC HERE
13
14
  module RubyVor
data/rubyvor.gemspec CHANGED
@@ -2,16 +2,16 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{rubyvor}
5
- s.version = "0.0.6"
5
+ s.version = "0.0.7"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Brendan Ribera"]
9
- s.date = %q{2008-12-11}
9
+ s.date = %q{2008-12-12}
10
10
  s.description = %q{RubyVor provides efficient computation of Voronoi diagrams and Delaunay triangulation for a set of Ruby points. It is intended to function as a complemenet to GeoRuby. These structures can be used to compute a nearest-neighbor graph for a set of points. This graph can in turn be used for proximity-based clustering of the input points.}
11
11
  s.email = ["brendan.ribera+rubyvor@gmail.com"]
12
12
  s.extensions = ["ext/extconf.rb"]
13
13
  s.extra_rdoc_files = ["History.txt", "Manifest.txt", "README.txt"]
14
- s.files = ["History.txt", "Manifest.txt", "README.txt", "Rakefile", "ext/Doc", "ext/edgelist.c", "ext/extconf.rb", "ext/geometry.c", "ext/heap.c", "ext/memory.c", "ext/output.c", "ext/rb_cComputation.c", "ext/rb_cPoint.c", "ext/rb_cPriorityQueue.c", "ext/ruby_vor.c", "ext/ruby_vor.h", "ext/vdefs.h", "ext/voronoi.c", "lib/ruby_vor.rb", "lib/ruby_vor/computation.rb", "lib/ruby_vor/point.rb", "lib/ruby_vor/priority_queue.rb", "lib/ruby_vor/version.rb", "rubyvor.gemspec", "test/test_computation.rb", "test/test_priority_queue.rb", "test/test_voronoi_interface.rb"]
14
+ s.files = ["History.txt", "Manifest.txt", "README.txt", "Rakefile", "ext/Doc", "ext/edgelist.c", "ext/extconf.rb", "ext/geometry.c", "ext/heap.c", "ext/memory.c", "ext/output.c", "ext/rb_cComputation.c", "ext/rb_cPoint.c", "ext/rb_cPriorityQueue.c", "ext/ruby_vor_c.c", "ext/ruby_vor_c.h", "ext/vdefs.h", "ext/voronoi.c", "lib/ruby_vor.rb", "lib/ruby_vor/computation.rb", "lib/ruby_vor/geo_ruby_extensions.rb", "lib/ruby_vor/point.rb", "lib/ruby_vor/priority_queue.rb", "lib/ruby_vor/version.rb", "rubyvor.gemspec", "test/test_computation.rb", "test/test_priority_queue.rb", "test/test_voronoi_interface.rb"]
15
15
  s.has_rdoc = true
16
16
  s.homepage = %q{http://github.com/bribera/rubyvor}
17
17
  s.rdoc_options = ["--main", "README.txt"]
@@ -34,6 +34,10 @@ class TestComputation < MiniTest::Unit::TestCase
34
34
  [4, 5, 6, 8], # 7
35
35
  [0, 2, 3, 5, 6, 7], # 8
36
36
  ]
37
+
38
+ comp.nn_graph.each_with_index do |neighbors,i|
39
+ refute_empty neighbors, "@nn_graph returned empty neighbors for node #{i}"
40
+ end
37
41
 
38
42
  assert_equal comp.nn_graph.map{|v| v.sort}.sort, \
39
43
  expected_graph.map{|v| v.sort}.sort
@@ -149,11 +153,36 @@ class TestComputation < MiniTest::Unit::TestCase
149
153
 
150
154
 
151
155
  def test_duplicate_points
152
- comp = RubyVor::VDDT::Computation.from_points([RubyVor::Point.new(1,1), RubyVor::Point.new(1,1), RubyVor::Point.new(2,3), RubyVor::Point.new(1,1), RubyVor::Point.new(4,0)])
153
- refute_equal comp.nn_graph, nil
154
- refute_equal comp.minimum_spanning_tree, nil
155
- refute_equal comp.cluster_by_distance(3), nil
156
- refute_equal comp.cluster_by_size([2]), nil
156
+ comp = RubyVor::VDDT::Computation.from_points([
157
+ RubyVor::Point.new(2,3), # 0
158
+ RubyVor::Point.new(1,1), # 1
159
+ RubyVor::Point.new(1,1), # 2
160
+ RubyVor::Point.new(1,1), # 3
161
+ RubyVor::Point.new(1,1), # 4
162
+ RubyVor::Point.new(1,1), # 5
163
+ RubyVor::Point.new(1,1), # 6
164
+ RubyVor::Point.new(1,1), # 7
165
+ RubyVor::Point.new(1,1), # 8
166
+ RubyVor::Point.new(4,10), # 9
167
+ RubyVor::Point.new(4,10.0), # 10
168
+ RubyVor::Point.new(4.0,10.0), # 11
169
+ RubyVor::Point.new(4.0,10.0), # 12
170
+ ])
171
+ comp.nn_graph.each_with_index do |neighbors,i|
172
+ refute_empty neighbors, "@nn_graph returned empty neighbors for node #{i}"
173
+ end
174
+
175
+ assert_equal [[0], [1,2,3,4,5,6,7,8], [9,10,11,12]], \
176
+ comp.cluster_by_distance(1).map{|cl| cl.sort}.sort
177
+
178
+ assert_equal [[0,1,2,3,4,5,6,7,8], [9,10,11,12]], \
179
+ comp.cluster_by_distance(5).map{|cl| cl.sort}.sort
180
+
181
+ assert_equal [[0,1,2,3,4,5,6,7,8,9,10,11,12]], \
182
+ comp.cluster_by_distance(10).map{|cl| cl.sort}.sort
183
+
184
+ assert_equal [[0,1,2,3,4,5,6,7,8], [9,10,11,12]], \
185
+ comp.cluster_by_size([2])[2].map{|cl| cl.sort}.sort
157
186
  end
158
187
 
159
188
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bribera-rubyvor
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brendan Ribera
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-12-11 00:00:00 -08:00
12
+ date: 2008-12-12 00:00:00 -08:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -47,12 +47,13 @@ files:
47
47
  - ext/rb_cComputation.c
48
48
  - ext/rb_cPoint.c
49
49
  - ext/rb_cPriorityQueue.c
50
- - ext/ruby_vor.c
51
- - ext/ruby_vor.h
50
+ - ext/ruby_vor_c.c
51
+ - ext/ruby_vor_c.h
52
52
  - ext/vdefs.h
53
53
  - ext/voronoi.c
54
54
  - lib/ruby_vor.rb
55
55
  - lib/ruby_vor/computation.rb
56
+ - lib/ruby_vor/geo_ruby_extensions.rb
56
57
  - lib/ruby_vor/point.rb
57
58
  - lib/ruby_vor/priority_queue.rb
58
59
  - lib/ruby_vor/version.rb