-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6bfda8b
commit a2f1ae3
Showing
3 changed files
with
33 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
import 'dart:developer'; | ||
|
||
import 'package:turf/turf.dart'; | ||
|
||
/// | ||
|
@@ -43,24 +45,31 @@ Position getCoord(dynamic coord) { | |
/// var coords = turf.getCoords(poly); | ||
/// //= [[[119.32, -8.7], [119.55, -8.69], [119.51, -8.54], [119.32, -8.7]]] | ||
/// | ||
List getCoords(dynamic coords) { | ||
List<dynamic> getCoords(dynamic coords) { | ||
if (coords == null) { | ||
throw Exception("coords is required"); | ||
} | ||
|
||
if (coords is List) { | ||
return coords; | ||
} | ||
|
||
if (coords is Feature && coords.geometry != null) { | ||
_getCoordsForGeometry(coords.geometry!); | ||
} | ||
|
||
if (coords is List) { | ||
return coords; | ||
if (coords is GeometryType) { | ||
_getCoordsForGeometry(coords.coordinates); | ||
} | ||
return _getCoordsForGeometry(coords); | ||
|
||
throw Exception( | ||
"{Array<any>|Geometry|Feature} coords Feature, Geometry Object or an Array"); | ||
This comment has been minimized.
Sorry, something went wrong.
lukas-h
Member
|
||
} | ||
|
||
_getCoordsForGeometry(GeometryObject geom) { | ||
if (geom is Point || geom is GeometryCollection) { | ||
throw Exception("Type must contain a list of Positions e.g Polygon"); | ||
} | ||
|
||
return (geom as GeometryType).coordinates; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,9 @@ | ||
import 'dart:math'; | ||
|
||
import 'package:test/test.dart'; | ||
import 'package:turf/helpers.dart'; | ||
import 'package:turf/src/invariant.dart'; | ||
// import 'package:collection/collection.dart'; | ||
|
||
main() { | ||
LineString line1 = LineString(coordinates: [Position(1, 2), Position(3, 4)]); | ||
|
@@ -18,12 +21,23 @@ main() { | |
test("invariant -- getCoords", () { | ||
var feature2 = Feature<LineString>(geometry: line1); | ||
expect(() => getCoords(null), throwsA(isA<Exception>())); | ||
expect(() => getCoords(feature1), throwsA(isA<Exception>())); | ||
expect( | ||
getCoords([ | ||
[119.32, -8.7], | ||
This comment has been minimized.
Sorry, something went wrong.
lukas-h
Member
|
||
[119.55, -8.69], | ||
[119.51, -8.54], | ||
[119.32, -8.7] | ||
]), | ||
equals([ | ||
[119.32, -8.7], | ||
[119.55, -8.69], | ||
[119.51, -8.54], | ||
[119.32, -8.7] | ||
])); | ||
expect(() => getCoords(feature1), throwsA(isA<Exception>())); | ||
expect(() => getCoords(feature1), throwsA(isA<Exception>())); | ||
var coords = getCoords(feature2); | ||
expect(coords.length, feature2.geometry!.coordinates.length); | ||
expect(coords.first, feature2.geometry!.coordinates.first); | ||
expect(coords.last, feature2.geometry!.coordinates.last); | ||
|
||
expect(coords, equals([Position(1, 2), Position(3, 4)])); | ||
This comment has been minimized.
Sorry, something went wrong.
lukas-h
Member
|
||
}); | ||
/* | ||
|
typo