From ab54f6bc5ef48fb23d00b883c3c8c377946ec661 Mon Sep 17 00:00:00 2001 From: Arman Torkzaban Date: Tue, 15 Mar 2022 16:13:20 +0100 Subject: [PATCH 1/7] beginning --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 6359f4d..fee2844 100644 --- a/README.md +++ b/README.md @@ -128,7 +128,7 @@ Any new benchmarks must be named `*_benchmark.dart` and reside in the - [ ] clustersKmeans ### META -- [ ] coordAll +- [x] coordAll - [x] coordEach - [ ] coordReduce - [x] featureEach From 9cc0eab0352ad8fb96034268161c53f8c0d00fe6 Mon Sep 17 00:00:00 2001 From: Arman Torkzaban Date: Wed, 16 Mar 2022 09:25:51 +0100 Subject: [PATCH 2/7] wip coordAll --- lib/src/meta.dart | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/lib/src/meta.dart b/lib/src/meta.dart index 7f53519..e56edbb 100644 --- a/lib/src/meta.dart +++ b/lib/src/meta.dart @@ -309,3 +309,33 @@ void featureEach(GeoJSONObject geoJSON, FeatureEachCallback callback) { throw Exception('Unknown Feature/FeatureCollection Type'); } } + +/// Gets all coordinates from any [GeoJSONObject]. +/// Receives any [GeoJSONObject] +/// Returns List +/// For example: +/// +/// ```dart +/// var featureColl = FeatureCollection(features: +/// [Feature(geometry: Point(coordinates: Position(13,15))) +/// ,Feature(geometry: LineString(coordinates: [Position(1, 2), +/// Position(67, 50)]))]); +/// +/// var coords = coordAll(features); +/// //= [Position(13,15), Position(1, 2), Position(67, 50)] +/// @Lukas: return Position or CoordinateType? +/// +List coordAll(GeoJSONObject geojson) { + List coords = []; + coordEach(geojson, ( + CoordinateType? currentCoord, + int? coordIndex, + int? featureIndex, + int? multiFeatureIndex, + int? geometryIndex, + ) { + coords.add(currentCoord); + return true; + }); + return coords; +} From 620479f6dba96fb30d29fd4df158dbc5a014b209 Mon Sep 17 00:00:00 2001 From: Arman Torkzaban Date: Wed, 16 Mar 2022 11:53:30 +0100 Subject: [PATCH 3/7] coordAll test, WIP --- lib/src/meta.dart | 1 + test/components/meta_test.dart | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/lib/src/meta.dart b/lib/src/meta.dart index e56edbb..67f0cc2 100644 --- a/lib/src/meta.dart +++ b/lib/src/meta.dart @@ -1,6 +1,7 @@ import 'geojson.dart'; typedef CoordEachCallback = dynamic Function( + //todo: can we change this Position CoordinateType? currentCoord, int? coordIndex, int? featureIndex, diff --git a/test/components/meta_test.dart b/test/components/meta_test.dart index 7179ccc..276686b 100644 --- a/test/components/meta_test.dart +++ b/test/components/meta_test.dart @@ -652,4 +652,36 @@ main() { expect(multiCount, 1, reason: func.toString()); } }); + + test('meta -- coordAll', () { + FeatureCollection lines = FeatureCollection( + features: [ + Feature( + geometry: LineString.fromJson({ + 'coordinates': [ + [10, 10], + [50, 30], + [30, 40] + ] + }), + ), + Feature( + geometry: LineString.fromJson({ + 'coordinates': [ + [-10, -10], + [-50, -30], + [-30, -40] + ] + }), + ), + ], + ); + + List results = coordAll(lines) as List; + expect(results, [ + Position.of([10, 10]), + Position.of([50, 30]), + Position.of([30, 40]) + ]); + }); } From ac75b875d20d1fb2eced309e11483d532302a979 Mon Sep 17 00:00:00 2001 From: Arman Torkzaban Date: Wed, 16 Mar 2022 13:32:38 +0100 Subject: [PATCH 4/7] changes CoordEachCallback's signature --- lib/src/meta.dart | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/src/meta.dart b/lib/src/meta.dart index 67f0cc2..16210ee 100644 --- a/lib/src/meta.dart +++ b/lib/src/meta.dart @@ -2,7 +2,7 @@ import 'geojson.dart'; typedef CoordEachCallback = dynamic Function( //todo: can we change this Position - CoordinateType? currentCoord, + Position? currentCoord, int? coordIndex, int? featureIndex, int? multiFeatureIndex, @@ -15,7 +15,7 @@ typedef CoordEachCallback = dynamic Function( /// For example: /// /// ```dart -/// // TODO add example +/// //TODO add example /// ``` void coordEach(GeoJSONObject geoJSON, CoordEachCallback callback, [bool excludeWrapCoord = false]) { @@ -66,7 +66,7 @@ void coordEach(GeoJSONObject geoJSON, CoordEachCallback callback, : 0; if (geomType == GeoJSONObjectType.point) { - if (callback(coords as CoordinateType, coordIndex, featureIndex, + if (callback(coords as Position, coordIndex, featureIndex, multiFeatureIndex, geometryIndex) == false) { throw _ShortCircuit(); @@ -326,10 +326,10 @@ void featureEach(GeoJSONObject geoJSON, FeatureEachCallback callback) { /// //= [Position(13,15), Position(1, 2), Position(67, 50)] /// @Lukas: return Position or CoordinateType? /// -List coordAll(GeoJSONObject geojson) { - List coords = []; +List coordAll(GeoJSONObject geojson) { + List coords = []; coordEach(geojson, ( - CoordinateType? currentCoord, + Position? currentCoord, int? coordIndex, int? featureIndex, int? multiFeatureIndex, From d64ba45c0183cec133e254e89a1c9a4188273ee7 Mon Sep 17 00:00:00 2001 From: Arman Torkzaban Date: Thu, 17 Mar 2022 07:43:26 +0100 Subject: [PATCH 5/7] typecast removed, test corrected --- lib/src/meta.dart | 5 ++--- test/components/meta_test.dart | 7 +++++-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/lib/src/meta.dart b/lib/src/meta.dart index 16210ee..2e54cb9 100644 --- a/lib/src/meta.dart +++ b/lib/src/meta.dart @@ -66,8 +66,8 @@ void coordEach(GeoJSONObject geoJSON, CoordEachCallback callback, : 0; if (geomType == GeoJSONObjectType.point) { - if (callback(coords as Position, coordIndex, featureIndex, - multiFeatureIndex, geometryIndex) == + if (callback(coords, coordIndex, featureIndex, multiFeatureIndex, + geometryIndex) == false) { throw _ShortCircuit(); } @@ -324,7 +324,6 @@ void featureEach(GeoJSONObject geoJSON, FeatureEachCallback callback) { /// /// var coords = coordAll(features); /// //= [Position(13,15), Position(1, 2), Position(67, 50)] -/// @Lukas: return Position or CoordinateType? /// List coordAll(GeoJSONObject geojson) { List coords = []; diff --git a/test/components/meta_test.dart b/test/components/meta_test.dart index 276686b..8743fba 100644 --- a/test/components/meta_test.dart +++ b/test/components/meta_test.dart @@ -677,11 +677,14 @@ main() { ], ); - List results = coordAll(lines) as List; + List results = coordAll(lines); expect(results, [ Position.of([10, 10]), Position.of([50, 30]), - Position.of([30, 40]) + Position.of([30, 40]), + Position.of([-10, -10]), + Position.of([-50, -30]), + Position.of([-30, -40]), ]); }); } From d5abc6af2dae68d20b0961cd7fe84d0ffd2a2acc Mon Sep 17 00:00:00 2001 From: Arman Torkzaban Date: Mon, 21 Mar 2022 08:21:06 +0100 Subject: [PATCH 6/7] changes before merging --- lib/src/meta.dart | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/src/meta.dart b/lib/src/meta.dart index 2e54cb9..bb341db 100644 --- a/lib/src/meta.dart +++ b/lib/src/meta.dart @@ -1,7 +1,6 @@ import 'geojson.dart'; typedef CoordEachCallback = dynamic Function( - //todo: can we change this Position Position? currentCoord, int? coordIndex, int? featureIndex, From ed2218473fec9e3112f4b41bad41fedb037cebc7 Mon Sep 17 00:00:00 2001 From: Lukas Himsel Date: Mon, 21 Mar 2022 09:13:03 +0100 Subject: [PATCH 7/7] refactor for Position in CoordEachCallback --- lib/src/meta.dart | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/src/meta.dart b/lib/src/meta.dart index 5650653..51782db 100644 --- a/lib/src/meta.dart +++ b/lib/src/meta.dart @@ -55,9 +55,9 @@ void _forEachCoordInGeometryObject( : 0; indexCounter.multiFeatureIndex = 0; - dynamic coords = geometry.coordinates as Iterable; + var coords = geometry.coordinates; if (geomType == GeoJSONObjectType.point) { - _forEachCoordInPoint(coords as CoordinateType, callback, indexCounter); + _forEachCoordInPoint(coords, callback, indexCounter); } else if (geomType == GeoJSONObjectType.lineString || geomType == GeoJSONObjectType.multiPoint) { _forEachCoordInCollection(coords, geomType, callback, indexCounter); @@ -141,8 +141,8 @@ void _forEachCoordInCollection(coords, GeoJSONObjectType geomType, } } -void _forEachCoordInPoint(CoordinateType coords, CoordEachCallback callback, - _IndexCounter indexCounter) { +void _forEachCoordInPoint( + Position coords, CoordEachCallback callback, _IndexCounter indexCounter) { if (callback(coords, indexCounter.coordIndex, indexCounter.featureIndex, indexCounter.multiFeatureIndex, indexCounter.geometryIndex) == false) {