@@ -15,29 +15,38 @@ defmodule GeospatialTest do
1515
1616 test "circle" do
1717 { :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
1919 end
2020
2121 test "circle with opts" do
2222 { :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
2424 end
25-
2625 test "distance" do
2726 { :ok , % Record { data: data } } = distance ( point ( { 1 , 1 } ) , point ( { 2 , 2 } ) ) |> run
2827 assert data == 156876.14940188665
2928 end
30-
29+
3130 test "fill" do
3231 { :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 } ] ] }
3433 end
3534
3635 test "geojson" do
3736 { :ok , % Record { data: data } } = geojson ( % { coordinates: [ 1 , 1 ] , type: "Point" } ) |> run
3837 assert data == % Point { coordinates: { 1 , 1 } }
3938 end
4039
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+
4150 test "to_geojson" do
4251 { :ok , % Record { data: data } } = point ( { 1 , 1 } ) |> to_geojson |> run
4352 assert data == % { "type" => "Point" , "coordinates" => [ 1 , 1 ] }
@@ -82,14 +91,13 @@ defmodule GeospatialTest do
8291
8392 test "polygon" do
8493 { :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 } ] ]
8695 end
8796
8897 test "polygon_sub" do
8998 p1 = polygon ( [ { 0 , 0 } , { 0 , 1 } , { 1 , 1 } , { 1 , 0 } ] )
9099 p2 = polygon ( [ { 0.25 , 0.25 } , { 0.25 , 0.5 } , { 0.5 , 0.5 } , { 0.5 , 0.25 } ] )
91100 { :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 } ] ]
94102 end
95103end
0 commit comments