56.7 Replacing and matching shapes
Replace objects or match the leaves of groups.
procedure
(transform-shape source destination [ #:mode mode #:correspondence correspondence #:allow-reverse? allow-reverse? #:sample-count sample-count]) → transform-shape-request? source : (or/c visual? symbol?) destination : (and/c visual? affine-visual? opacity-visual?) mode : (or/c 'auto 'morph 'cross-fade) = 'auto correspondence : (or/c 'auto 'perimeter 'path) = 'auto allow-reverse? : boolean? = #t sample-count : (and/c exact-integer? (>=/c 8)) = 64
The default 'auto first tries a geometric transition when each endpoint is one built-in path-visual?, circle-visual?, or rectangle-visual?. Circle/rectangle pairs use a canonical eight-segment perimeter: both start at their right midpoint and correspond at the cardinal and diagonal positions. This produces an evenly rounded square-to-circle interior. Pass 'perimeter to require that primitive correspondence, or 'path to use only the general stored-path policy. Other geometric pairs use automatic topology-class pairing, including closed-loop phase/direction and open-path direction; when counts differ, they try deterministic birth/death preparation. The source and destination styles are alpha layers over the same intermediate outline, so a fill/stroke change fades naturally while the geometry moves. Their transforms are interpolated too.
If either endpoint is a group, image, text, formula, SVG tree, custom Visual, or atomic geometry that cannot be prepared safely, 'auto keeps the exact endpoint trees and cross-fades them at their own positions. This is a deliberate graceful fallback: it does not flatten a group or manufacture a semantic mapping between its children. 'morph requires the geometric case and raises an exception otherwise. 'cross-fade always selects the fallback and ignores the correspondence controls.
At exact start, the source is unchanged. At interior samples it is hidden and a temporary frontmost layer is drawn. At structural completion, regardless of the easing result, the source is removed and the exact caller-supplied destination Visual is installed. Temporary path conversions and normalized outlines are therefore never retained in later clips.
The operation reserves all ordinary Visual components and presence for both source and destination identities. It cannot be combined in one play clip with another animation of either endpoint.
procedure
(transform-shape-request? value) → boolean?
value : any/c
procedure
(transform-matching-visuals source destination [ #:matches matches #:mode mode #:mismatch-mode mismatch-mode #:allow-reverse? allow-reverse? #:sample-count sample-count]) → transform-matching-visuals-request? source : visual? destination : (and/c visual? affine-visual? opacity-visual?) matches : (listof visual-match?) = '() mode : (or/c 'auto 'morph 'cross-fade) = 'auto mismatch-mode : (or/c 'fade 'fade-transform) = 'fade allow-reverse? : boolean? = #t sample-count : (and/c exact-integer? (>=/c 8)) = 64
For a matched path, circle, or rectangle that can use the existing topology-aware outline preparation, 'auto shares an intermediate geometric morph. Other matched affine/opacity leaves move through an interpolated affine transform while their source/destination content cross-fades. Unmatched leaves fade in place; 'fade-transform pairs the remaining leaves by nearest position to give them the same moving cross-fade. Pass 'morph to require every matched pair to have geometric correspondence, or 'cross-fade to disable all geometric morphs.
General Visual matching is intentionally conservative. It does not infer semantic matches for arbitrary SVG/text/custom leaves after renaming, preserve one leaf through a split or merge, resolve occlusion/collisions, or replace the formula APIs’ TeX/glyph correspondence. At exact start the source is unchanged; interior samples use a temporary frontmost overlay; at the clip boundary the exact destination root is installed.
procedure
(transform-matching-visuals-request? value) → boolean?
value : any/c