bribera-rubyvor 0.0.2

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.
@@ -0,0 +1,22 @@
1
+ module RubyVor
2
+ module VDDT
3
+ class Decomposition
4
+ attr_reader :voronoi_diagram_raw, :delaunay_triangulation_raw
5
+ def initialize(vd_raw=[], dt_raw=[])
6
+ @voronoi_diagram_raw = vd_raw
7
+ @delaunay_triangulation_raw = dt_raw
8
+ end
9
+
10
+ private
11
+
12
+ def voronoi_diagram_raw=(v)
13
+ @voronoi_diagram_raw = v
14
+ end
15
+
16
+ def delaunay_triangulation_raw=(v)
17
+ @delaunay_triangulation_raw = v
18
+ end
19
+
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,19 @@
1
+ module RubyVor
2
+ class Point
3
+ attr_accessor :x, :y
4
+ def initialize(x=0.0,y=0.0)
5
+ @x = x
6
+ @y = y
7
+ end
8
+
9
+ class << self
10
+ def test_large
11
+ a = []
12
+ 1000000.times {
13
+ a << new(100000.0 * rand, 100000.0 * rand)
14
+ }
15
+ a
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,3 @@
1
+ module RubyVor
2
+ VERSION = '0.0.2'
3
+ end
data/lib/ruby_vor.rb ADDED
@@ -0,0 +1,13 @@
1
+ $:.unshift File.dirname(__FILE__)
2
+ $:.unshift File.join(File.dirname(__FILE__), '..', 'ext')
3
+ require 'voronoi_interface.so'
4
+ require 'ruby_vor/version'
5
+ require 'ruby_vor/point'
6
+ require 'ruby_vor/decomposition'
7
+
8
+ module RubyVor
9
+ def self.test_l
10
+ VDDT::Decomposition.from_points(Point.test_large)
11
+ end
12
+
13
+ end
data/rubyvor.gemspec ADDED
@@ -0,0 +1,34 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = %q{rubyvor}
3
+ s.version = "0.0.2"
4
+
5
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
6
+ s.authors = ["Brendan Ribera"]
7
+ s.date = %q{2008-12-03}
8
+ 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.}
9
+ s.email = ["brendan.ribera+rubyvor@gmail.com"]
10
+ s.extensions = ["ext/extconf.rb"]
11
+ s.extra_rdoc_files = ["History.txt", "Manifest.txt", "README.txt"]
12
+ 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/vdefs.h", "ext/voronoi.c", "ext/voronoi_interface.c", "lib/ruby_vor.rb", "lib/ruby_vor/decomposition.rb", "lib/ruby_vor/point.rb", "lib/ruby_vor/version.rb", "rubyvor.gemspec", "test/test_voronoi_interface.rb"]
13
+ s.has_rdoc = true
14
+ s.homepage = %q{http://github.com/bribera/rubyvor}
15
+ s.rdoc_options = ["--main", "README.txt"]
16
+ s.require_paths = ["lib", "ext"]
17
+ s.rubyforge_project = %q{rubyvor}
18
+ s.rubygems_version = %q{1.2.0}
19
+ s.summary = %q{RubyVor provides efficient computation of Voronoi diagrams and Delaunay triangulation for a set of Ruby points}
20
+ s.test_files = ["test/test_voronoi_interface.rb"]
21
+
22
+ if s.respond_to? :specification_version then
23
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
24
+ s.specification_version = 2
25
+
26
+ if current_version >= 3 then
27
+ s.add_development_dependency(%q<hoe>, [">= 1.8.2"])
28
+ else
29
+ s.add_dependency(%q<hoe>, [">= 1.8.2"])
30
+ end
31
+ else
32
+ s.add_dependency(%q<hoe>, [">= 1.8.2"])
33
+ end
34
+ end
@@ -0,0 +1,158 @@
1
+ require 'rubygems'
2
+ require 'minitest/unit'
3
+ require File.dirname(__FILE__) + '/../lib/ruby_vor'
4
+
5
+ class TestVoronoiInterface < MiniTest::Unit::TestCase
6
+
7
+ MAX_DELTA = 0.000001
8
+
9
+ def initialize(*args)
10
+ @points = @trianglulation_raw = @diagram_raw = nil
11
+ super(*args)
12
+ end
13
+
14
+ def test_diagram_correct
15
+ # Perform the decomposition.
16
+ decomp = RubyVor::VDDT::Decomposition.from_points(sample_points)
17
+
18
+ # Test each raw entry against three basic assertions:
19
+ # * entry lengths must match
20
+ # * entry types must match
21
+ # * entry values must match, with allowance for rounding errors (i.e. within a very small delta)
22
+ decomp.voronoi_diagram_raw.each_with_index do |computed_entry, i|
23
+ sample_entry = example_diagram_raw[i]
24
+
25
+
26
+ assert_equal computed_entry.length, sample_entry.length
27
+ assert_equal computed_entry.first, sample_entry.first
28
+
29
+ computed_entry.each_with_index do |computed_value,j|
30
+ # We already tested the type...
31
+ next if j == 0
32
+ assert_in_delta computed_value, sample_entry[j], MAX_DELTA
33
+ end
34
+ end
35
+ end
36
+
37
+
38
+ def test_triangulation_correct
39
+ # Perform the decomposition.
40
+ decomp = RubyVor::VDDT::Decomposition.from_points(sample_points)
41
+
42
+ # One assertion:
43
+ # * raw triangulation must match exactly.
44
+
45
+ assert_equal example_triangulation_raw, decomp.delaunay_triangulation_raw
46
+ end
47
+
48
+
49
+
50
+ #
51
+ # A few helper methods
52
+ #
53
+
54
+ private
55
+
56
+ def sample_points
57
+ # Build a sample case
58
+ if @points.nil? || @points.empty?
59
+ @points = []
60
+ data = %w{ 0.0 0.0
61
+ 0.0 0.5
62
+ 0.5 0.0
63
+ 3 3
64
+ 0.5 0.5
65
+ 5.0 5.0
66
+ 5.0 5.5
67
+ 5.5 5.0
68
+ 5.5 5.5 }
69
+ for x in 0..(data.length/2 - 1)
70
+ @points << RubyVor::Point.new(data[x * 2].to_f, data[x * 2 + 1].to_f)
71
+ end
72
+ end
73
+ @points
74
+ end
75
+
76
+ def example_diagram_raw
77
+ if @diagram_raw.nil? || @diagram_raw.empty?
78
+ @diagram_raw = [
79
+ [:s, 0.000000, 0.000000],
80
+ [:s, 0.500000, 0.000000],
81
+ [:l, 1.000000, 0.000000, 0.250000],
82
+ [:s, 0.000000, 0.500000],
83
+ [:l, 0.000000, 1.000000, 0.250000],
84
+ [:s, 0.500000, 0.500000],
85
+ [:l, 0.000000, 1.000000, 0.250000],
86
+ [:v, 0.250000, 0.250000],
87
+ [:l, 1.000000, 1.000000, 0.500000],
88
+ [:v, 0.250000, 0.250000],
89
+ [:e, 3, 1, 0],
90
+ [:l, 1.000000, 0.000000, 0.250000],
91
+ [:s, 3.000000, 3.000000],
92
+ [:l, 1.000000, 1.000000, 3.500000],
93
+ [:v, 3.250000, 0.250000],
94
+ [:e, 2, 0, 2],
95
+ [:l, 0.833333, 1.000000, 2.958333],
96
+ [:s, 5.000000, 5.000000],
97
+ [:l, 1.000000, 1.000000, 8.000000],
98
+ [:s, 5.500000, 5.000000],
99
+ [:l, 1.000000, 0.800000, 7.450000],
100
+ [:v, 5.249999, 2.750001],
101
+ [:l, 1.000000, 0.000000, 5.250000],
102
+ [:s, 5.000000, 5.500000],
103
+ [:l, 0.000000, 1.000000, 5.250000],
104
+ [:s, 5.500000, 5.500000],
105
+ [:l, 0.000000, 1.000000, 5.250000],
106
+ [:v, 5.250000, 5.250000],
107
+ [:e, 9, 4, 3],
108
+ [:l, 1.000000, 1.000000, 10.500000],
109
+ [:v, 5.250000, 5.250000],
110
+ [:e, 12, 5, 4],
111
+ [:l, 1.000000, 0.000000, 5.250000],
112
+ [:v, 0.250000, 3.250000],
113
+ [:e, 4, 6, 1],
114
+ [:e, 5, 6, 2],
115
+ [:l, 1.000000, 0.833333, 2.958333],
116
+ [:v, 2.750000, 5.250000],
117
+ [:e, 7, 7, 3],
118
+ [:e, 10, 7, 5],
119
+ [:l, 0.800000, 1.000000, 7.450000],
120
+ [:v, 15.249999, -9.749999],
121
+ [:e, 8, 3, 8],
122
+ [:e, 6, 2, 8],
123
+ [:l, 1.000000, 1.000000, 5.500000],
124
+ [:v, -9.749999, 15.249999],
125
+ [:e, 14, 9, 6],
126
+ [:e, 15, 9, 7],
127
+ [:l, 1.000000, 1.000000, 5.500000],
128
+ [:e, 1, -1, 1],
129
+ [:e, 17, -1, 9],
130
+ [:e, 13, -1, 5],
131
+ [:e, 11, 4, -1],
132
+ [:e, 16, 8, -1],
133
+ [:e, 0, 0, -1]
134
+ ]
135
+ end
136
+ @diagram_raw
137
+ end
138
+
139
+ def example_triangulation_raw
140
+ if @trianglulation_raw.nil? || @trianglulation_raw.empty?
141
+ @trianglulation_raw = [
142
+ [0, 4, 2],
143
+ [1, 4, 0],
144
+ [3, 2, 4],
145
+ [5, 7, 3],
146
+ [5, 8, 7],
147
+ [6, 8, 5],
148
+ [1, 3, 4],
149
+ [3, 6, 5],
150
+ [7, 2, 3],
151
+ [1, 6, 3]
152
+ ]
153
+ end
154
+ @trianglulation_raw
155
+ end
156
+ end
157
+
158
+ MiniTest::Unit.autorun
metadata ADDED
@@ -0,0 +1,85 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bribera-rubyvor
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Brendan Ribera
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2008-12-03 00:00:00 -08:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: hoe
17
+ version_requirement:
18
+ version_requirements: !ruby/object:Gem::Requirement
19
+ requirements:
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 1.8.2
23
+ version:
24
+ description: 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.
25
+ email:
26
+ - brendan.ribera+rubyvor@gmail.com
27
+ executables: []
28
+
29
+ extensions:
30
+ - ext/extconf.rb
31
+ extra_rdoc_files:
32
+ - History.txt
33
+ - Manifest.txt
34
+ - README.txt
35
+ files:
36
+ - History.txt
37
+ - Manifest.txt
38
+ - README.txt
39
+ - Rakefile
40
+ - ext/Doc
41
+ - ext/edgelist.c
42
+ - ext/extconf.rb
43
+ - ext/geometry.c
44
+ - ext/heap.c
45
+ - ext/memory.c
46
+ - ext/output.c
47
+ - ext/vdefs.h
48
+ - ext/voronoi.c
49
+ - ext/voronoi_interface.c
50
+ - lib/ruby_vor.rb
51
+ - lib/ruby_vor/decomposition.rb
52
+ - lib/ruby_vor/point.rb
53
+ - lib/ruby_vor/version.rb
54
+ - rubyvor.gemspec
55
+ - test/test_voronoi_interface.rb
56
+ has_rdoc: true
57
+ homepage: http://github.com/bribera/rubyvor
58
+ post_install_message:
59
+ rdoc_options:
60
+ - --main
61
+ - README.txt
62
+ require_paths:
63
+ - lib
64
+ - ext
65
+ required_ruby_version: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: "0"
70
+ version:
71
+ required_rubygems_version: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: "0"
76
+ version:
77
+ requirements: []
78
+
79
+ rubyforge_project: rubyvor
80
+ rubygems_version: 1.2.0
81
+ signing_key:
82
+ specification_version: 2
83
+ summary: RubyVor provides efficient computation of Voronoi diagrams and Delaunay triangulation for a set of Ruby points
84
+ test_files:
85
+ - test/test_voronoi_interface.rb