referenceWalk function

void referenceWalk(
  1. DraftDocument doc,
  2. DrawSink sink,
  3. ViewportTransform camera,
  4. Size viewport,
  5. StyleResolver resolver, {
  6. double minTextCapPixels = kMinTextCapPixels,
  7. Set<Handle> omitOwners = const {},
})

Draws the document the slow, obvious way, so DraftPainter can be compared against it.

It uses no SpatialIndex. No packed tree, no dirty overlay, no container index, no scratch buffers, no cull floor, no anisotropy bypass — it walks doc.tree from the root, reads leaves through leavesByOwner, composes transforms with Transform2.multiply, and keeps an entity when its world-space entityBounds meets the view. That independence is the whole value: two implementations sharing a mistake agree, and a test comparing them stays green.

It agrees with the painter on three things only, because all three are inputs rather than answers: the document, the camera, and the rebase origin.

Group flattening is reproduced rather than avoided. A group's leaves belong to the container that encloses the group and sort among that container's own leaves by handle — which is what ContainerIndex does when it folds them in, and what the draw order means. An instance is the recursion boundary.

omitOwners means what it means to DraftPainter — a leaf whose direct owner is in the set is not drawn — and is honoured by this walk's own route (spec 13, D6): at a node in the set its own leaves are passed over while its child nodes are still visited. The painter tests each leaf's owner instead; two routes to one meaning, so a test where they disagree is red.

Layers (spec 12b D6, plan P-5), by this walk's own route. At the root, a leaf or an instance whose effective layer is hidden is not drawn. The effective layer is the style resolver's layer-0 substitution: a root leaf or instance on layer 0 is tested against layer 0, anything else against its own; an ATTRIB is placed through its instance's effective layer. Below the root nothing is filtered, because the painter's definition walk is not (D6: "The painter's definition walk stays unfiltered … Residual, recorded: a definition leaf on a non-zero hidden layer still draws"); the instance's own layer decides whether a symbol draws. An oracle stricter than the painter there would only raise a false red in a state the spec sanctions. The index answers the root question with a filter memo; this walk reads the table each time. A layer the table does not have is drawn, as the filter treats it.

Implementation

void referenceWalk(
  DraftDocument doc,
  DrawSink sink,
  ViewportTransform camera,
  Size viewport,
  StyleResolver resolver, {
  double minTextCapPixels = kMinTextCapPixels,
  Set<Handle> omitOwners = const {},
}) {
  final world = camera.visibleWorld(viewport);
  final origin = rebaseOriginFor(world);
  _ReferenceWalk(doc, sink, camera, resolver, world, origin,
          doc.leavesByOwner(), minTextCapPixels, omitOwners)
      .container(doc.rootHandle, Transform2.identity(),
          StyleContext.documentRoot, 0, ReservedHandles.layerZero);
}