Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(perf): perform bbox culling prior to aggressive culling for polylines #1993

Merged
merged 3 commits into from
Dec 5, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/src/layer/polygon_layer/polygon.dart
Original file line number Diff line number Diff line change
@@ -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);

6 changes: 6 additions & 0 deletions lib/src/layer/polyline_layer/polyline.dart
Original file line number Diff line number Diff line change
@@ -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,
4 changes: 4 additions & 0 deletions lib/src/layer/polyline_layer/polyline_layer.dart
Original file line number Diff line number Diff line change
@@ -143,6 +143,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
// where none of the line is visibles
JaffaKetchup marked this conversation as resolved.
Show resolved Hide resolved
if (!boundsAdjusted.isOverlapping(polyline.boundingBox)) continue;

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