Skip to content

Commit

Permalink
fix equality bug for lineStrings (#12)
Browse files Browse the repository at this point in the history
* ignore .DS_Store files

* add simple lineString tests

* fix equality bug for lineString
  • Loading branch information
jsiedentop authored Feb 14, 2024
1 parent 693d586 commit 1815e14
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ build/
# Omit committing pubspec.lock for library packages; see
# https://dart.dev/guides/libraries/private-files#pubspeclock.
pubspec.lock
.DS_Store
2 changes: 1 addition & 1 deletion lib/src/turf_equality_base.dart
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ class Equality {
line1.coordinates.first, newLine.coordinates.first)) {
return false;
} else {
_compareLine(line1, newLine);
return _compareLine(line1, newLine);
}
}
} else {
Expand Down
25 changes: 25 additions & 0 deletions test/context/helper.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import 'package:turf/helpers.dart';

LineString lineString(List<List<int>> coordinates) {
return LineString(coordinates: coordinates.toPositions());
}

Point point(List<double> coordinates) {
return Point(coordinates: Position.of(coordinates));
}

Feature<Polygon> polygon(List<List<List<int>>> coordinates) {
return Feature(
geometry: Polygon(coordinates: coordinates.toPositions()),
);
}

extension PointsExtension on List<List<int>> {
List<Position> toPositions() =>
map((position) => Position.of(position)).toList(growable: false);
}

extension PolygonPointsExtensions on List<List<List<int>>> {
List<List<Position>> toPositions() =>
map((element) => element.toPositions()).toList(growable: false);
}
33 changes: 33 additions & 0 deletions test/geojson_equality_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,40 @@ import 'package:turf_equality/turf_equality.dart';
import 'package:test/test.dart';
import 'package:turf/helpers.dart';

import 'context/helper.dart';

void main() {
group('LineString Equality', () {
Equality eq = Equality();
test('two points, different values', () {
final result = eq.compare(
lineString([
[125, -30],
[135, -30],
]),
lineString([
[115, -35],
[125, -30],
]),
);
expect(result, false);
});

test('two points, same value', () {
final result = eq.compare(
lineString([
[115, -35],
[125, -30],
]),
lineString([
[115, -35],
[125, -30],
]),
);
expect(result, true);
});
});

group(
'Turf GeoJSONEquality',
() {
Expand Down

0 comments on commit 1815e14

Please sign in to comment.