minimumFor static method

DiagramSize minimumFor({
  1. required DiagramRect bounds,
  2. required Iterable<({DiagramRect frame, DiagramSize minimum})> members,
})

Aggregate minimum that preserves every framed member's declared minimum. Inputs use resolved frames from the same scene as bounds.

Implementation

static DiagramSize minimumFor({
  required DiagramRect bounds,
  required Iterable<({DiagramRect frame, DiagramSize minimum})> members,
}) {
  var scaleX = 0.0;
  var scaleY = 0.0;
  for (final member in members) {
    if (![
      member.frame.width,
      member.frame.height,
      member.minimum.width,
      member.minimum.height,
    ].every((value) => value.isFinite && value > 0)) {
      throw ArgumentError('Resize members require finite positive sizes');
    }
    scaleX = math.max(scaleX, member.minimum.width / member.frame.width);
    scaleY = math.max(scaleY, member.minimum.height / member.frame.height);
  }
  // Connector-only selections still need representably positive geometry.
  const epsilon = 2.220446049250313e-16;
  return DiagramSize(
    scaleX > 0
        ? bounds.width * scaleX
        : math.max(
            double.minPositive,
            math.max(
                  bounds.width,
                  math.max(bounds.left.abs(), bounds.right.abs()),
                ) *
                epsilon,
          ),
    scaleY > 0
        ? bounds.height * scaleY
        : math.max(
            double.minPositive,
            math.max(
                  bounds.height,
                  math.max(bounds.top.abs(), bounds.bottom.abs()),
                ) *
                epsilon,
          ),
  );
}