ffi-geos 0.0.4 → 0.0.5

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/.gitignore ADDED
@@ -0,0 +1,18 @@
1
+ *.orig
2
+ .*.swp
3
+ .*.swo
4
+ *.tmp
5
+ *.kpf
6
+ *.komodoproject
7
+ *~
8
+ .DS_Store
9
+ *tmp*
10
+ pkg/
11
+ doc/
12
+ *.orig
13
+ *.patch
14
+ .vimrc_local
15
+ *.rbc
16
+ test-all.sh
17
+ .rbx
18
+ Gemfile.lock
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/MIT-LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2011 J Smith <dark.panda@gmail.com>
1
+ Copyright (c) 2012 J Smith <dark.panda@gmail.com>
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person
4
4
  obtaining a copy of this software and associated documentation
data/Rakefile CHANGED
@@ -8,6 +8,7 @@ gem 'rdoc', '~> 3.12'
8
8
  require 'rubygems/package_task'
9
9
  require 'rake/testtask'
10
10
  require 'rdoc/task'
11
+ require 'bundler/gem_tasks'
11
12
 
12
13
  if RUBY_VERSION >= '1.9'
13
14
  begin
@@ -19,28 +20,13 @@ end
19
20
 
20
21
  $:.push 'lib'
21
22
 
22
- version = File.read('VERSION') rescue ''
23
-
24
- begin
25
- require 'jeweler'
26
- Jeweler::Tasks.new do |gem|
27
- gem.name = "ffi-geos"
28
- gem.summary = "An ffi wrapper for GEOS, a C++ port of the Java Topology Suite (JTS)."
29
- gem.description = gem.summary
30
- gem.email = "dark.panda@gmail.com"
31
- gem.homepage = "http://github.com/dark-panda/ffi-geos"
32
- gem.authors = [ "J Smith" ]
33
- gem.add_dependency "ffi", "~> 1.0.0"
34
- end
35
- Jeweler::GemcutterTasks.new
36
- rescue LoadError
37
- puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
38
- end
23
+ version = Geos::VERSION
39
24
 
40
25
  desc 'Test GEOS interface'
41
26
  Rake::TestTask.new(:test) do |t|
42
27
  t.test_files = FileList['test/**/*_tests.rb']
43
28
  t.verbose = !!ENV['VERBOSE_TESTS']
29
+ t.warning = !!ENV['WARNINGS']
44
30
  end
45
31
 
46
32
  desc 'Build docs'
data/ffi-geos.gemspec CHANGED
@@ -1,74 +1,27 @@
1
- # Generated by jeweler
2
- # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
1
  # -*- encoding: utf-8 -*-
5
2
 
3
+ require File.expand_path('../lib/ffi-geos/version', __FILE__)
4
+
6
5
  Gem::Specification.new do |s|
7
- s.name = %q{ffi-geos}
8
- s.version = "0.0.4"
6
+ s.name = "ffi-geos"
7
+ s.version = Geos::VERSION
9
8
 
10
9
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
- s.authors = [%q{J Smith}]
12
- s.date = %q{2012-02-28}
13
- s.description = %q{An ffi wrapper for GEOS, a C++ port of the Java Topology Suite (JTS).}
14
- s.email = %q{dark.panda@gmail.com}
10
+ s.authors = ["J Smith"]
11
+ s.description = "An ffi wrapper for GEOS, a C++ port of the Java Topology Suite (JTS)."
12
+ s.summary = s.description
13
+ s.email = "dark.panda@gmail.com"
15
14
  s.extra_rdoc_files = [
16
15
  "README.rdoc"
17
16
  ]
18
- s.files = [
19
- "MIT-LICENSE",
20
- "README.rdoc",
21
- "Rakefile",
22
- "VERSION",
23
- "ffi-geos.gemspec",
24
- "lib/ffi-geos.rb",
25
- "lib/ffi-geos/buffer_params.rb",
26
- "lib/ffi-geos/coordinate_sequence.rb",
27
- "lib/ffi-geos/geometry.rb",
28
- "lib/ffi-geos/geometry_collection.rb",
29
- "lib/ffi-geos/line_string.rb",
30
- "lib/ffi-geos/linear_ring.rb",
31
- "lib/ffi-geos/multi_line_string.rb",
32
- "lib/ffi-geos/multi_point.rb",
33
- "lib/ffi-geos/multi_polygon.rb",
34
- "lib/ffi-geos/point.rb",
35
- "lib/ffi-geos/polygon.rb",
36
- "lib/ffi-geos/prepared_geometry.rb",
37
- "lib/ffi-geos/strtree.rb",
38
- "lib/ffi-geos/tools.rb",
39
- "lib/ffi-geos/utils.rb",
40
- "lib/ffi-geos/wkb_reader.rb",
41
- "lib/ffi-geos/wkb_writer.rb",
42
- "lib/ffi-geos/wkt_reader.rb",
43
- "lib/ffi-geos/wkt_writer.rb",
44
- "test/coordinate_sequence_tests.rb",
45
- "test/geometry_tests.rb",
46
- "test/misc_tests.rb",
47
- "test/point_tests.rb",
48
- "test/prepared_geometry_tests.rb",
49
- "test/strtree_tests.rb",
50
- "test/test_helper.rb",
51
- "test/utils_tests.rb",
52
- "test/wkb_reader_tests.rb",
53
- "test/wkb_writer_tests.rb",
54
- "test/wkt_reader_tests.rb",
55
- "test/wkt_writer_tests.rb"
56
- ]
57
- s.homepage = %q{http://github.com/dark-panda/ffi-geos}
58
- s.require_paths = [%q{lib}]
59
- s.rubygems_version = %q{1.8.9}
60
- s.summary = %q{An ffi wrapper for GEOS, a C++ port of the Java Topology Suite (JTS).}
61
-
62
- if s.respond_to? :specification_version then
63
- s.specification_version = 3
17
+ s.files = `git ls-files`.split($\)
18
+ s.executables = s.files.grep(%r{^bin/}).map { |f| File.basename(f) }
19
+ s.test_files = s.files.grep(%r{^(test|spec|features)/})
20
+ s.homepage = "http://github.com/dark-panda/ffi-geos"
21
+ s.require_paths = ["lib"]
64
22
 
65
- if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
66
- s.add_runtime_dependency(%q<ffi>, ["~> 1.0.0"])
67
- else
68
- s.add_dependency(%q<ffi>, ["~> 1.0.0"])
69
- end
70
- else
71
- s.add_dependency(%q<ffi>, ["~> 1.0.0"])
72
- end
23
+ s.add_dependency("ffi", ["~> 1.0.0"])
24
+ s.add_dependency("rdoc")
25
+ s.add_dependency("rake", ["~> 0.9"])
73
26
  end
74
27
 
data/lib/ffi-geos.rb CHANGED
@@ -1,6 +1,7 @@
1
1
 
2
2
  require 'ffi'
3
3
  require 'rbconfig'
4
+ require 'ffi-geos/version'
4
5
 
5
6
  module Geos
6
7
  GEOS_BASE = File.join(File.dirname(__FILE__), 'ffi-geos')
@@ -1030,7 +1031,6 @@ module Geos
1030
1031
  end
1031
1032
 
1032
1033
  module VersionConstants
1033
- VERSION = File.read(File.join(GEOS_BASE, %w{ .. .. VERSION })).strip
1034
1034
  GEOS_JTS_PORT = Geos.jts_port
1035
1035
  GEOS_VERSION,
1036
1036
  GEOS_VERSION_MAJOR, GEOS_VERSION_MINOR, GEOS_VERSION_PATCH, GEOS_VERSION_PRERELEASE,
@@ -3,81 +3,93 @@ module Geos
3
3
  class BufferParams
4
4
  include Geos::Tools
5
5
 
6
- attr_reader :ptr, :params
7
-
8
6
  VALID_PARAMETERS = [
9
7
  :quad_segs, :endcap, :join, :mitre_limit, :single_sided
10
8
  ].freeze
11
9
 
12
10
  undef :clone, :dup
13
11
 
14
- # The defaults for the params according to GEOS are as found in
15
- # Geos::Constants::BUFFER_PARAMS_DEFAULTS. Note that when setting the
16
- # :quad_segs value that you should set it before setting other values like
17
- # :join and :mitre_limit, as GEOS contains logic concerning how the
18
- # :quad_segs value affects these parameters and vice versa. For details,
19
- # refer to src/operation/buffer/BufferParameters.cpp and the
20
- # BufferParameters::setQuadrantSegments(int) method in the GEOS source
21
- # code for details.
22
- def initialize(params = {})
23
- params = Geos::Constants::BUFFER_PARAM_DEFAULTS.merge(params)
24
-
25
- ptr = FFIGeos.GEOSBufferParams_create_r(Geos.current_handle)
26
- @ptr = FFI::AutoPointer.new(
27
- ptr,
28
- self.class.method(:release)
29
- )
30
-
31
- @params = {}
32
- VALID_PARAMETERS.each do |param|
33
- self.send("#{param}=", params[param])
12
+ if FFIGeos.respond_to?(:GEOSBufferParams_create_r)
13
+ attr_reader :ptr, :params
14
+
15
+ # The defaults for the params according to GEOS are as found in
16
+ # Geos::Constants::BUFFER_PARAMS_DEFAULTS. Note that when setting the
17
+ # :quad_segs value that you should set it before setting other values like
18
+ # :join and :mitre_limit, as GEOS contains logic concerning how the
19
+ # :quad_segs value affects these parameters and vice versa. For details,
20
+ # refer to src/operation/buffer/BufferParameters.cpp and the
21
+ # BufferParameters::setQuadrantSegments(int) method in the GEOS source
22
+ # code for details.
23
+ def initialize(params = {})
24
+ params = Geos::Constants::BUFFER_PARAM_DEFAULTS.merge(params)
25
+
26
+ ptr = FFIGeos.GEOSBufferParams_create_r(Geos.current_handle)
27
+ @ptr = FFI::AutoPointer.new(
28
+ ptr,
29
+ self.class.method(:release)
30
+ )
31
+
32
+ @params = {}
33
+ VALID_PARAMETERS.each do |param|
34
+ self.send("#{param}=", params[param])
35
+ end
34
36
  end
35
- end
36
37
 
37
- def self.release(ptr) #:nodoc:
38
- FFIGeos.GEOSBufferParams_destroy_r(Geos.current_handle, ptr)
39
- end
38
+ def self.release(ptr) #:nodoc:
39
+ FFIGeos.GEOSBufferParams_destroy_r(Geos.current_handle, ptr)
40
+ end
40
41
 
41
- def endcap=(value)
42
- check_enum_value(Geos::BufferCapStyles, value)
42
+ def endcap=(value)
43
+ check_enum_value(Geos::BufferCapStyles, value)
43
44
 
44
- if bool_result(FFIGeos.GEOSBufferParams_setEndCapStyle_r(Geos.current_handle, ptr, value))
45
- @params[:endcap] = symbol_for_enum(Geos::BufferCapStyles, value)
45
+ if bool_result(FFIGeos.GEOSBufferParams_setEndCapStyle_r(Geos.current_handle, ptr, value))
46
+ @params[:endcap] = symbol_for_enum(Geos::BufferCapStyles, value)
47
+ end
46
48
  end
47
- end
48
49
 
49
- def join=(value)
50
- check_enum_value(Geos::BufferJoinStyles, value)
50
+ def join=(value)
51
+ check_enum_value(Geos::BufferJoinStyles, value)
51
52
 
52
- if bool_result(FFIGeos.GEOSBufferParams_setJoinStyle_r(Geos.current_handle, ptr, value))
53
- @params[:join] = symbol_for_enum(Geos::BufferJoinStyles, value)
53
+ if bool_result(FFIGeos.GEOSBufferParams_setJoinStyle_r(Geos.current_handle, ptr, value))
54
+ @params[:join] = symbol_for_enum(Geos::BufferJoinStyles, value)
55
+ end
54
56
  end
55
- end
56
57
 
57
- def mitre_limit=(value)
58
- if bool_result(FFIGeos.GEOSBufferParams_setMitreLimit_r(Geos.current_handle, ptr, value))
59
- @params[:mitre_limit] = value
58
+ def mitre_limit=(value)
59
+ if bool_result(FFIGeos.GEOSBufferParams_setMitreLimit_r(Geos.current_handle, ptr, value))
60
+ @params[:mitre_limit] = value
61
+ end
60
62
  end
61
- end
62
63
 
63
- def quad_segs=(value)
64
- if bool_result(FFIGeos.GEOSBufferParams_setQuadrantSegments_r(Geos.current_handle, ptr, value))
65
- @params[:quad_segs] = value
64
+ def quad_segs=(value)
65
+ if bool_result(FFIGeos.GEOSBufferParams_setQuadrantSegments_r(Geos.current_handle, ptr, value))
66
+ @params[:quad_segs] = value
67
+ end
66
68
  end
67
- end
68
69
 
69
- def single_sided=(value)
70
- if bool_result(FFIGeos.GEOSBufferParams_setSingleSided_r(Geos.current_handle, ptr, value ? 1 : 0))
71
- @params[:single_sided] = value
70
+ def single_sided=(value)
71
+ if bool_result(FFIGeos.GEOSBufferParams_setSingleSided_r(Geos.current_handle, ptr, value ? 1 : 0))
72
+ @params[:single_sided] = value
73
+ end
72
74
  end
73
- end
74
75
 
75
- VALID_PARAMETERS.each do |param|
76
- self.class_eval(<<-EOF, __FILE__, __LINE__ + 1)
77
- def #{param}
78
- @params[:#{param}]
76
+ VALID_PARAMETERS.each do |param|
77
+ self.class_eval(<<-EOF, __FILE__, __LINE__ + 1)
78
+ def #{param}
79
+ @params[:#{param}]
80
+ end
81
+ EOF
82
+ end
83
+ else
84
+ attr_accessor(*VALID_PARAMETERS)
85
+
86
+ def initialize(params = {})
87
+ params = Geos::Constants::BUFFER_PARAM_DEFAULTS.merge(params)
88
+
89
+ VALID_PARAMETERS.each do |param|
90
+ self.send("#{param}=", params[param])
79
91
  end
80
- EOF
92
+ end
81
93
  end
82
94
  end
83
95
  end
@@ -6,13 +6,46 @@ module Geos
6
6
  class ParseError < ArgumentError
7
7
  end
8
8
 
9
+ class CoordinateAccessor
10
+ attr_accessor :parent, :dimension
11
+
12
+ include Enumerable
13
+
14
+ def initialize(parent, dimension)
15
+ @parent = parent
16
+ @dimension = dimension
17
+ end
18
+
19
+ def [](idx)
20
+ parent.get_ordinate(idx, self.dimension)
21
+ end
22
+
23
+ def []=(idx, value)
24
+ parent.set_ordinate(idx, self.dimension, value)
25
+ end
26
+
27
+ def each
28
+ if block_given?
29
+ parent.length.times do |n|
30
+ yield parent.get_ordinate(n, self.dimension)
31
+ end
32
+ self
33
+ else
34
+ parent.length.times.collect { |n|
35
+ parent.get_ordinate(n, self.dimension)
36
+ }.to_enum
37
+ end
38
+ end
39
+ end
40
+
9
41
  include Enumerable
10
42
 
11
- attr_reader :ptr
43
+ attr_reader :ptr, :x, :y, :z
12
44
 
13
45
  # :call-seq:
14
46
  # new(ptr, auto_free = true)
15
- # new(size = 0, dims = 0)
47
+ # new(size = 0, dimensions = 0)
48
+ # new(options)
16
49
  # new(points)
17
50
  #
18
51
  # The ptr version of the initializer is for internal use.
@@ -27,7 +60,7 @@ module Geos
27
60
  ptr, auto_free = if args.first.is_a?(FFI::Pointer)
28
61
  [ args.first, args[1] ]
29
62
  else
30
- size, dims = if args.first.is_a?(Array)
63
+ size, dimensions = if args.first.is_a?(Array)
31
64
  points = if args.first.first.is_a?(Array)
32
65
  args.first
33
66
  else
@@ -44,15 +77,20 @@ module Geos
44
77
  else
45
78
  [ points.length, points.first.length ]
46
79
  end
80
+ elsif args.first.is_a?(Hash)
81
+ args.first.values_at(:size, :dimensions)
47
82
  else
48
83
  if !args.length.between?(0, 2)
49
84
  raise ArgumentError.new("wrong number of arguments (#{args.length} for 0-2)")
50
85
  else
51
- [ args[0] || 0, args[1] || 0 ]
86
+ [ args[0], args[1] ]
52
87
  end
53
88
  end
54
89
 
55
- [ FFIGeos.GEOSCoordSeq_create_r(Geos.current_handle, size, dims), true ]
90
+ size ||= 0
91
+ dimensions ||= 0
92
+
93
+ [ FFIGeos.GEOSCoordSeq_create_r(Geos.current_handle, size, dimensions), true ]
56
94
  end
57
95
 
58
96
  @ptr = FFI::AutoPointer.new(
@@ -64,6 +102,10 @@ module Geos
64
102
  @ptr.autorelease = false
65
103
  end
66
104
 
105
+ @x = CoordinateAccessor.new(self, 0)
106
+ @y = CoordinateAccessor.new(self, 1)
107
+ @z = CoordinateAccessor.new(self, 2)
108
+
67
109
  if points
68
110
  points.each_with_index do |point, idx|
69
111
  point.each_with_index do |val, dim|
@@ -90,25 +132,31 @@ module Geos
90
132
  # Yields coordinates as [ x, y, z ]. The z coordinate may be omitted for
91
133
  # 2-dimensional CoordinateSequences.
92
134
  def each
93
- self.length.times do |n|
94
- yield [
95
- self.get_x(n),
96
- (self.dimensions >= 2 ? self.get_y(n) : nil),
97
- (self.dimensions >= 3 ? self.get_z(n) : nil)
98
- ].compact
135
+ if block_given?
136
+ self.length.times do |n|
137
+ yield self.build_coordinate(n)
138
+ end
139
+ self
140
+ else
141
+ self.length.times.collect { |n|
142
+ self.build_coordinate(n)
143
+ }.to_enum
99
144
  end
100
145
  end
101
146
 
147
+ # Sets the x value of a coordinate. Can also be set via #x[]=.
102
148
  def set_x(idx, val)
103
149
  self.check_bounds(idx)
104
150
  FFIGeos.GEOSCoordSeq_setX_r(Geos.current_handle, self.ptr, idx, val)
105
151
  end
106
152
 
153
+ # Sets the y value of a coordinate. Can also be set via #y[]=.
107
154
  def set_y(idx, val)
108
155
  self.check_bounds(idx)
109
156
  FFIGeos.GEOSCoordSeq_setY_r(Geos.current_handle, self.ptr, idx, val)
110
157
  end
111
158
 
159
+ # Sets the z value of a coordinate. Can also be set via #z[]=.
112
160
  def set_z(idx, val)
113
161
  self.check_bounds(idx)
114
162
  FFIGeos.GEOSCoordSeq_setZ_r(Geos.current_handle, self.ptr, idx, val)
@@ -119,6 +167,7 @@ module Geos
119
167
  FFIGeos.GEOSCoordSeq_setOrdinate_r(Geos.current_handle, self.ptr, idx, dim, val)
120
168
  end
121
169
 
170
+ # Gets the x value of a coordinate. Can also be retrieved via #x[].
122
171
  def get_x(idx)
123
172
  self.check_bounds(idx)
124
173
  FFI::MemoryPointer.new(:double).tap { |ret|
@@ -126,6 +175,7 @@ module Geos
126
175
  }.read_double
127
176
  end
128
177
 
178
+ # Gets the y value of a coordinate. Can also be retrieved via #y[].
129
179
  def get_y(idx)
130
180
  self.check_bounds(idx)
131
181
  FFI::MemoryPointer.new(:double).tap { |ret|
@@ -133,6 +183,7 @@ module Geos
133
183
  }.read_double
134
184
  end
135
185
 
186
+ # Gets the z value of a coordinate. Can also be retrieved via #z[].
136
187
  def get_z(idx)
137
188
  self.check_bounds(idx)
138
189
  FFI::MemoryPointer.new(:double).tap { |ret|
@@ -193,5 +244,13 @@ module Geos
193
244
  raise RuntimeError.new("Index out of bounds")
194
245
  end
195
246
  end
247
+
248
+ def build_coordinate(n) #:nodoc:
249
+ [
250
+ self.get_x(n),
251
+ (self.dimensions >= 2 ? self.get_y(n) : nil),
252
+ (self.dimensions >= 3 ? self.get_z(n) : nil)
253
+ ].compact
254
+ end
196
255
  end
197
256
  end
@@ -78,30 +78,51 @@ module Geos
78
78
  cast_geometry_ptr(FFIGeos.GEOSIntersection_r(Geos.current_handle, self.ptr, geom.ptr))
79
79
  end
80
80
 
81
- # :call-seq:
82
- # buffer(width)
83
- # buffer(width, options)
84
- # buffer(width, buffer_params)
85
- # buffer(width, quad_segs)
86
- #
87
- # Calls buffer on the Geometry. Options can be passed as either a
88
- # BufferParams object, as an equivalent Hash or as a quad_segs value. By
89
- # default, the default values found in Geos::Constants::BUFFER_PARAMS_DEFAULTS
90
- # are used.
91
- def buffer(width, options = nil)
92
- options ||= {}
93
- params = case options
94
- when Hash
95
- Geos::BufferParams.new(options)
96
- when Geos::BufferParams
97
- options
98
- when Numeric
99
- Geos::BufferParams.new(:quad_segs => options)
100
- else
101
- raise ArgumentError.new("Expected Geos::BufferParams, a Hash or a Numeric")
81
+ if FFIGeos.respond_to?(:GEOSBufferWithParams_r)
82
+ # :call-seq:
83
+ # buffer(width)
84
+ # buffer(width, options)
85
+ # buffer(width, buffer_params)
86
+ # buffer(width, quad_segs)
87
+ #
88
+ # Calls buffer on the Geometry. Options can be passed as either a
89
+ # BufferParams object, as an equivalent Hash or as a quad_segs value.
90
+ # Default values can be found in Geos::Constants::BUFFER_PARAM_DEFAULTS.
91
+ #
92
+ # Note that when using versions of GEOS prior to 3.3.0, only the
93
+ # quad_segs option is recognized when using Geometry#buffer and other
94
+ # options are ignored.
95
+ def buffer(width, options = nil)
96
+ options ||= {}
97
+ params = case options
98
+ when Hash
99
+ Geos::BufferParams.new(options)
100
+ when Geos::BufferParams
101
+ options
102
+ when Numeric
103
+ Geos::BufferParams.new(:quad_segs => options)
104
+ else
105
+ raise ArgumentError.new("Expected Geos::BufferParams, a Hash or a Numeric")
106
+ end
107
+
108
+ cast_geometry_ptr(FFIGeos.GEOSBufferWithParams_r(Geos.current_handle, self.ptr, params.ptr, width))
102
109
  end
110
+ else
111
+ def buffer(width, options = nil)
112
+ options ||= {}
113
+ quad_segs = case options
114
+ when Hash
115
+ Geos::BufferParams.new(options).quad_segs
116
+ when Geos::BufferParams
117
+ options.quad_segs
118
+ when Numeric
119
+ options
120
+ else
121
+ raise ArgumentError.new("Expected Geos::BufferParams, a Hash or a Numeric")
122
+ end
103
123
 
104
- cast_geometry_ptr(FFIGeos.GEOSBufferWithParams_r(Geos.current_handle, self.ptr, params.ptr, width))
124
+ cast_geometry_ptr(FFIGeos.GEOSBuffer_r(Geos.current_handle, self.ptr, width, quad_segs))
125
+ end
105
126
  end
106
127
 
107
128
  def convex_hull
@@ -280,11 +301,6 @@ module Geos
280
301
  end
281
302
  end
282
303
 
283
- def disjoint?(geom)
284
- check_geometry(geom)
285
- bool_result(FFIGeos.GEOSDisjoint_r(Geos.current_handle, self.ptr, geom.ptr))
286
- end
287
-
288
304
  def eql?(geom)
289
305
  check_geometry(geom)
290
306
  bool_result(FFIGeos.GEOSEquals_r(Geos.current_handle, self.ptr, geom.ptr))
@@ -0,0 +1,5 @@
1
+
2
+ module Geos
3
+ VERSION = "0.0.5"
4
+ end
5
+
@@ -196,4 +196,79 @@ class CoordinateSequenceTests < Test::Unit::TestCase
196
196
  cs = Geos::CoordinateSequence.new([[1, 2, 3], [10, 11, 12]])
197
197
  assert_equal("1.0 2.0 3.0, 10.0 11.0 12.0", cs.to_s)
198
198
  end
199
+
200
+ def test_get_by_proxy
201
+ cs = Geos::CoordinateSequence.new([[1, 2], [10, 11]])
202
+
203
+ assert_equal(1, cs.x[0])
204
+ assert_equal(10, cs.x[1])
205
+
206
+ assert_equal(2, cs.y[0])
207
+ assert_equal(11, cs.y[1])
208
+
209
+ assert_equal('NaN', cs.z[0].to_s)
210
+ assert_equal('NaN', cs.z[1].to_s)
211
+
212
+ assert_raise(RuntimeError) do
213
+ cs.x[100]
214
+ end
215
+
216
+ assert_raise(RuntimeError) do
217
+ cs.y[100]
218
+ end
219
+
220
+ assert_raise(RuntimeError) do
221
+ cs.z[100]
222
+ end
223
+ end
224
+
225
+ def test_set_by_proxy
226
+ cs = Geos::CoordinateSequence.new(2)
227
+ cs.x[0] = 1
228
+ cs.x[1] = 10
229
+
230
+ cs.y[0] = 2
231
+ cs.y[1] = 11
232
+
233
+ assert_equal(1, cs.get_x(0))
234
+ assert_equal(10, cs.get_x(1))
235
+
236
+ assert_equal(2, cs.get_y(0))
237
+ assert_equal(11, cs.get_y(1))
238
+
239
+ assert_raise(RuntimeError) do
240
+ cs.x[100] = 10
241
+ end
242
+
243
+ assert_raise(RuntimeError) do
244
+ cs.y[100] = 10
245
+ end
246
+
247
+ assert_raise(RuntimeError) do
248
+ cs.z[100] = 10
249
+ end
250
+ end
251
+
252
+ def test_proxy_enumerator
253
+ cs = Geos::CoordinateSequence.new(10)
254
+
255
+ assert_kind_of(Enumerable, cs.x.each)
256
+ assert_kind_of(Enumerable, cs.x.to_enum)
257
+ assert_equal(cs.x, cs.x.each {})
258
+ end
259
+
260
+ def test_options_hash
261
+ cs = Geos::CoordinateSequence.new(:size => 10, :dimensions => 2)
262
+
263
+ assert_equal(10, cs.size)
264
+ assert_equal(2, cs.dimensions)
265
+ end
266
+
267
+ def test_enumerator
268
+ cs = Geos::CoordinateSequence.new(10)
269
+
270
+ assert_kind_of(Enumerable, cs.each)
271
+ assert_kind_of(Enumerable, cs.to_enum)
272
+ assert_equal(cs, cs.each {})
273
+ end
199
274
  end
data/test/test_helper.rb CHANGED
@@ -8,7 +8,7 @@ else
8
8
  require File.join(File.dirname(__FILE__), %w{ .. lib ffi-geos })
9
9
  end
10
10
 
11
- puts "Ruby version #{RUBY_VERSION} - #{RbConfig::CONFIG['RUBY_INSTALL_NAME']}"
11
+ puts "Ruby version #{RUBY_VERSION}-p#{RUBY_PATCHLEVEL} - #{RbConfig::CONFIG['RUBY_INSTALL_NAME']}"
12
12
  puts "ffi version #{Gem.loaded_specs['ffi'].version}" if Gem.loaded_specs['ffi']
13
13
  puts "GEOS version #{Geos::GEOS_VERSION}"
14
14
  puts "ffi-geos version #{Geos::VERSION}" if defined?(Geos::VERSION)
data/test/utils_tests.rb CHANGED
@@ -55,7 +55,7 @@ class UtilsTests < Test::Unit::TestCase
55
55
  def test_bad_create_point
56
56
  cs = Geos::CoordinateSequence.new(0, 0)
57
57
  assert_raise(RuntimeError) do
58
- geom = Geos.create_point(cs)
58
+ Geos.create_point(cs)
59
59
  end
60
60
  end
61
61
 
@@ -87,7 +87,7 @@ class UtilsTests < Test::Unit::TestCase
87
87
  def test_create_bad_line_string
88
88
  cs = Geos::CoordinateSequence.new(1, 0)
89
89
  assert_raise(RuntimeError) do
90
- geom = Geos::create_line_string(cs)
90
+ Geos::create_line_string(cs)
91
91
  end
92
92
  end
93
93
 
@@ -126,7 +126,7 @@ class UtilsTests < Test::Unit::TestCase
126
126
  cs = Geos::CoordinateSequence.new(1, 0)
127
127
 
128
128
  assert_raise(RuntimeError) do
129
- geom = Geos::create_linear_ring(cs)
129
+ Geos::create_linear_ring(cs)
130
130
  end
131
131
  end
132
132
 
@@ -114,7 +114,7 @@ class WktReaderTests < Test::Unit::TestCase
114
114
 
115
115
  def test_read_exception
116
116
  assert_raise(RuntimeError) do
117
- geom = read('gibberish')
117
+ read('gibberish')
118
118
  end
119
119
  end
120
120
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ffi-geos
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-02-28 00:00:00.000000000 Z
12
+ date: 2012-07-25 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: ffi
16
- requirement: &2169057720 !ruby/object:Gem::Requirement
16
+ requirement: !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,7 +21,44 @@ dependencies:
21
21
  version: 1.0.0
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *2169057720
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: 1.0.0
30
+ - !ruby/object:Gem::Dependency
31
+ name: rdoc
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: rake
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: '0.9'
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '0.9'
25
62
  description: An ffi wrapper for GEOS, a C++ port of the Java Topology Suite (JTS).
26
63
  email: dark.panda@gmail.com
27
64
  executables: []
@@ -29,10 +66,11 @@ extensions: []
29
66
  extra_rdoc_files:
30
67
  - README.rdoc
31
68
  files:
69
+ - .gitignore
70
+ - Gemfile
32
71
  - MIT-LICENSE
33
72
  - README.rdoc
34
73
  - Rakefile
35
- - VERSION
36
74
  - ffi-geos.gemspec
37
75
  - lib/ffi-geos.rb
38
76
  - lib/ffi-geos/buffer_params.rb
@@ -50,6 +88,7 @@ files:
50
88
  - lib/ffi-geos/strtree.rb
51
89
  - lib/ffi-geos/tools.rb
52
90
  - lib/ffi-geos/utils.rb
91
+ - lib/ffi-geos/version.rb
53
92
  - lib/ffi-geos/wkb_reader.rb
54
93
  - lib/ffi-geos/wkb_writer.rb
55
94
  - lib/ffi-geos/wkt_reader.rb
@@ -86,8 +125,20 @@ required_rubygems_version: !ruby/object:Gem::Requirement
86
125
  version: '0'
87
126
  requirements: []
88
127
  rubyforge_project:
89
- rubygems_version: 1.8.16
128
+ rubygems_version: 1.8.23
90
129
  signing_key:
91
130
  specification_version: 3
92
131
  summary: An ffi wrapper for GEOS, a C++ port of the Java Topology Suite (JTS).
93
- test_files: []
132
+ test_files:
133
+ - test/coordinate_sequence_tests.rb
134
+ - test/geometry_tests.rb
135
+ - test/misc_tests.rb
136
+ - test/point_tests.rb
137
+ - test/prepared_geometry_tests.rb
138
+ - test/strtree_tests.rb
139
+ - test/test_helper.rb
140
+ - test/utils_tests.rb
141
+ - test/wkb_reader_tests.rb
142
+ - test/wkb_writer_tests.rb
143
+ - test/wkt_reader_tests.rb
144
+ - test/wkt_writer_tests.rb
data/VERSION DELETED
@@ -1 +0,0 @@
1
- 0.0.4