terraformer 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/test/helper.rb CHANGED
@@ -9,7 +9,16 @@ $:.unshift lib unless $:.include? lib
9
9
  require 'terraformer'
10
10
 
11
11
  module MiniTest::Expectations
12
+
13
+ GEOJSON_VALIDATE_URL = 'http://geojsonlint.com/validate'
14
+
15
+ def validate_geojson geojson_h
16
+ r = JSON.parse HTTP['Content-Type' => 'application/json'].post(GEOJSON_VALIDATE_URL, json: geojson_h).body
17
+ r['status'].must_equal 'ok'
18
+ end
19
+
12
20
  infect_an_assertion :refute_nil, :dont_be_terrible_ok, :unary
21
+ infect_an_assertion :validate_geojson, :must_be_valid_geojson, :unary
13
22
  end
14
23
 
15
24
  examples = File.expand_path '../examples', __FILE__
@@ -18,3 +27,6 @@ EXAMPLES = Dir[examples + '/*.geojson'].reduce({}) do |h, gj|
18
27
  File.read(gj).gsub(/\r*\n*/,'').gsub(' ',' ')
19
28
  h
20
29
  end
30
+
31
+ PARSED_EXAMPLES = EXAMPLES.keys.reduce({}){|h,k| h[k] = Terraformer.parse EXAMPLES[k]; h}
32
+
@@ -0,0 +1,64 @@
1
+ require_relative './helper'
2
+
3
+ describe Terraformer::Primitive do
4
+
5
+ describe 'envelope' do
6
+
7
+ it 'returns envelope with ne origin and size' do
8
+ c = Terraformer.parse EXAMPLES[:circle]
9
+ c.dont_be_terrible_ok
10
+ env = c.envelope
11
+ env[:x].must_equal BigDecimal("0.9999910168471585E2")
12
+ env[:y].must_equal BigDecimal("-0.8983152838976E-3")
13
+ env[:w].must_equal BigDecimal("0.179663056825E-2")
14
+ env[:h].must_equal BigDecimal("0.17966305681389E-2")
15
+ end
16
+
17
+ end
18
+
19
+ describe 'bbox' do
20
+
21
+ it 'returns a geojson bounding box' do
22
+ c = Terraformer.parse EXAMPLES[:circle]
23
+ c.dont_be_terrible_ok
24
+ bbox = c.bbox
25
+ bbox.must_equal ["0.9999910168471585E2",
26
+ "-0.8983152838976E-3",
27
+ "0.1000008983152841E3",
28
+ "0.8983152842413E-3"].map {|n| BigDecimal(n)}
29
+ end
30
+
31
+ it 'returns a geojson polygon of the bounding box' do
32
+ c = Terraformer.parse EXAMPLES[:circle]
33
+ c.dont_be_terrible_ok
34
+ bbox = c.bbox :polygon
35
+ expected = Terraformer::Polygon.new [[99.99910168471585, -0.0008983152838976],
36
+ [99.99910168471585, 0.0008983152842413],
37
+ [100.0008983152841, 0.0008983152842413],
38
+ [100.0008983152841, -0.0008983152838976],
39
+ [99.99910168471585, -0.0008983152838976]]
40
+ bbox.must_equal expected
41
+ end
42
+
43
+ end
44
+
45
+ describe 'to_json' do
46
+
47
+ it 'returns a geojson object' do
48
+ c = Terraformer.parse EXAMPLES[:circle]
49
+ JSON.parse(c.to_json).must_equal JSON.parse(EXAMPLES[:circle])
50
+ end
51
+
52
+ it 'returns a geojson object with bbox' do
53
+ c = Terraformer.parse EXAMPLES[:circle]
54
+ expected = JSON.parse(EXAMPLES[:circle])
55
+ expected['bbox'] = [0.9999910168471585E2,
56
+ -0.8983152838976E-3,
57
+ 0.1000008983152841E3,
58
+ 0.8983152842413E-3]
59
+ JSON.parse(c.to_json(include_bbox: true)).must_equal expected
60
+ end
61
+
62
+ end
63
+
64
+ end
@@ -21,9 +21,11 @@ describe Terraformer do
21
21
  p.dont_be_terrible_ok
22
22
  p.type.must_equal 'MultiPoint'
23
23
  p.coordinates.must_be_instance_of Array
24
- p.coordinates.length.must_equal 2
24
+ p.coordinates.length.must_equal 4
25
25
  p.coordinates[0].must_equal Terraformer::Coordinate.new 100, 0
26
26
  p.coordinates[1].must_equal Terraformer::Coordinate.new 101, 1
27
+ p.coordinates[2].must_equal Terraformer::Coordinate.new 100, 1
28
+ p.coordinates[3].must_equal Terraformer::Coordinate.new 99, 0
27
29
  end
28
30
 
29
31
  it 'parses line strings' do
@@ -31,9 +33,11 @@ describe Terraformer do
31
33
  p.dont_be_terrible_ok
32
34
  p.type.must_equal 'LineString'
33
35
  p.coordinates.must_be_instance_of Array
34
- p.coordinates.length.must_equal 2
36
+ p.coordinates.length.must_equal 4
35
37
  p.coordinates[0].must_equal Terraformer::Coordinate.new 100, 0
36
38
  p.coordinates[1].must_equal Terraformer::Coordinate.new 101, 1
39
+ p.coordinates[2].must_equal Terraformer::Coordinate.new 100, 1
40
+ p.coordinates[3].must_equal Terraformer::Coordinate.new 99, 0
37
41
  end
38
42
 
39
43
  it 'parses multi line strings' do
@@ -132,6 +136,42 @@ describe Terraformer do
132
136
  JSON.parse(c.to_json).must_equal JSON.parse(EXAMPLES[:circle])
133
137
  end
134
138
 
139
+ it 'rounds buffered vertices to PRECISION' do
140
+ p = Terraformer.parse EXAMPLES[:point]
141
+ p.dont_be_terrible_ok
142
+ c = p.coordinates.buffer 100
143
+ splitter = ->(d) {
144
+ a = d.split
145
+ a[1][a[3]..-1].length
146
+ }
147
+ c.coordinates.each_coordinate do |c|
148
+ splitter[c.x].must_be :<=, Terraformer::PRECISION
149
+ splitter[c.x].must_be :<=, Terraformer::PRECISION
150
+ end
151
+ end
152
+
153
+ end
154
+
155
+ describe 'coordinates_contain_point?' do
156
+
157
+ it 'returns true when point is in coordinates' do
158
+ coordinates = [[10,10],[20,10],[20,20],[10,20],[10,10]]
159
+ point = [15,15]
160
+ Terraformer::Geometry.coordinates_contain_point?(coordinates, point).must_equal true
161
+ end
162
+
163
+ it 'returns false when point is not in coordinates' do
164
+ coordinates = [[10,10],[20,10],[20,20],[10,20],[10,10]]
165
+ point = [25,25]
166
+ Terraformer::Geometry.coordinates_contain_point?(coordinates, point).must_equal false
167
+ end
168
+
169
+ it 'returns true when point is on edge of coordinates' do
170
+ coordinates = [[10,10],[20,10],[20,20],[10,20],[10,10]]
171
+ point = [15,10]
172
+ Terraformer::Geometry.coordinates_contain_point?(coordinates, point).must_equal true
173
+ end
174
+
135
175
  end
136
176
 
137
177
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: terraformer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kenichi Nakamura
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-05-08 00:00:00.000000000 Z
11
+ date: 2014-05-27 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: ''
14
14
  email:
@@ -21,11 +21,20 @@ files:
21
21
  - Gemfile
22
22
  - README.md
23
23
  - Rakefile
24
+ - lib/ext/array.rb
25
+ - lib/ext/big_decimal.rb
26
+ - lib/ext/big_math.rb
27
+ - lib/ext/enumerable.rb
28
+ - lib/ext/hash.rb
24
29
  - lib/terraformer.rb
25
30
  - lib/terraformer/bounds.rb
31
+ - lib/terraformer/circle.rb
32
+ - lib/terraformer/convex_hull.rb
26
33
  - lib/terraformer/coordinate.rb
27
34
  - lib/terraformer/feature.rb
35
+ - lib/terraformer/geodesic.rb
28
36
  - lib/terraformer/geometry.rb
37
+ - lib/terraformer/geometry/class_methods.rb
29
38
  - lib/terraformer/line_string.rb
30
39
  - lib/terraformer/multi_line_string.rb
31
40
  - lib/terraformer/multi_point.rb
@@ -34,6 +43,7 @@ files:
34
43
  - lib/terraformer/polygon.rb
35
44
  - lib/terraformer/version.rb
36
45
  - terraformer.gemspec
46
+ - test/convex_hull_spec.rb
37
47
  - test/examples/circle.geojson
38
48
  - test/examples/geometry_collection.geojson
39
49
  - test/examples/line_string.geojson
@@ -43,7 +53,11 @@ files:
43
53
  - test/examples/point.geojson
44
54
  - test/examples/polygon.geojson
45
55
  - test/examples/polygon_with_holes.geojson
56
+ - test/examples/sf_county.geojson
57
+ - test/examples/waldocanyon.geojson
58
+ - test/geometry_spec.rb
46
59
  - test/helper.rb
60
+ - test/primitive_spec.rb
47
61
  - test/terraformer_spec.rb
48
62
  homepage: https://github.com/esripdx/terraformer-ruby
49
63
  licenses:
@@ -70,6 +84,7 @@ signing_key:
70
84
  specification_version: 4
71
85
  summary: ''
72
86
  test_files:
87
+ - test/convex_hull_spec.rb
73
88
  - test/examples/circle.geojson
74
89
  - test/examples/geometry_collection.geojson
75
90
  - test/examples/line_string.geojson
@@ -79,5 +94,9 @@ test_files:
79
94
  - test/examples/point.geojson
80
95
  - test/examples/polygon.geojson
81
96
  - test/examples/polygon_with_holes.geojson
97
+ - test/examples/sf_county.geojson
98
+ - test/examples/waldocanyon.geojson
99
+ - test/geometry_spec.rb
82
100
  - test/helper.rb
101
+ - test/primitive_spec.rb
83
102
  - test/terraformer_spec.rb