Skip to content

Commit

Permalink
Code review suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
jsiedentop committed Feb 17, 2024
1 parent dbce5ab commit 02f4584
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 53 deletions.
20 changes: 10 additions & 10 deletions lib/src/booleans/boolean_contains.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,22 @@ import 'boolean_helper.dart';
/// [booleanContains] returns the exact opposite result of the [booleanWithin].
/// example:
/// ```dart
/// var line = LineString(coordinates: [
/// final line = LineString(coordinates: [
/// Position.of([1, 1]),
/// Position.of([1, 2]),
/// Position.of([1, 3]),
/// Position.of([1, 4])
/// ]);
/// var point = Point(coordinates: Position.of([1, 2]));
/// final point = Point(coordinates: Position.of([1, 2]));
/// booleanContains(line, point);
/// //=true
/// ```
bool booleanContains(GeoJSONObject feature1, GeoJSONObject feature2) {
var geom1 = getGeom(feature1);
var geom2 = getGeom(feature2);
final geom1 = getGeom(feature1);
final geom2 = getGeom(feature2);

var coords1 = (geom1 as GeometryType).coordinates;
var coords2 = (geom2 as GeometryType).coordinates;
final coords1 = (geom1 as GeometryType).coordinates;
final coords2 = (geom2 as GeometryType).coordinates;
if (geom1 is Point) {
if (geom2 is Point) {
return coords1 == coords2;
Expand Down Expand Up @@ -73,14 +73,14 @@ bool booleanContains(GeoJSONObject feature1, GeoJSONObject feature2) {
/// Is Polygon2 in Polygon1
/// Only takes into account outer rings
bool _isPolyInPoly(GeoJSONObject geom1, GeoJSONObject geom2) {
var poly1Bbox = bbox(geom1);
var poly2Bbox = bbox(geom2);
final poly1Bbox = bbox(geom1);
final poly2Bbox = bbox(geom2);
if (!_doBBoxesOverlap(poly1Bbox, poly2Bbox)) {
return false;
}

for (var ring in (geom2 as GeometryType).coordinates) {
for (var coord in ring) {
for (final ring in (geom2 as GeometryType).coordinates) {
for (final coord in ring) {
if (!booleanPointInPolygon(coord, geom1)) {
return false;
}
Expand Down
8 changes: 4 additions & 4 deletions lib/src/booleans/boolean_helper.dart
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,8 @@ bool isLineInMultiPolygon(LineString line, MultiPolygon polygon) =>
_isLineInGeoJsonPolygon(line, polygon);

bool _isLineInGeoJsonPolygon(LineString line, GeoJSONObject polygon) {
var boundingBoxOfPolygon = bbox(polygon);
var boundingBoxOfLine = bbox(line);
final boundingBoxOfPolygon = bbox(polygon);
final boundingBoxOfLine = bbox(line);

if (!_doBBoxesOverlap(boundingBoxOfPolygon, boundingBoxOfLine)) {
return false;
Expand Down Expand Up @@ -197,8 +197,8 @@ bool _isPolygonInGeoJsonPolygon(
Polygon polygon1,
GeoJSONObject polygon2,
) {
var boundingBoxOfPolygon1 = bbox(polygon1);
var boundingBoxOfPolygon2 = bbox(polygon2);
final boundingBoxOfPolygon1 = bbox(polygon1);
final boundingBoxOfPolygon2 = bbox(polygon2);
if (!_doBBoxesOverlap(boundingBoxOfPolygon2, boundingBoxOfPolygon1)) {
return false;
}
Expand Down
29 changes: 0 additions & 29 deletions lib/src/booleans/discussion.md

This file was deleted.

20 changes: 10 additions & 10 deletions test/booleans/within_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ void main() {
(path, geoJson) {
final multiPolygon = (geoJson as Feature);
final pointInHole = point([-86.69208526611328, 36.20373274711739]);
var pointInPolygon = point([-86.72229766845702, 36.20258997094334]);
var pointInSecondPolygon =
final pointInPolygon = point([-86.72229766845702, 36.20258997094334]);
final pointInSecondPolygon =
point([-86.75079345703125, 36.18527313913089]);

expect(booleanWithin(pointInHole, multiPolygon), false,
Expand All @@ -59,7 +59,7 @@ void main() {
});

test("within - point in polygon", () {
var simplePolygon = polygon([
final simplePolygon = polygon([
[
[0, 0],
[0, 100],
Expand All @@ -68,15 +68,15 @@ void main() {
[0, 0],
],
]);
var pointIn = point([50, 50]);
var pointOut = point([140, 150]);
final pointIn = point([50, 50]);
final pointOut = point([140, 150]);

expect(booleanWithin(pointIn, simplePolygon), true,
reason: "point inside polygon");
expect(booleanWithin(pointOut, simplePolygon), false,
reason: "point outside polygon");

var concavePolygon = polygon([
final concavePolygon = polygon([
[
[0, 0],
[50, 50],
Expand All @@ -87,8 +87,8 @@ void main() {
],
]);

var pointInConcave = point([75, 75]);
var pointOutConcave = point([25, 50]);
final pointInConcave = point([75, 75]);
final pointOutConcave = point([25, 50]);

expect(booleanWithin(pointInConcave, concavePolygon), true,
reason: "point inside concave polygon");
Expand All @@ -108,9 +108,9 @@ void loadGeoJson(

void loadGeoJsonFiles(
String path, void Function(String path, GeoJSONObject geoJson) test) {
var testDirectory = Directory(path);
final testDirectory = Directory(path);

for (var file in testDirectory.listSync(recursive: true)) {
for (final file in testDirectory.listSync(recursive: true)) {
if (file is File && file.path.endsWith('.geojson')) {
if (file.path.contains('skip')) continue;

Expand Down

0 comments on commit 02f4584

Please sign in to comment.