Skip to content

Commit

Permalink
feat(perf): perform bbox culling prior to aggressive culling for poly…
Browse files Browse the repository at this point in the history
…lines (#1993)
  • Loading branch information
JaffaKetchup authored Dec 5, 2024
1 parent b81d6db commit 4dc3bca
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/src/layer/polygon_layer/polygon.dart
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ class Polygon<R extends Object> {

LatLngBounds? _boundingBox;

/// Get the bounding box of the [Polygon.points] (cached).
/// Get the bounding box of the [points] (cached).
LatLngBounds get boundingBox =>
_boundingBox ??= LatLngBounds.fromPoints(points);

Expand Down
6 changes: 6 additions & 0 deletions lib/src/layer/polyline_layer/polyline.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ class Polyline<R extends Object> {
/// {@macro fm.hde.hitValue}
final R? hitValue;

LatLngBounds? _boundingBox;

/// Get the bounding box of the [points] (cached).
LatLngBounds get boundingBox =>
_boundingBox ??= LatLngBounds.fromPoints(points);

/// Create a new [Polyline] used for the [PolylineLayer].
Polyline({
required this.points,
Expand Down
4 changes: 4 additions & 0 deletions lib/src/layer/polyline_layer/polyline_layer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,10 @@ class _PolylineLayerState<R extends Object> extends State<PolylineLayer<R>>
for (final projectedPolyline in polylines) {
final polyline = projectedPolyline.polyline;

// Test bounding boxes to avoid potentially expensive aggressive culling
// when none of the line is visible
if (!boundsAdjusted.isOverlapping(polyline.boundingBox)) continue;

// Gradient poylines cannot be easily segmented
if (polyline.gradientColors != null) {
yield projectedPolyline;
Expand Down

0 comments on commit 4dc3bca

Please sign in to comment.