diagram_core/src/ops/draw.rs#
Source: lib/diagram_core/src/ops/draw.rs
ops::draw -- the freeform and arc tools (RS-16, KB-09): a stroke smoothed into a NURBS curve,
a quarter of an ellipse between two points. Both are 1-D shapes like a line (glue::new_line):
their ends glue to connection points (CN-12) and their geometry follows Width, so they keep
their form when an end moves.
simplify(pts, tol) -> corners Ramer-Douglas-Peucker: the points of a stroke that keep
every other point within tol of the polyline
Spline::of(points) -> Spline a clamped B-spline (degree 3, fewer for 2 or 3 points)
with the points as its control polygon and evenly spaced
knots 0, 1, 2 ...; the curve starts and ends at the
first and last point and runs smoothly along the rest
quarter_arc(a, b, horizontal) -> Arc the quarter ellipse from a to b with page-parallel
axes: horizontal = it leaves a horizontally (and meets b
vertically), else the other way round
new_freeform(tx, eng, owner, stroke, tol, close, begin, end) -> ShapeRef
new_arc(tx, eng, owner, begin, end, horizontal) -> ShapeRef
How Visio keeps them (MS-VSDX, Geometry section rows; geometry.rs reads them the same way):
* The freeform: MoveTo at the begin, then one NURBSTo whose X, Y is the end, A the knot of
the last control point, B its weight, C the knot of the first one (the current point), D
its weight, and E = NURBS(knotLast, degree, xType, yType, x1, y1, knot1, weight1, ...) the
control points between (type 0: a fraction of Width / Height, 1: local inches). Visio's
own freeform tool writes NURBSTo too; its smoothing is its own (not documented), so the
curve here is a choice: the corners of the stroke as control points. A 1-D shape has
Height 0 (its chord is the local x axis, as a line's), so the y values are local inches
written as Width*k inside the NURBS formula: the whole curve scales with Width when an
end moves, as a line's rows do (Annahme: Visio's 1-D freeforms keep y as constants of
their own; the formula keeps the form instead, and Visio evaluates NURBS() with
expressions like any function).
* A stroke that ends where it began (within `close`) is a closed 2-D shape (Visio's freeform
tool closes a shape there and fills it): its box around the control points, the rows in
fractions of Width and Height (xType = yType = 0), filled.
* The arc: MoveTo at the begin, an EllipticalArcTo to the end through the control point A, B
(the middle of the quarter: 45 degrees of the ellipse's parameter), C the angle of the
ellipse's major axis in the shape's local coordinates (the page's x axis, so -Angle at
the start), D the ratio of that axis to the other. A and B are Width*k as well. Visio's
arc tool draws a quarter ellipse whose bow follows the direction the drag starts in
(Annahme from its help: "drag in the direction you want the arc to bow"; the start's
axis decides here).
The 1-D cells are those of new_line: PinX/Y in the middle, Width the chord, Angle its
direction, LocPinX Width*0.5, Begin and End constants until glued.
fn simplify(pts: &[[f64; 2]], tol: f64) -> Vec<[f64; 2]>the corners of a stroke: every point ofptslies withintolof the polyline through the result, which starts and ends with the stroke's first and last point (repeated points go)struct Splinea clamped, uniform B-spline through its first and last control pointdegree: usizepoints: Vec<[f64; 2]>knots: Vec<f64>-- the full knot vector: points + degree + 1 knots
impl Spline
fn of(points: &[[f64; 2]]) -> Option<Spline>the spline with these control points: degree 3 (2 for three points, 1 for two), knots 0 .. 0, 1, 2 .. n - degree + 1 .. (None: fewer than two points)fn at(&self, t: f64) -> [f64; 2]the point at parameter t in 0 ..= 1 of the knot range (de Boor)struct Arca quarter of an ellipse with axes parallel to the page'scentre: [f64; 2]rx: f64-- the half axes along x and yry: f64mid: [f64; 2]-- the point halfway (45 degrees of the parameter)
fn quarter_arc(a: [f64; 2], b: [f64; 2], horizontal: bool) -> Arcthe quarter ellipse fromatob: leavingahorizontally (horizontal) or verticallyfn new_freeform(tx: &mut Transaction, eng: &mut Engine, owner: Owner, stroke: &[[f64; 2]], tol: f64, close: f64, begin: Target, end: Target) -> Result<ShapeRef, EditError>a freeform shape from a stroke (page points in drawing units): its corners withintol(simplify) smoothed into a NURBS curve; a stroke whose end lies withincloseof its start (and that has a few corners) is a closed, filled 2-D shape, else a 1-D shape whose ends glue like a line's (Target::Shape is refused, as for lines) -> its handle. A stroke without length is refused (Invalid)fn new_arc(tx: &mut Transaction, eng: &mut Engine, owner: Owner, begin: ([f64; 2], Target), end: ([f64; 2], Target), horizontal: bool) -> Result<ShapeRef, EditError>a quarter-ellipse arc frombegintoend(page points with their glue targets; lines glue statically, Target::Shape is refused), leaving the begin horizontally or vertically (quarter_arc) -> its handle. Begin and end in one place are refused (Invalid)