Skip to content

Commit

Permalink
Minor improvement to remove anonymous function instant invocation pat…
Browse files Browse the repository at this point in the history
…tern by using `any` method on list
  • Loading branch information
JaffaKetchup committed Sep 12, 2024
1 parent 31fd4ba commit b15c074
Showing 1 changed file with 16 additions and 22 deletions.
38 changes: 16 additions & 22 deletions lib/src/layer/polygon_layer/painter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -64,36 +64,30 @@ base class _PolygonPainter<R extends Object>
origin: hitTestCameraOrigin,
points: projectedPolygon.points,
);

if (projectedCoords.first != projectedCoords.last) {
projectedCoords.add(projectedCoords.first);
}

final isValidPolygon = projectedCoords.length >= 3;
final isInPolygon =
isValidPolygon && isPointInPolygon(point, projectedCoords);

final hasHoles = projectedPolygon.holePoints.isNotEmpty;
final isInHole = hasHoles &&
() {
for (final points in projectedPolygon.holePoints) {
final projectedHoleCoords = getOffsetsXY(
camera: camera,
origin: hitTestCameraOrigin,
points: points,
);

if (projectedHoleCoords.first != projectedHoleCoords.last) {
projectedHoleCoords.add(projectedHoleCoords.first);
}
final isInHole = projectedPolygon.holePoints.any(
(points) {
final projectedHoleCoords = getOffsetsXY(
camera: camera,
origin: hitTestCameraOrigin,
points: points,
);
if (projectedHoleCoords.first != projectedHoleCoords.last) {
projectedHoleCoords.add(projectedHoleCoords.first);
}

final isValidHolePolygon = projectedHoleCoords.length >= 3;
if (isValidHolePolygon &&
isPointInPolygon(point, projectedHoleCoords)) {
return true;
}
}
return false;
}();
final isValidHolePolygon = projectedHoleCoords.length >= 3;
return isValidHolePolygon &&
isPointInPolygon(point, projectedHoleCoords);
},
);

// Second check handles case where polygon outline intersects a hole,
// ensuring that the hit matches with the visual representation
Expand Down

0 comments on commit b15c074

Please sign in to comment.