terraformer 0.0.9 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,105 @@
1
+ require_relative './helper'
2
+
3
+ describe Terraformer::Point do
4
+
5
+ describe 'construction' do
6
+ it 'constructs from coordinate' do
7
+ c = Terraformer::Coordinate.new -122.6764, 45.5165
8
+ p = Terraformer::Point.new c
9
+ p.must_be_valid_geojson
10
+ p.to_json.must_equal '{"type":"Point","coordinates":[-122.6764,45.5165]}'
11
+ end
12
+
13
+ it 'constructs from array' do
14
+ p = Terraformer::Point.new [-122.6764, 45.5165]
15
+ p.must_be_valid_geojson
16
+ p.to_json.must_equal '{"type":"Point","coordinates":[-122.6764,45.5165]}'
17
+ end
18
+
19
+ it 'costructs from numeric' do
20
+ p = Terraformer::Point.new -122.6764, 45.5165
21
+ p.must_be_valid_geojson
22
+ p.to_json.must_equal '{"type":"Point","coordinates":[-122.6764,45.5165]}'
23
+ end
24
+ end
25
+
26
+ describe 'methods' do
27
+ before :each do
28
+ @p = Terraformer::Point.new [-122.6764, 45.5165]
29
+ end
30
+
31
+ it 'should have coordinates' do
32
+ c = Terraformer::Coordinate.new -122.6764, 45.5165
33
+ @p.coordinates.must_equal c
34
+ end
35
+
36
+ it 'first_coordinate should equal coordinates' do
37
+ @p.first_coordinate.must_equal @p.coordinates
38
+ end
39
+
40
+ describe 'distance and bearing' do
41
+ before :each do
42
+ @p2 = Terraformer::Point.new [-122, 45]
43
+ end
44
+
45
+ it 'should get distance_and_bearing_to point' do
46
+ dabt = @p.distance_and_bearing_to(@p2)
47
+ dabt[0][:distance].must_equal 78159.08126203461
48
+ dabt[0][:bearing][:initial].must_equal 136.9932756675306
49
+ dabt[0][:bearing][:final].must_equal 137.473721440933
50
+ end
51
+
52
+ it 'should get distance_to point' do
53
+ @p.distance_to(@p2).must_equal 78159.08126203461
54
+ end
55
+
56
+ it 'should get initial_bearing_to point' do
57
+ @p.initial_bearing_to(@p2).must_equal 136.9932756675306
58
+ end
59
+
60
+ it 'should get final_bearing_to point' do
61
+ @p.final_bearing_to(@p2).must_equal 137.473721440933
62
+ end
63
+
64
+ # TODO: write tests for different types of objects
65
+ end
66
+
67
+ describe 'contains?' do
68
+
69
+ it 'should contains equal point' do
70
+ assert @p.contains?(@p)
71
+ end
72
+
73
+ it 'should not contains unequal point' do
74
+ p2 = Terraformer::Point.new [-122, 45]
75
+ assert !@p.contains?(p2)
76
+ end
77
+
78
+ it 'should error on contains for other type' do
79
+ l = Terraformer::LineString.new [-122, 45], [-123, 46]
80
+
81
+ assert_raises ArgumentError do
82
+ !@p.contains?(l)
83
+ end
84
+
85
+ end
86
+ end
87
+
88
+ describe 'within?' do
89
+
90
+ it 'should be within same point' do
91
+ assert @p.within?(@p)
92
+ end
93
+
94
+ it 'should not be within unequal point' do
95
+ p2 = Terraformer::Point.new [-122, 45]
96
+ assert !@p.within?(p2)
97
+ end
98
+
99
+ # TODO: write tests for other classes
100
+ end
101
+
102
+ end
103
+
104
+
105
+ end
@@ -0,0 +1,142 @@
1
+ require_relative './helper'
2
+
3
+ describe Terraformer::Polygon do
4
+
5
+ describe 'construction' do
6
+ it 'constructs from coordinates' do
7
+ a = Terraformer::Coordinate.new -122.6764, 45.5165
8
+ b = a + [0, 0.02]
9
+ c = b + [0.02, 0]
10
+ d = c + [0, -0.02]
11
+ p = Terraformer::Polygon.new a, b, c, d, a
12
+ p.to_json.must_equal '{"type":"Polygon","coordinates":[[[-122.6764,45.5165],[-122.6764,45.5365],[-122.6564,45.5365],[-122.6564,45.5165],[-122.6764,45.5165]]]}'
13
+ p.must_be_valid_geojson
14
+ end
15
+
16
+ it 'constructs from coordinates array' do
17
+ a = Terraformer::Coordinate.new -122.6764, 45.5165
18
+ b = a + [0, 0.02]
19
+ c = b + [0.02, 0]
20
+ d = c + [0, -0.02]
21
+ p = Terraformer::Polygon.new [a, b, c, d, a]
22
+ p.to_json.must_equal '{"type":"Polygon","coordinates":[[[-122.6764,45.5165],[-122.6764,45.5365],[-122.6564,45.5365],[-122.6564,45.5165],[-122.6764,45.5165]]]}'
23
+ p.must_be_valid_geojson
24
+ end
25
+
26
+ it 'constructs from array' do
27
+ p = Terraformer::Polygon.new [[[-122.6764,45.5165],[-122.6764,45.5365],[-122.6564,45.5365],[-122.6564,45.5165],[-122.6764,45.5165]]]
28
+ p.to_json.must_equal '{"type":"Polygon","coordinates":[[[-122.6764,45.5165],[-122.6764,45.5365],[-122.6564,45.5365],[-122.6564,45.5165],[-122.6764,45.5165]]]}'
29
+ p.must_be_valid_geojson
30
+ end
31
+
32
+ it 'constructs with holes from coordinates arrays' do
33
+ a = Terraformer::Coordinate.new -122.6764, 45.5165
34
+ b = a + [0, 0.02]
35
+ c = b + [0.02, 0]
36
+ d = c + [0, -0.02]
37
+ hole = [
38
+ [ -122.67072200775145, 45.52438983143154 ],
39
+ [ -122.67072200775145, 45.53241707548722 ],
40
+ [ -122.6617956161499, 45.53241707548722 ],
41
+ [ -122.6617956161499, 45.52438983143154 ],
42
+ [ -122.67072200775145, 45.52438983143154 ]
43
+ ].map {|c| Terraformer::Coordinate.new c}
44
+ p = Terraformer::Polygon.new [a, b, c, d, a], hole
45
+ p.to_json.must_equal '{"type":"Polygon","coordinates":[[[-122.6764,45.5165],[-122.6764,45.5365],[-122.6564,45.5365],[-122.6564,45.5165],[-122.6764,45.5165]],[[-122.67072200775145,45.52438983143154],[-122.67072200775145,45.53241707548722],[-122.6617956161499,45.53241707548722],[-122.6617956161499,45.52438983143154],[-122.67072200775145,45.52438983143154]]]}'
46
+ p.must_be_valid_geojson
47
+ end
48
+
49
+ it 'constructs with holes from array' do
50
+ p = Terraformer::Polygon.new [[[-122.6764,45.5165],[-122.6764,45.5365],[-122.6564,45.5365],[-122.6564,45.5165],[-122.6764,45.5165]],[[-122.67072200775145,45.52438983143154],[-122.67072200775145,45.53241707548722],[-122.6617956161499,45.53241707548722],[-122.6617956161499,45.52438983143154],[-122.67072200775145,45.52438983143154]]]
51
+ p.to_json.must_equal '{"type":"Polygon","coordinates":[[[-122.6764,45.5165],[-122.6764,45.5365],[-122.6564,45.5365],[-122.6564,45.5165],[-122.6764,45.5165]],[[-122.67072200775145,45.52438983143154],[-122.67072200775145,45.53241707548722],[-122.6617956161499,45.53241707548722],[-122.6617956161499,45.52438983143154],[-122.67072200775145,45.52438983143154]]]}'
52
+ p.must_be_valid_geojson
53
+ end
54
+
55
+ describe 'modification methods' do
56
+
57
+ before :each do
58
+ @a = Terraformer::Coordinate.new -122, 45
59
+ @b = @a + [0.1, 0.1]
60
+ @c = @b + [0.1, 0.1]
61
+
62
+ @p = Terraformer::Polygon.new @a, @b, @c, @a
63
+
64
+ @d = @c + [0.1, 0.1]
65
+ end
66
+
67
+ it 'should add coordinate' do
68
+ @p.add_vertex @d
69
+ @p.coordinates.must_equal [[ @a, @b, @c, @d, @a ]]
70
+ end
71
+
72
+ it 'should add point' do
73
+ d = Terraformer::Point.new @d
74
+ @p.add_vertex d
75
+ @p.coordinates.must_equal [[ @a, @b, @c, @d, @a ]]
76
+ end
77
+
78
+ it 'should return add argument error' do
79
+ assert_raises ArgumentError do
80
+ @p.add_vertex 1
81
+ end
82
+ end
83
+
84
+ it 'should << coordinate' do
85
+ @p << @d
86
+ @p.coordinates.must_equal [[ @a, @b, @c, @d, @a ]]
87
+ end
88
+
89
+ it 'should << point' do
90
+ d = Terraformer::Point.new @d
91
+ @p << d
92
+ @p.coordinates.must_equal [[ @a, @b, @c, @d, @a ]]
93
+ end
94
+
95
+ it 'should return << argument error' do
96
+ assert_raises ArgumentError do
97
+ @p << 1
98
+ end
99
+ end
100
+
101
+ it 'should insert coordinate' do
102
+ @p.insert_vertex 1, @d
103
+ @p.coordinates.must_equal [[ @a, @d, @b, @c, @a ]]
104
+ end
105
+
106
+ it 'should insert point' do
107
+ d = Terraformer::Point.new @d
108
+ @p.insert_vertex 1, d
109
+ @p.coordinates.must_equal [[ @a, @d, @b, @c, @a ]]
110
+ end
111
+
112
+ it 'should return insert argument error' do
113
+ assert_raises ArgumentError do
114
+ @p.insert_vertex 1, 1
115
+ end
116
+ end
117
+
118
+ it 'should remove coordinate' do
119
+ @p.remove_vertex @b
120
+ @p.coordinates.must_equal [[ @a, @c, @a ]]
121
+ end
122
+
123
+ it 'should remove point' do
124
+ d = Terraformer::Point.new @b
125
+ @p.remove_vertex d
126
+ @p.coordinates.must_equal [[ @a, @c, @a ]]
127
+ end
128
+
129
+ it 'should return remove argument error' do
130
+ assert_raises ArgumentError do
131
+ @p.remove_vertex 1
132
+ end
133
+ end
134
+
135
+ it 'should remove vertex at index' do
136
+ @p.remove_vertex_at 1
137
+ @p.coordinates.must_equal [[ @a, @c, @a ]]
138
+ end
139
+ end
140
+
141
+ end
142
+ 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.9
4
+ version: 0.1.0
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-12-30 00:00:00.000000000 Z
11
+ date: 2015-02-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: launchy
@@ -39,7 +39,6 @@ files:
39
39
  - lib/ext/big_decimal.rb
40
40
  - lib/ext/big_math.rb
41
41
  - lib/ext/enumerable.rb
42
- - lib/ext/hash.rb
43
42
  - lib/terraformer.rb
44
43
  - lib/terraformer/arcgis.rb
45
44
  - lib/terraformer/bounds.rb
@@ -59,7 +58,9 @@ files:
59
58
  - lib/terraformer/version.rb
60
59
  - terraformer.gemspec
61
60
  - test/arcgis_spec.rb
61
+ - test/circle_spec.rb
62
62
  - test/convex_hull_spec.rb
63
+ - test/coordinate_spec.rb
63
64
  - test/examples/cascadiagons.geojson
64
65
  - test/examples/circle.geojson
65
66
  - test/examples/geometry_collection.geojson
@@ -74,6 +75,11 @@ files:
74
75
  - test/examples/waldocanyon.geojson
75
76
  - test/geometry_spec.rb
76
77
  - test/helper.rb
78
+ - test/line_string_spec.rb
79
+ - test/multi_line_string_spec.rb
80
+ - test/multi_point_spec.rb
81
+ - test/point_spec.rb
82
+ - test/polygon_spec.rb
77
83
  - test/primitive_spec.rb
78
84
  - test/terraformer_spec.rb
79
85
  homepage: https://github.com/esripdx/terraformer-ruby
@@ -102,7 +108,9 @@ specification_version: 4
102
108
  summary: ''
103
109
  test_files:
104
110
  - test/arcgis_spec.rb
111
+ - test/circle_spec.rb
105
112
  - test/convex_hull_spec.rb
113
+ - test/coordinate_spec.rb
106
114
  - test/examples/cascadiagons.geojson
107
115
  - test/examples/circle.geojson
108
116
  - test/examples/geometry_collection.geojson
@@ -117,5 +125,10 @@ test_files:
117
125
  - test/examples/waldocanyon.geojson
118
126
  - test/geometry_spec.rb
119
127
  - test/helper.rb
128
+ - test/line_string_spec.rb
129
+ - test/multi_line_string_spec.rb
130
+ - test/multi_point_spec.rb
131
+ - test/point_spec.rb
132
+ - test/polygon_spec.rb
120
133
  - test/primitive_spec.rb
121
134
  - test/terraformer_spec.rb
data/lib/ext/hash.rb DELETED
@@ -1,21 +0,0 @@
1
- class Hash
2
-
3
- unless instance_methods.include? :only
4
- # same as select_with_keys without forcing `Symbol` usage
5
- #
6
- def only *ks
7
- ks = ks.compact.uniq
8
- select {|k,v| ks.include? k}
9
- end
10
- end
11
-
12
- unless instance_methods.include? :not
13
- # same as select_without_keys without forcing `Symbol` usage
14
- #
15
- def not *ks
16
- ks = ks.compact.uniq
17
- select {|k,v| !ks.include? k}
18
- end
19
- end
20
-
21
- end