discontinuedPackage jet_cad_floor_plan has been discontinued and replaced by jet_cad_2d_plan.

firstLeafOf function

({EntityKind kind, GeometryPayload payload})? firstLeafOf(
  1. DraftDocument doc,
  2. Handle owner, [
  3. Map<Handle, List<int>>? leavesByOwner
])

The lowest-handle leaf owner owns, or null. O(entities): at command or document-change rate, never per frame. With leavesByOwner (DraftDocument.leavesByOwner, shared by a caller asking for many owners in one pass), only owner's own leaves are visited.

Implementation

({EntityKind kind, GeometryPayload payload})? firstLeafOf(
    DraftDocument doc, Handle owner,
    [Map<Handle, List<int>>? leavesByOwner]) {
  final entities = doc.entities;
  int? best;
  final slots = leavesByOwner == null
      ? entities.liveSlots
      : leavesByOwner[owner] ?? const <int>[];
  for (final slot in slots) {
    if (entities.ownerAt(slot) != owner) continue;
    if (best == null ||
        entities.handleAt(slot).value < entities.handleAt(best).value) {
      best = slot;
    }
  }
  if (best == null) return null;
  return (
    kind: entities.kindAt(best),
    payload: doc.geometry.read(entities.geomIndexAt(best)),
  );
}