estimateAppearancePaintBounds function

Rect2D? estimateAppearancePaintBounds({
  1. required Rect2D? sourceBounds,
  2. required bool foregroundPresent,
  3. required Iterable<CanvasSourceUnderlay> underlays,
})

Estimates visible paint for a text/icon appearance.

sourceBounds describes the original source silhouette estimate.

The source bounds are included directly only when foregroundPresent is true. Underlays always derive independently from sourceBounds.

This affects paint/content bounds only. It does not alter source layout, pivots, selection, hit testing, or snapping.

Implementation

Rect2D? estimateAppearancePaintBounds({
  required Rect2D? sourceBounds,
  required bool foregroundPresent,
  required Iterable<CanvasSourceUnderlay> underlays,
}) {
  if (sourceBounds == null) return null;

  Rect2D? result = foregroundPresent ? sourceBounds : null;

  for (final underlay in underlays) {
    final underlayBounds = estimateSourceUnderlayPaintBounds(
      sourceBounds,
      underlay,
    );

    if (underlayBounds == null) continue;

    result = result == null
        ? underlayBounds
        : Rect2DX.union(result, underlayBounds);
  }

  return result;
}