discontinuedPackage jet_cad_floor_plan has been discontinued and replaced by jet_cad_2d_plan.

placeCut function

Cut? placeCut(
  1. List<(double, double)> stretches,
  2. double c,
  3. double w
)

Where an opening centred at c with width w cuts (spec 08 D8), among stretches (sorted, as stretchesOf gives them):

  1. the candidates are the stretches at least w long;
  2. none: no fit, null;
  3. the chosen one is the candidate nearest c (the distance from c to the interval, 0 inside it); ties go to the lower a;
  4. the cut is [x, x + w] with x = clamp(c − w/2, a, b − w), and it is clamped when x ≠ c − w/2: exact, since an unclamped x is c − w/2 itself.

Null too for a degenerate opening (D6): a width not greater than wallJoin.linear, or a non-finite width or centre.

Implementation

Cut? placeCut(List<(double, double)> stretches, double c, double w) {
  if (!c.isFinite || !w.isFinite || !(w > wallJoin.linear)) return null;
  (double, double)? best;
  var bestDistance = double.infinity;
  for (final s in stretches) {
    final (a, b) = s;
    if (!(w <= b - a)) continue;
    final distance = c < a ? a - c : (c > b ? c - b : 0.0);
    if (distance < bestDistance) {
      best = s;
      bestDistance = distance;
    }
  }
  if (best == null) return null;
  final (a, b) = best;
  final want = c - w / 2;
  var x = want;
  if (x < a) x = a;
  if (x > b - w) x = b - w;
  return (a: x, b: x + w, clamped: x != want);
}