From fbe8e2d2253f9950905241dfb8c773500f9c9265 Mon Sep 17 00:00:00 2001 From: Leif Linse Date: Fri, 26 Jan 2024 11:00:03 +0100 Subject: [PATCH] Fix some changes got lost in a previous rebase --- lib/src/line_slice.dart | 6 +++--- test/components/line_slice_test.dart | 8 ++++++-- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/lib/src/line_slice.dart b/lib/src/line_slice.dart index 17059fb..66da783 100644 --- a/lib/src/line_slice.dart +++ b/lib/src/line_slice.dart @@ -10,7 +10,7 @@ import 'package:turf/src/invariant.dart'; /// as the resolved line would only contain one point which isn't supported by LineString. /// /// This can be useful for extracting only the part of a route between waypoints. -Feature lineSlice( +Feature? lineSlice( Point startPt, Point stopPt, Feature line) { final coords = line.geometry; if (coords == null) { @@ -19,7 +19,7 @@ Feature lineSlice( final startVertex = nearestPointOnLine(coords, startPt); final stopVertex = nearestPointOnLine(coords, stopPt); - if (startVertex['index'] == stopVertex['index']) { + if (startVertex.properties!['index'] == stopVertex.properties!['index']) { // LineString do not allow 1 point lines return null; } @@ -31,7 +31,7 @@ Feature lineSlice( } final List clipCoords = [getCoord(ends[0])]; for (var i = ends[0].properties!['index'] + 1; - i < ends[1].properties!['index'] + 1; + i < ends[1].properties!['index']; i++) { clipCoords.add(coords.coordinates[i]); } diff --git a/test/components/line_slice_test.dart b/test/components/line_slice_test.dart index cf42499..8d6eecd 100644 --- a/test/components/line_slice_test.dart +++ b/test/components/line_slice_test.dart @@ -9,7 +9,8 @@ void main() { test('lineSlice - exact points', () { final slice = lineSlice( Point(coordinates: start), Point(coordinates: via), lineFeature); - expect(slice.properties, isNotNull); + expect(slice, isNotNull); + expect(slice!.properties, isNotNull); expect(slice.properties!.keys, contains(propName)); expect(slice.properties![propName], equals(propValue)); @@ -17,6 +18,7 @@ void main() { geometry: LineString(coordinates: [start, via]), ); expect(slice.geometry, isNotNull); + expect(slice.geometry!.coordinates, hasLength(2)); expect(length(slice).round(), equals(length(expectedLineFeature).round())); }); test('lineSlice - interpolation', () { @@ -26,7 +28,8 @@ void main() { expect(startPt, isNotNull); final slice = lineSlice(startPt, Point(coordinates: via), lineFeature); - expect(slice.properties, isNotNull); + expect(slice, isNotNull); + expect(slice!.properties, isNotNull); expect(slice.properties!.keys, contains(propName)); expect(slice.properties![propName], equals(propValue)); @@ -34,6 +37,7 @@ void main() { geometry: LineString(coordinates: [start, via]), ); expect(slice.geometry, isNotNull); + expect(slice.geometry!.coordinates, hasLength(2)); expect( length(slice, Unit.meters).round(), equals(length(expectedLine, Unit.meters).round() - skipDist),