activerecord-postgres-earthdistance 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (65) hide show
  1. data/.document +5 -0
  2. data/Gemfile +11 -0
  3. data/Gemfile.lock +84 -0
  4. data/LICENSE +20 -0
  5. data/README.rdoc +17 -0
  6. data/Rakefile +55 -0
  7. data/VERSION +1 -0
  8. data/activerecord-postgres-earthdistance.gemspec +124 -0
  9. data/lib/activerecord-postgres-earthdistance.rb +48 -0
  10. data/lib/activerecord-postgres-earthdistance/activerecord.rb +17 -0
  11. data/lib/templates/cube.sql +326 -0
  12. data/lib/templates/earthdistance.sql +93 -0
  13. data/lib/templates/setup_earthdistance.rb +434 -0
  14. data/test/app/.gitignore +4 -0
  15. data/test/app/Gemfile +5 -0
  16. data/test/app/Gemfile.lock +83 -0
  17. data/test/app/README +256 -0
  18. data/test/app/Rakefile +7 -0
  19. data/test/app/app/controllers/application_controller.rb +3 -0
  20. data/test/app/app/helpers/application_helper.rb +2 -0
  21. data/test/app/app/models/place.rb +3 -0
  22. data/test/app/app/views/layouts/application.html.erb +14 -0
  23. data/test/app/config.ru +4 -0
  24. data/test/app/config/application.rb +42 -0
  25. data/test/app/config/boot.rb +13 -0
  26. data/test/app/config/database.yml +25 -0
  27. data/test/app/config/environment.rb +5 -0
  28. data/test/app/config/environments/development.rb +26 -0
  29. data/test/app/config/environments/production.rb +49 -0
  30. data/test/app/config/environments/test.rb +35 -0
  31. data/test/app/config/initializers/backtrace_silencers.rb +7 -0
  32. data/test/app/config/initializers/inflections.rb +10 -0
  33. data/test/app/config/initializers/mime_types.rb +5 -0
  34. data/test/app/config/initializers/secret_token.rb +7 -0
  35. data/test/app/config/initializers/session_store.rb +8 -0
  36. data/test/app/config/initializers/use_sql_schema.rb +3 -0
  37. data/test/app/config/locales/en.yml +5 -0
  38. data/test/app/config/routes.rb +58 -0
  39. data/test/app/db/development_structure.sql +807 -0
  40. data/test/app/db/migrate/20110225205046_setup_earthdistance.rb +434 -0
  41. data/test/app/db/migrate/20110225205131_create_places.rb +15 -0
  42. data/test/app/db/schema.rb +24 -0
  43. data/test/app/db/seeds.rb +7 -0
  44. data/test/app/doc/README_FOR_APP +2 -0
  45. data/test/app/lib/tasks/.gitkeep +0 -0
  46. data/test/app/public/404.html +26 -0
  47. data/test/app/public/422.html +26 -0
  48. data/test/app/public/500.html +26 -0
  49. data/test/app/public/favicon.ico +0 -0
  50. data/test/app/public/images/rails.png +0 -0
  51. data/test/app/public/index.html +239 -0
  52. data/test/app/public/javascripts/application.js +2 -0
  53. data/test/app/public/javascripts/controls.js +965 -0
  54. data/test/app/public/javascripts/dragdrop.js +974 -0
  55. data/test/app/public/javascripts/effects.js +1123 -0
  56. data/test/app/public/javascripts/prototype.js +6001 -0
  57. data/test/app/public/javascripts/rails.js +175 -0
  58. data/test/app/public/robots.txt +5 -0
  59. data/test/app/public/stylesheets/.gitkeep +0 -0
  60. data/test/app/script/rails +6 -0
  61. data/test/app/test/performance/browsing_test.rb +9 -0
  62. data/test/app/test/test_helper.rb +13 -0
  63. data/test/app/test/unit/place_test.rb +27 -0
  64. data/test/app/vendor/plugins/.gitkeep +0 -0
  65. metadata +205 -0
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
data/Gemfile ADDED
@@ -0,0 +1,11 @@
1
+ source :gemcutter
2
+
3
+ gem 'rails', '>= 3.0.0'
4
+ gem 'pg', '>= 0.11'
5
+
6
+ group :development do
7
+ gem "shoulda", ">= 0"
8
+ gem "bundler", "~> 1.0.0"
9
+ gem "jeweler", "~> 1.6.2"
10
+ gem "rcov", ">= 0"
11
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,84 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ abstract (1.0.0)
5
+ actionmailer (3.0.7)
6
+ actionpack (= 3.0.7)
7
+ mail (~> 2.2.15)
8
+ actionpack (3.0.7)
9
+ activemodel (= 3.0.7)
10
+ activesupport (= 3.0.7)
11
+ builder (~> 2.1.2)
12
+ erubis (~> 2.6.6)
13
+ i18n (~> 0.5.0)
14
+ rack (~> 1.2.1)
15
+ rack-mount (~> 0.6.14)
16
+ rack-test (~> 0.5.7)
17
+ tzinfo (~> 0.3.23)
18
+ activemodel (3.0.7)
19
+ activesupport (= 3.0.7)
20
+ builder (~> 2.1.2)
21
+ i18n (~> 0.5.0)
22
+ activerecord (3.0.7)
23
+ activemodel (= 3.0.7)
24
+ activesupport (= 3.0.7)
25
+ arel (~> 2.0.2)
26
+ tzinfo (~> 0.3.23)
27
+ activeresource (3.0.7)
28
+ activemodel (= 3.0.7)
29
+ activesupport (= 3.0.7)
30
+ activesupport (3.0.7)
31
+ arel (2.0.10)
32
+ builder (2.1.2)
33
+ erubis (2.6.6)
34
+ abstract (>= 1.0.0)
35
+ git (1.2.5)
36
+ i18n (0.5.0)
37
+ jeweler (1.6.2)
38
+ bundler (~> 1.0)
39
+ git (>= 1.2.5)
40
+ rake
41
+ mail (2.2.19)
42
+ activesupport (>= 2.3.6)
43
+ i18n (>= 0.4.0)
44
+ mime-types (~> 1.16)
45
+ treetop (~> 1.4.8)
46
+ mime-types (1.16)
47
+ pg (0.11.0)
48
+ polyglot (0.3.1)
49
+ rack (1.2.3)
50
+ rack-mount (0.6.14)
51
+ rack (>= 1.0.0)
52
+ rack-test (0.5.7)
53
+ rack (>= 1.0)
54
+ rails (3.0.7)
55
+ actionmailer (= 3.0.7)
56
+ actionpack (= 3.0.7)
57
+ activerecord (= 3.0.7)
58
+ activeresource (= 3.0.7)
59
+ activesupport (= 3.0.7)
60
+ bundler (~> 1.0)
61
+ railties (= 3.0.7)
62
+ railties (3.0.7)
63
+ actionpack (= 3.0.7)
64
+ activesupport (= 3.0.7)
65
+ rake (>= 0.8.7)
66
+ thor (~> 0.14.4)
67
+ rake (0.9.2)
68
+ rcov (0.9.9)
69
+ shoulda (2.11.3)
70
+ thor (0.14.6)
71
+ treetop (1.4.9)
72
+ polyglot (>= 0.3.1)
73
+ tzinfo (0.3.27)
74
+
75
+ PLATFORMS
76
+ ruby
77
+
78
+ DEPENDENCIES
79
+ bundler (~> 1.0.0)
80
+ jeweler (~> 1.6.2)
81
+ pg (>= 0.11)
82
+ rails (>= 3.0.0)
83
+ rcov
84
+ shoulda
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Juan Maiz
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,17 @@
1
+ = activerecord-postgres-earthdistance
2
+
3
+ Description goes here.
4
+
5
+ == Note on Patches/Pull Requests
6
+
7
+ * Fork the project.
8
+ * Make your feature addition or bug fix.
9
+ * Add tests for it. This is important so I don't break it in a
10
+ future version unintentionally.
11
+ * Commit, do not mess with rakefile, version, or history.
12
+ (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
13
+ * Send me a pull request. Bonus points for topic branches.
14
+
15
+ == Copyright
16
+
17
+ Copyright (c) 2011 Juan Maiz. See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,55 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+
14
+ require 'jeweler'
15
+ Jeweler::Tasks.new do |gem|
16
+ gem.name = "activerecord-postgres-earthdistance"
17
+ gem.license = "MIT"
18
+ gem.name = "activerecord-postgres-earthdistance"
19
+ gem.summary = %Q{Now you can filter records within a radius}
20
+ gem.description = %Q{I'll write it tomorrow}
21
+ gem.email = "diogob@gmail.com"
22
+ gem.homepage = "http://github.com/softa/activerecord-postgres-earthdistance"
23
+ gem.authors = ["Juan Maiz", "Diogo Biazus"]
24
+ gem.add_dependency "pg"
25
+ gem.add_dependency "rails"
26
+ # dependencies defined in Gemfile
27
+ end
28
+ Jeweler::RubygemsDotOrgTasks.new
29
+
30
+ require 'rake/testtask'
31
+ Rake::TestTask.new(:test) do |test|
32
+ test.libs << 'lib' << 'test'
33
+ test.pattern = 'test/**/test_*.rb'
34
+ test.verbose = true
35
+ end
36
+
37
+ require 'rcov/rcovtask'
38
+ Rcov::RcovTask.new do |test|
39
+ test.libs << 'test'
40
+ test.pattern = 'test/**/test_*.rb'
41
+ test.verbose = true
42
+ test.rcov_opts << '--exclude "gems/*"'
43
+ end
44
+
45
+ task :default => :test
46
+
47
+ require 'rake/rdoctask'
48
+ Rake::RDocTask.new do |rdoc|
49
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
50
+
51
+ rdoc.rdoc_dir = 'rdoc'
52
+ rdoc.title = "activerecord-postgres-earthdistance #{version}"
53
+ rdoc.rdoc_files.include('README*')
54
+ rdoc.rdoc_files.include('lib/**/*.rb')
55
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
@@ -0,0 +1,124 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{activerecord-postgres-earthdistance}
8
+ s.version = "0.1.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Juan Maiz", "Diogo Biazus"]
12
+ s.date = %q{2011-06-23}
13
+ s.description = %q{I'll write it tomorrow}
14
+ s.email = %q{diogob@gmail.com}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ "Gemfile",
22
+ "Gemfile.lock",
23
+ "LICENSE",
24
+ "README.rdoc",
25
+ "Rakefile",
26
+ "VERSION",
27
+ "activerecord-postgres-earthdistance.gemspec",
28
+ "lib/activerecord-postgres-earthdistance.rb",
29
+ "lib/activerecord-postgres-earthdistance/activerecord.rb",
30
+ "lib/templates/cube.sql",
31
+ "lib/templates/earthdistance.sql",
32
+ "lib/templates/setup_earthdistance.rb",
33
+ "test/app/.gitignore",
34
+ "test/app/Gemfile",
35
+ "test/app/Gemfile.lock",
36
+ "test/app/README",
37
+ "test/app/Rakefile",
38
+ "test/app/app/controllers/application_controller.rb",
39
+ "test/app/app/helpers/application_helper.rb",
40
+ "test/app/app/models/place.rb",
41
+ "test/app/app/views/layouts/application.html.erb",
42
+ "test/app/config.ru",
43
+ "test/app/config/application.rb",
44
+ "test/app/config/boot.rb",
45
+ "test/app/config/database.yml",
46
+ "test/app/config/environment.rb",
47
+ "test/app/config/environments/development.rb",
48
+ "test/app/config/environments/production.rb",
49
+ "test/app/config/environments/test.rb",
50
+ "test/app/config/initializers/backtrace_silencers.rb",
51
+ "test/app/config/initializers/inflections.rb",
52
+ "test/app/config/initializers/mime_types.rb",
53
+ "test/app/config/initializers/secret_token.rb",
54
+ "test/app/config/initializers/session_store.rb",
55
+ "test/app/config/initializers/use_sql_schema.rb",
56
+ "test/app/config/locales/en.yml",
57
+ "test/app/config/routes.rb",
58
+ "test/app/db/development_structure.sql",
59
+ "test/app/db/migrate/20110225205046_setup_earthdistance.rb",
60
+ "test/app/db/migrate/20110225205131_create_places.rb",
61
+ "test/app/db/schema.rb",
62
+ "test/app/db/seeds.rb",
63
+ "test/app/doc/README_FOR_APP",
64
+ "test/app/lib/tasks/.gitkeep",
65
+ "test/app/public/404.html",
66
+ "test/app/public/422.html",
67
+ "test/app/public/500.html",
68
+ "test/app/public/favicon.ico",
69
+ "test/app/public/images/rails.png",
70
+ "test/app/public/index.html",
71
+ "test/app/public/javascripts/application.js",
72
+ "test/app/public/javascripts/controls.js",
73
+ "test/app/public/javascripts/dragdrop.js",
74
+ "test/app/public/javascripts/effects.js",
75
+ "test/app/public/javascripts/prototype.js",
76
+ "test/app/public/javascripts/rails.js",
77
+ "test/app/public/robots.txt",
78
+ "test/app/public/stylesheets/.gitkeep",
79
+ "test/app/script/rails",
80
+ "test/app/test/performance/browsing_test.rb",
81
+ "test/app/test/test_helper.rb",
82
+ "test/app/test/unit/place_test.rb",
83
+ "test/app/vendor/plugins/.gitkeep"
84
+ ]
85
+ s.homepage = %q{http://github.com/softa/activerecord-postgres-earthdistance}
86
+ s.licenses = ["MIT"]
87
+ s.require_paths = ["lib"]
88
+ s.rubygems_version = %q{1.6.2}
89
+ s.summary = %q{Now you can filter records within a radius}
90
+
91
+ if s.respond_to? :specification_version then
92
+ s.specification_version = 3
93
+
94
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
95
+ s.add_runtime_dependency(%q<rails>, [">= 3.0.0"])
96
+ s.add_runtime_dependency(%q<pg>, [">= 0.11"])
97
+ s.add_development_dependency(%q<shoulda>, [">= 0"])
98
+ s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
99
+ s.add_development_dependency(%q<jeweler>, ["~> 1.6.2"])
100
+ s.add_development_dependency(%q<rcov>, [">= 0"])
101
+ s.add_runtime_dependency(%q<pg>, [">= 0"])
102
+ s.add_runtime_dependency(%q<rails>, [">= 0"])
103
+ else
104
+ s.add_dependency(%q<rails>, [">= 3.0.0"])
105
+ s.add_dependency(%q<pg>, [">= 0.11"])
106
+ s.add_dependency(%q<shoulda>, [">= 0"])
107
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
108
+ s.add_dependency(%q<jeweler>, ["~> 1.6.2"])
109
+ s.add_dependency(%q<rcov>, [">= 0"])
110
+ s.add_dependency(%q<pg>, [">= 0"])
111
+ s.add_dependency(%q<rails>, [">= 0"])
112
+ end
113
+ else
114
+ s.add_dependency(%q<rails>, [">= 3.0.0"])
115
+ s.add_dependency(%q<pg>, [">= 0.11"])
116
+ s.add_dependency(%q<shoulda>, [">= 0"])
117
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
118
+ s.add_dependency(%q<jeweler>, ["~> 1.6.2"])
119
+ s.add_dependency(%q<rcov>, [">= 0"])
120
+ s.add_dependency(%q<pg>, [">= 0"])
121
+ s.add_dependency(%q<rails>, [">= 0"])
122
+ end
123
+ end
124
+
@@ -0,0 +1,48 @@
1
+ require 'rails'
2
+ require 'rails/generators'
3
+ require 'rails/generators/migration'
4
+
5
+ # = Earth Distance Railtie
6
+ #
7
+ # Creates a new railtie for 2 reasons:
8
+ #
9
+ # * Initialize ActiveRecord properly
10
+ # * Add earthdistance:setup generator
11
+ class EarthDistance < Rails::Railtie
12
+
13
+ initializer 'activerecord-postgres-earthdistance' do
14
+ ActiveSupport.on_load :active_record do
15
+ require "activerecord-postgres-earthdistance/activerecord"
16
+ end
17
+ end
18
+
19
+ # Creates the earthdistance:setup generator. This generator creates a migration that
20
+ # adds earthdistance support for your database. If fact, it's just the sql from the
21
+ # contrib inside a migration. But it' s handy, isn't it?
22
+ #
23
+ # To use your generator, simply run it in your project:
24
+ #
25
+ # rails g earthdistance:setup
26
+ class Setup < Rails::Generators::Base
27
+ include Rails::Generators::Migration
28
+
29
+ def self.source_root
30
+ @source_root ||= File.join(File.dirname(__FILE__), 'templates')
31
+ end
32
+
33
+ def self.next_migration_number(dirname)
34
+ if ActiveRecord::Base.timestamped_migrations
35
+ Time.now.utc.strftime("%Y%m%d%H%M%S")
36
+ else
37
+ "%.3d" % (current_migration_number(dirname) + 1)
38
+ end
39
+ end
40
+
41
+ def create_migration_file
42
+ migration_template 'setup_earthdistance.rb', 'db/migrate/setup_earthdistance.rb'
43
+ end
44
+
45
+ end
46
+ end
47
+ # require "activerecord-postgres-earthdistance/string"
48
+ # require "activerecord-postgres-earthdistance/hash"
@@ -0,0 +1,17 @@
1
+ # Extends AR to add earthdistance functionality.
2
+ module ActiveRecord
3
+ class Base
4
+ def self.acts_as_geolocated(options = {}, distances = {})
5
+ @@latitude_column = options[:lat]
6
+ @@longitude_column = options[:lng]
7
+ @@latitude_column = (column_names.include?("lat") ? "lat" : "latitude") unless @@latitude_column
8
+ @@longitude_column = (column_names.include?("lng") ? "lng" : "longitude") unless @@longitude_column
9
+
10
+ def self.within_radius radius, lat, lng, unit = :meters
11
+ where(["ll_to_earth(#{@@latitude_column}, #{@@longitude_column}) <@ earth_box(ll_to_earth(?, ?), ?)
12
+ AND earth_distance(ll_to_earth(#{@@latitude_column}, #{@@longitude_column}), ll_to_earth(?, ?)) <= ?",
13
+ lat, lng, radius, lat, lng, radius])
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,326 @@
1
+ /* $PostgreSQL: pgsql/contrib/cube/cube.sql.in,v 1.25 2009/06/11 18:30:03 tgl Exp $ */
2
+
3
+ -- Adjust this setting to control where the objects get created.
4
+ SET search_path = public;
5
+
6
+ -- Create the user-defined type for N-dimensional boxes
7
+ --
8
+
9
+ CREATE OR REPLACE FUNCTION cube_in(cstring)
10
+ RETURNS cube
11
+ AS '$libdir/cube'
12
+ LANGUAGE C IMMUTABLE STRICT;
13
+
14
+ CREATE OR REPLACE FUNCTION cube(float8[], float8[]) RETURNS cube
15
+ AS '$libdir/cube', 'cube_a_f8_f8'
16
+ LANGUAGE C IMMUTABLE STRICT;
17
+
18
+ CREATE OR REPLACE FUNCTION cube(float8[]) RETURNS cube
19
+ AS '$libdir/cube', 'cube_a_f8'
20
+ LANGUAGE C IMMUTABLE STRICT;
21
+
22
+ CREATE OR REPLACE FUNCTION cube_out(cube)
23
+ RETURNS cstring
24
+ AS '$libdir/cube'
25
+ LANGUAGE C IMMUTABLE STRICT;
26
+
27
+ CREATE TYPE cube (
28
+ INTERNALLENGTH = variable,
29
+ INPUT = cube_in,
30
+ OUTPUT = cube_out,
31
+ ALIGNMENT = double
32
+ );
33
+
34
+ COMMENT ON TYPE cube IS 'multi-dimensional cube ''(FLOAT-1, FLOAT-2, ..., FLOAT-N), (FLOAT-1, FLOAT-2, ..., FLOAT-N)''';
35
+
36
+ --
37
+ -- External C-functions for R-tree methods
38
+ --
39
+
40
+ -- Comparison methods
41
+
42
+ CREATE OR REPLACE FUNCTION cube_eq(cube, cube)
43
+ RETURNS bool
44
+ AS '$libdir/cube'
45
+ LANGUAGE C IMMUTABLE STRICT;
46
+
47
+ COMMENT ON FUNCTION cube_eq(cube, cube) IS 'same as';
48
+
49
+ CREATE OR REPLACE FUNCTION cube_ne(cube, cube)
50
+ RETURNS bool
51
+ AS '$libdir/cube'
52
+ LANGUAGE C IMMUTABLE STRICT;
53
+
54
+ COMMENT ON FUNCTION cube_ne(cube, cube) IS 'different';
55
+
56
+ CREATE OR REPLACE FUNCTION cube_lt(cube, cube)
57
+ RETURNS bool
58
+ AS '$libdir/cube'
59
+ LANGUAGE C IMMUTABLE STRICT;
60
+
61
+ COMMENT ON FUNCTION cube_lt(cube, cube) IS 'lower than';
62
+
63
+ CREATE OR REPLACE FUNCTION cube_gt(cube, cube)
64
+ RETURNS bool
65
+ AS '$libdir/cube'
66
+ LANGUAGE C IMMUTABLE STRICT;
67
+
68
+ COMMENT ON FUNCTION cube_gt(cube, cube) IS 'greater than';
69
+
70
+ CREATE OR REPLACE FUNCTION cube_le(cube, cube)
71
+ RETURNS bool
72
+ AS '$libdir/cube'
73
+ LANGUAGE C IMMUTABLE STRICT;
74
+
75
+ COMMENT ON FUNCTION cube_le(cube, cube) IS 'lower than or equal to';
76
+
77
+ CREATE OR REPLACE FUNCTION cube_ge(cube, cube)
78
+ RETURNS bool
79
+ AS '$libdir/cube'
80
+ LANGUAGE C IMMUTABLE STRICT;
81
+
82
+ COMMENT ON FUNCTION cube_ge(cube, cube) IS 'greater than or equal to';
83
+
84
+ CREATE OR REPLACE FUNCTION cube_cmp(cube, cube)
85
+ RETURNS int4
86
+ AS '$libdir/cube'
87
+ LANGUAGE C IMMUTABLE STRICT;
88
+
89
+ COMMENT ON FUNCTION cube_cmp(cube, cube) IS 'btree comparison function';
90
+
91
+ CREATE OR REPLACE FUNCTION cube_contains(cube, cube)
92
+ RETURNS bool
93
+ AS '$libdir/cube'
94
+ LANGUAGE C IMMUTABLE STRICT;
95
+
96
+ COMMENT ON FUNCTION cube_contains(cube, cube) IS 'contains';
97
+
98
+ CREATE OR REPLACE FUNCTION cube_contained(cube, cube)
99
+ RETURNS bool
100
+ AS '$libdir/cube'
101
+ LANGUAGE C IMMUTABLE STRICT;
102
+
103
+ COMMENT ON FUNCTION cube_contained(cube, cube) IS 'contained in';
104
+
105
+ CREATE OR REPLACE FUNCTION cube_overlap(cube, cube)
106
+ RETURNS bool
107
+ AS '$libdir/cube'
108
+ LANGUAGE C IMMUTABLE STRICT;
109
+
110
+ COMMENT ON FUNCTION cube_overlap(cube, cube) IS 'overlaps';
111
+
112
+ -- support routines for indexing
113
+
114
+ CREATE OR REPLACE FUNCTION cube_union(cube, cube)
115
+ RETURNS cube
116
+ AS '$libdir/cube'
117
+ LANGUAGE C IMMUTABLE STRICT;
118
+
119
+ CREATE OR REPLACE FUNCTION cube_inter(cube, cube)
120
+ RETURNS cube
121
+ AS '$libdir/cube'
122
+ LANGUAGE C IMMUTABLE STRICT;
123
+
124
+ CREATE OR REPLACE FUNCTION cube_size(cube)
125
+ RETURNS float8
126
+ AS '$libdir/cube'
127
+ LANGUAGE C IMMUTABLE STRICT;
128
+
129
+
130
+ -- Misc N-dimensional functions
131
+
132
+ CREATE OR REPLACE FUNCTION cube_subset(cube, int4[])
133
+ RETURNS cube
134
+ AS '$libdir/cube'
135
+ LANGUAGE C IMMUTABLE STRICT;
136
+
137
+ -- proximity routines
138
+
139
+ CREATE OR REPLACE FUNCTION cube_distance(cube, cube)
140
+ RETURNS float8
141
+ AS '$libdir/cube'
142
+ LANGUAGE C IMMUTABLE STRICT;
143
+
144
+ -- Extracting elements functions
145
+
146
+ CREATE OR REPLACE FUNCTION cube_dim(cube)
147
+ RETURNS int4
148
+ AS '$libdir/cube'
149
+ LANGUAGE C IMMUTABLE STRICT;
150
+
151
+ CREATE OR REPLACE FUNCTION cube_ll_coord(cube, int4)
152
+ RETURNS float8
153
+ AS '$libdir/cube'
154
+ LANGUAGE C IMMUTABLE STRICT;
155
+
156
+ CREATE OR REPLACE FUNCTION cube_ur_coord(cube, int4)
157
+ RETURNS float8
158
+ AS '$libdir/cube'
159
+ LANGUAGE C IMMUTABLE STRICT;
160
+
161
+ CREATE OR REPLACE FUNCTION cube(float8) RETURNS cube
162
+ AS '$libdir/cube', 'cube_f8'
163
+ LANGUAGE C IMMUTABLE STRICT;
164
+
165
+ CREATE OR REPLACE FUNCTION cube(float8, float8) RETURNS cube
166
+ AS '$libdir/cube', 'cube_f8_f8'
167
+ LANGUAGE C IMMUTABLE STRICT;
168
+
169
+ CREATE OR REPLACE FUNCTION cube(cube, float8) RETURNS cube
170
+ AS '$libdir/cube', 'cube_c_f8'
171
+ LANGUAGE C IMMUTABLE STRICT;
172
+
173
+ CREATE OR REPLACE FUNCTION cube(cube, float8, float8) RETURNS cube
174
+ AS '$libdir/cube', 'cube_c_f8_f8'
175
+ LANGUAGE C IMMUTABLE STRICT;
176
+
177
+ -- Test if cube is also a point
178
+
179
+ CREATE OR REPLACE FUNCTION cube_is_point(cube)
180
+ RETURNS bool
181
+ AS '$libdir/cube'
182
+ LANGUAGE C IMMUTABLE STRICT;
183
+
184
+ -- Increasing the size of a cube by a radius in at least n dimensions
185
+
186
+ CREATE OR REPLACE FUNCTION cube_enlarge(cube, float8, int4)
187
+ RETURNS cube
188
+ AS '$libdir/cube'
189
+ LANGUAGE C IMMUTABLE STRICT;
190
+
191
+ --
192
+ -- OPERATORS
193
+ --
194
+
195
+ CREATE OPERATOR < (
196
+ LEFTARG = cube, RIGHTARG = cube, PROCEDURE = cube_lt,
197
+ COMMUTATOR = '>', NEGATOR = '>=',
198
+ RESTRICT = scalarltsel, JOIN = scalarltjoinsel
199
+ );
200
+
201
+ CREATE OPERATOR > (
202
+ LEFTARG = cube, RIGHTARG = cube, PROCEDURE = cube_gt,
203
+ COMMUTATOR = '<', NEGATOR = '<=',
204
+ RESTRICT = scalargtsel, JOIN = scalargtjoinsel
205
+ );
206
+
207
+ CREATE OPERATOR <= (
208
+ LEFTARG = cube, RIGHTARG = cube, PROCEDURE = cube_le,
209
+ COMMUTATOR = '>=', NEGATOR = '>',
210
+ RESTRICT = scalarltsel, JOIN = scalarltjoinsel
211
+ );
212
+
213
+ CREATE OPERATOR >= (
214
+ LEFTARG = cube, RIGHTARG = cube, PROCEDURE = cube_ge,
215
+ COMMUTATOR = '<=', NEGATOR = '<',
216
+ RESTRICT = scalargtsel, JOIN = scalargtjoinsel
217
+ );
218
+
219
+ CREATE OPERATOR && (
220
+ LEFTARG = cube, RIGHTARG = cube, PROCEDURE = cube_overlap,
221
+ COMMUTATOR = '&&',
222
+ RESTRICT = areasel, JOIN = areajoinsel
223
+ );
224
+
225
+ CREATE OPERATOR = (
226
+ LEFTARG = cube, RIGHTARG = cube, PROCEDURE = cube_eq,
227
+ COMMUTATOR = '=', NEGATOR = '<>',
228
+ RESTRICT = eqsel, JOIN = eqjoinsel,
229
+ MERGES
230
+ );
231
+
232
+ CREATE OPERATOR <> (
233
+ LEFTARG = cube, RIGHTARG = cube, PROCEDURE = cube_ne,
234
+ COMMUTATOR = '<>', NEGATOR = '=',
235
+ RESTRICT = neqsel, JOIN = neqjoinsel
236
+ );
237
+
238
+ CREATE OPERATOR @> (
239
+ LEFTARG = cube, RIGHTARG = cube, PROCEDURE = cube_contains,
240
+ COMMUTATOR = '<@',
241
+ RESTRICT = contsel, JOIN = contjoinsel
242
+ );
243
+
244
+ CREATE OPERATOR <@ (
245
+ LEFTARG = cube, RIGHTARG = cube, PROCEDURE = cube_contained,
246
+ COMMUTATOR = '@>',
247
+ RESTRICT = contsel, JOIN = contjoinsel
248
+ );
249
+
250
+ -- these are obsolete/deprecated:
251
+ CREATE OPERATOR @ (
252
+ LEFTARG = cube, RIGHTARG = cube, PROCEDURE = cube_contains,
253
+ COMMUTATOR = '~',
254
+ RESTRICT = contsel, JOIN = contjoinsel
255
+ );
256
+
257
+ CREATE OPERATOR ~ (
258
+ LEFTARG = cube, RIGHTARG = cube, PROCEDURE = cube_contained,
259
+ COMMUTATOR = '@',
260
+ RESTRICT = contsel, JOIN = contjoinsel
261
+ );
262
+
263
+
264
+ -- define the GiST support methods
265
+ CREATE OR REPLACE FUNCTION g_cube_consistent(internal,cube,int,oid,internal)
266
+ RETURNS bool
267
+ AS '$libdir/cube'
268
+ LANGUAGE C IMMUTABLE STRICT;
269
+
270
+ CREATE OR REPLACE FUNCTION g_cube_compress(internal)
271
+ RETURNS internal
272
+ AS '$libdir/cube'
273
+ LANGUAGE C IMMUTABLE STRICT;
274
+
275
+ CREATE OR REPLACE FUNCTION g_cube_decompress(internal)
276
+ RETURNS internal
277
+ AS '$libdir/cube'
278
+ LANGUAGE C IMMUTABLE STRICT;
279
+
280
+ CREATE OR REPLACE FUNCTION g_cube_penalty(internal,internal,internal)
281
+ RETURNS internal
282
+ AS '$libdir/cube'
283
+ LANGUAGE C IMMUTABLE STRICT;
284
+
285
+ CREATE OR REPLACE FUNCTION g_cube_picksplit(internal, internal)
286
+ RETURNS internal
287
+ AS '$libdir/cube'
288
+ LANGUAGE C IMMUTABLE STRICT;
289
+
290
+ CREATE OR REPLACE FUNCTION g_cube_union(internal, internal)
291
+ RETURNS cube
292
+ AS '$libdir/cube'
293
+ LANGUAGE C IMMUTABLE STRICT;
294
+
295
+ CREATE OR REPLACE FUNCTION g_cube_same(cube, cube, internal)
296
+ RETURNS internal
297
+ AS '$libdir/cube'
298
+ LANGUAGE C IMMUTABLE STRICT;
299
+
300
+
301
+ -- Create the operator classes for indexing
302
+
303
+ CREATE OPERATOR CLASS cube_ops
304
+ DEFAULT FOR TYPE cube USING btree AS
305
+ OPERATOR 1 < ,
306
+ OPERATOR 2 <= ,
307
+ OPERATOR 3 = ,
308
+ OPERATOR 4 >= ,
309
+ OPERATOR 5 > ,
310
+ FUNCTION 1 cube_cmp(cube, cube);
311
+
312
+ CREATE OPERATOR CLASS gist_cube_ops
313
+ DEFAULT FOR TYPE cube USING gist AS
314
+ OPERATOR 3 && ,
315
+ OPERATOR 6 = ,
316
+ OPERATOR 7 @> ,
317
+ OPERATOR 8 <@ ,
318
+ OPERATOR 13 @ ,
319
+ OPERATOR 14 ~ ,
320
+ FUNCTION 1 g_cube_consistent (internal, cube, int, oid, internal),
321
+ FUNCTION 2 g_cube_union (internal, internal),
322
+ FUNCTION 3 g_cube_compress (internal),
323
+ FUNCTION 4 g_cube_decompress (internal),
324
+ FUNCTION 5 g_cube_penalty (internal, internal, internal),
325
+ FUNCTION 6 g_cube_picksplit (internal, internal),
326
+ FUNCTION 7 g_cube_same (cube, cube, internal);