@@ -15,29 +15,38 @@ defmodule GeospatialTest do
15
15
16
16
test "circle" do
17
17
{ :ok , % Record { data: data } } = circle ( { 1 , 1 } , 5 ) |> run
18
- assert % Polygon { outer_coordinates : [ _h | _t ] , inner_coordinates: [ ] } = data
18
+ assert % Polygon { coordinates : [ _h | [ ] ] } = data
19
19
end
20
20
21
21
test "circle with opts" do
22
22
{ :ok , % Record { data: data } } = circle ( { 1 , 1 } , 5 , num_vertices: 100 , fill: true ) |> run
23
- assert % Polygon { outer_coordinates : [ _h | _t ] , inner_coordinates: [ ] } = data
23
+ assert % Polygon { coordinates : [ _h | [ ] ] } = data
24
24
end
25
-
26
25
test "distance" do
27
26
{ :ok , % Record { data: data } } = distance ( point ( { 1 , 1 } ) , point ( { 2 , 2 } ) ) |> run
28
27
assert data == 156876.14940188665
29
28
end
30
-
29
+
31
30
test "fill" do
32
31
{ :ok , % Record { data: data } } = fill ( line ( [ { 1 , 1 } , { 4 , 5 } , { 2 , 2 } , { 1 , 1 } ] ) ) |> run
33
- assert data == % Polygon { outer_coordinates : [ { 1 , 1 } , { 4 , 5 } , { 2 , 2 } , { 1 , 1 } ] }
32
+ assert data == % Polygon { coordinates : [ [ { 1 , 1 } , { 4 , 5 } , { 2 , 2 } , { 1 , 1 } ] ] }
34
33
end
35
34
36
35
test "geojson" do
37
36
{ :ok , % Record { data: data } } = geojson ( % { coordinates: [ 1 , 1 ] , type: "Point" } ) |> run
38
37
assert data == % Point { coordinates: { 1 , 1 } }
39
38
end
40
39
40
+ test "geojson with holes" do
41
+ coords = [ square ( 0 , 0 , 10 ) , square ( 1 , 1 , 1 ) , square ( 4 , 4 , 1 ) ]
42
+ { :ok , % Record { data: data } } = geojson ( % { type: "Polygon" , coordinates: coords } ) |> run
43
+ assert data == % Polygon { coordinates: coords }
44
+ end
45
+
46
+ defp square ( x , y , s ) do
47
+ [ { x , y } , { x + s , y } , { x + s , y + s } , { x , y + s } , { x , y } ]
48
+ end
49
+
41
50
test "to_geojson" do
42
51
{ :ok , % Record { data: data } } = point ( { 1 , 1 } ) |> to_geojson |> run
43
52
assert data == % { "type" => "Point" , "coordinates" => [ 1 , 1 ] }
@@ -82,14 +91,13 @@ defmodule GeospatialTest do
82
91
83
92
test "polygon" do
84
93
{ :ok , % Record { data: data } } = polygon ( [ { 0 , 0 } , { 0 , 1 } , { 1 , 1 } , { 1 , 0 } ] ) |> run
85
- assert data . outer_coordinates == [ { 0 , 0 } , { 0 , 1 } , { 1 , 1 } , { 1 , 0 } , { 0 , 0 } ]
94
+ assert data . coordinates == [ [ { 0 , 0 } , { 0 , 1 } , { 1 , 1 } , { 1 , 0 } , { 0 , 0 } ] ]
86
95
end
87
96
88
97
test "polygon_sub" do
89
98
p1 = polygon ( [ { 0 , 0 } , { 0 , 1 } , { 1 , 1 } , { 1 , 0 } ] )
90
99
p2 = polygon ( [ { 0.25 , 0.25 } , { 0.25 , 0.5 } , { 0.5 , 0.5 } , { 0.5 , 0.25 } ] )
91
100
{ :ok , % Record { data: data } } = p1 |> polygon_sub ( p2 ) |> run
92
- assert data . outer_coordinates == [ { 0 , 0 } , { 0 , 1 } , { 1 , 1 } , { 1 , 0 } , { 0 , 0 } ]
93
- assert data . inner_coordinates == [ { 0.25 , 0.25 } , { 0.25 , 0.5 } , { 0.5 , 0.5 } , { 0.5 , 0.25 } , { 0.25 , 0.25 } ]
101
+ assert data . coordinates == [ [ { 0 , 0 } , { 0 , 1 } , { 1 , 1 } , { 1 , 0 } , { 0 , 0 } ] , [ { 0.25 , 0.25 } , { 0.25 , 0.5 } , { 0.5 , 0.5 } , { 0.5 , 0.25 } , { 0.25 , 0.25 } ] ]
94
102
end
95
103
end
0 commit comments