computeBounds method

Aabb3? computeBounds({
  1. double sigmaPadding = 3.0,
})

Computes the axis-aligned bounds of the splat centers, each padded by sigmaPadding times the splat's largest axis scale so the visible footprint stays inside the box.

Implementation

vm.Aabb3? computeBounds({double sigmaPadding = 3.0}) {
  if (count == 0) return null;
  var minX = double.infinity, minY = double.infinity, minZ = double.infinity;
  var maxX = double.negativeInfinity,
      maxY = double.negativeInfinity,
      maxZ = double.negativeInfinity;
  for (var i = 0; i < count; i++) {
    final o = i * 3;
    final r =
        sigmaPadding *
        math.max(
          scales[o].abs(),
          math.max(scales[o + 1].abs(), scales[o + 2].abs()),
        );
    final x = positions[o], y = positions[o + 1], z = positions[o + 2];
    if (x - r < minX) minX = x - r;
    if (y - r < minY) minY = y - r;
    if (z - r < minZ) minZ = z - r;
    if (x + r > maxX) maxX = x + r;
    if (y + r > maxY) maxY = y + r;
    if (z + r > maxZ) maxZ = z + r;
  }
  return vm.Aabb3.minMax(
    vm.Vector3(minX, minY, minZ),
    vm.Vector3(maxX, maxY, maxZ),
  );
}