diagram_core/src/tools/dimension.rs#
Source: lib/diagram_core/src/tools/dimension.rs
tools::dimension -- Maßlinien (AS-11): the ends of a dimension shape on points and shapes
Kind Horizontal, Vertical, Aligned (what the dimension shape measures:
its master shows the horizontal or vertical distance of its ends or
its own length)
Anchor where an end goes: a free point, a connection point of a shape
(static glue), a point of a shape's box (Width and Height fractions)
anchor_at(doc, s, frac) the connection point at that point of the box, else the box point
point(doc, &anchor) where it is on the page now
of_shape(doc, s, kind) the shape's own extent: its left and right side (bottom and top)
between(doc, a, b, kind) between two shapes: the sides that face each other (horizontal:
the left shape's right side and the right shape's left side;
vertical: the lower one's top and the upper one's bottom; aligned:
the nearest pair)
attach(tx, eng, dim, end, &anchor) one end there, glued or tied
place(tx, eng, dim, kind, &begin, &end, clear) both ends; the dimension line (the control
row "Line" of the master, if it has one) `clear` beyond the shapes:
above them (horizontal), left of them (vertical)
How an end follows (so it does in Visio too, the cells are Visio's own):
* a connection point: static glue as glue::glue writes it -- BeginX = PAR(PNT(Sheet.N!
Connections.Xk,Sheet.N!Connections.Yk)), BegTrigger = _XFTRIGGER(Sheet.N!EventXFMod) and a
Connect entry;
* any other point of a shape: the same formula on the box, BeginX = PAR(PNT(Sheet.N!Width*fx,
Sheet.N!Height*fy)) with the trigger, without a Connect entry (Visio has no Connect for it; the
formula alone moves the end, as PAR reads the shape's transform);
* a free point: a constant.
The candidates of a shape are its connection points (Type 0 and 2; outward ones are no glue
target), a shape without any offers the middles of its four sides.
enum Kindwhat a dimension measuresHorizontal-- the horizontal distance of its endsVertical-- the vertical distance of its endsAligned-- its length
enum Anchorwhere an end of a dimension goesFree([f64; 2])-- a point of the pagePoint { shape: ShapeRef, row: u32, }-- connection pointrow(IX) of a shape: static glueBox { shape: ShapeRef, at: [f64; 2], }-- a point of a shape's box: fractions of Width and Height in its local coordinates
impl Anchor
fn shape(&self) -> Option<ShapeRef>the shape it is on (None: a free point)fn point(doc: &Document, a: &Anchor) -> [f64; 2]where an anchor is on the page nowfn anchor_at(doc: &Document, s: ShapeRef, frac: [f64; 2]) -> Anchorthe connection point at the box pointfrac(fractions of Width and Height), else the box point itselffn of_shape(doc: &Document, s: ShapeRef, kind: Kind) -> (Anchor, Anchor)a shape's own extent: left and right side (Horizontal, Aligned: along its width), bottom and top (Vertical); the first end left of (below) the secondfn between(doc: &Document, a: ShapeRef, b: ShapeRef, kind: Kind) -> (Anchor, Anchor)between two shapes (see the file header); the first end left of (below) the secondfn attach(tx: &mut Transaction, eng: &mut Engine, dim: ShapeRef, end: End, anchor: &Anchor) -> Result<(), EditError>put an end of dimension shapedim(1-D) onanchor: glued to a connection point, tied to a box point by formula, or freefn place(tx: &mut Transaction, eng: &mut Engine, dim: ShapeRef, kind: Kind, begin: &Anchor, end: &Anchor, clear: f64) -> Result<(), EditError>both ends ofdimon their anchors; the dimension lineclear(drawing units) above the shapes (Horizontal) or left of them (Vertical), when the master has the control row "Line"fn end_formulas(doc: &Document, dim: ShapeRef) -> (Option<alloc::string::String>, Option<alloc::string::String>)the formulas of BeginX and EndX of a 1-D shape (None: a constant), for checks