diagram_core/src/geometry.rs#
Source: lib/diagram_core/src/geometry.rs
geometry -- the Geometry sections of a shape as paths, and the transforms of shapes (JD4)
Xform an affine map (x, y) -> (a x + c y + e, b x + d y + f)
Path { subs } / Sub { start, segs, closed } / Seg::Line | Seg::Cubic
paths of straight lines and cubic Bézier curves: every row
type ends up as one of the two (arcs and ellipses as cubic
pieces of at most 90 degrees, NURBS and splines exactly as
Bézier pieces where they are polynomial, else sampled)
doc.geometry_paths(sheet, w, h) the Geometry sections of a sheet with their flags (NoFill,
NoLine, NoShow, NoSnap) and paths in local coordinates
doc.geometry_tagged(sheet, w, h) (JD21) the same, and per piece the row (IX) it comes from
Conic / row_conic (JD21) the ellipse an ArcTo, EllipticalArcTo, Ellipse or
RelEllipticalArcTo row draws: c + u cos t + v sin t
doc.local_xform(sheet) local -> parent: Pin, LocPin, Angle, FlipX, FlipY
doc.page_xform(shape) local -> page: the chain of groups up to the page
round_corners(path, r) the Rounding cell: corners between straight lines rounded
nurbs_segments / parse_args NURBS(...) and POLYLINE(...) values as the file keeps them
Everything comes from the cached values (V) through inheritance (doc.resolve): nothing is
recalculated (PLAN.md, "Fallen"). Local coordinates: inches, the origin at the bottom left
corner of the shape's box, y up. The row types follow [MS-VSDX] (Geometry section):
MoveTo, LineTo, ArcTo (bow A: positive turns counter-clockwise, the arc's middle lies right
of the chord), EllipticalArcTo (through the control point A, B; C the angle of the major
axis, D major over minor), Ellipse (centre X, Y; ends of the two axes A, B and C, D),
NURBSTo (E = NURBS(knotLast, degree, xType, yType, x, y, knot, weight, ...): the current
point is the first control point with knot C and weight D, X, Y the last with knot A and
weight B; type 0 means a fraction of Width / Height), PolylineTo (A = POLYLINE(xType, yType,
x, y, ...)), SplineStart / SplineKnot, InfiniteLine (drawn 1000 inches each way), and the
relative rows RelMoveTo, RelLineTo, RelCubBezTo, RelQuadBezTo, RelEllipticalArcTo in
fractions of Width and Height. Visio fills only closed sub-paths (end = start).
A shape's transform to its parent (MS-VSDX, "Shape Transform"): move the local pin to the
origin, flip (FlipX mirrors x, FlipY mirrors y), turn by Angle, move to the pin -- the pin
lies in the parent's coordinates (the page, or the group's local ones).
struct Xforman affine map: (x, y) -> (a x + c y + e, b x + d y + f)a: f64b: f64c: f64d: f64e: f64f: f64
impl Xform
const IDENTITY: Xform = Xform { a: 1.0, b: 0.0, c: 0.0, d: 1.0, e: 0.0, f: 0.0 }const fn translate(x: f64, y: f64) -> Xformconst fn scale(sx: f64, sy: f64) -> Xformfn rotate(angle: f64) -> Xforma turn byangleradians, counter-clockwise (y up)fn then(&self, next: &Xform) -> Xformfirstself, thennextfn apply(&self, p: [f64; 2]) -> [f64; 2]fn apply_vec(&self, v: [f64; 2]) -> [f64; 2]a direction (without the translation)fn det(&self) -> f64fn inverse(&self) -> Option<Xform>the inverse (None: singular)fn angle(&self) -> f64the angle the x axis is turned to (radians, counter-clockwise)fn scale_factor(&self) -> f64how much lengths grow (the square root of |det|)enum Sega piece of a sub-path: to a point, or a cubic Bézier curve (two control points, the end)Line([f64; 2])Cubic([f64; 2], [f64; 2], [f64; 2])
impl Seg
fn end(&self) -> [f64; 2]struct Suba sub-path: a start and pieces end to end; closed when it ends where it startsstart: [f64; 2]segs: Vec<Seg>closed: bool
impl Sub
fn end(&self) -> [f64; 2]fn map(&self, m: &Xform) -> Subthe same under a transformfn reversed(&self) -> Subthe same run backwardsfn hull(&self) -> [f64; 4]the box of its points and control points (x0, y0, x1, y1)fn flatten(&self, per_curve: usize, out: &mut Vec<[f64; 2]>)the points along it, curves cut intoper_curvestraight piecesstruct Patha path: sub-paths drawn together (filled even-odd)subs: Vec<Sub>
impl Path
fn map(&self, m: &Xform) -> Pathfn is_empty(&self) -> boolfn hull(&self) -> Option<[f64; 4]>the box of all points and control points (None: no points)struct GeoSectionone Geometry section of a shape: its flags and its sub-paths in local coordinatesindex: u32-- IX of the section (Geometry1 is 0)no_fill: boolno_line: boolno_show: boolno_snap: boolpath: Path
/// how far an infinite line is drawn each way (inches)
INFINITE: f64 = 1000.0
impl Document
fn geometry_paths(&self, sheet: SheetRef, w: f64, h: f64) -> Vec<GeoSection>the Geometry sectionssheetreally has (inherited ones included, deleted ones left out) with their rows as paths in local coordinates;wandhare the shape's Width and Height (the relative rows and the relative points of NURBS and POLYLINE need them)fn geometry_tagged(&self, sheet: SheetRef, w: f64, h: f64) -> Vec<(GeoSection, Vec<Vec<u32>>)>(JD21) geometry_paths and, per sub-path, the IX of the row each piece comes from (a row that draws several pieces -- an arc, a NURBS curve, a polyline -- gives each of them its IX)fn local_xform(&self, sheet: SheetRef) -> Xformthe transform of a shape's local coordinates to its parent's (the page, or the local coordinates of its group): T(Pin) R(Angle) Flip T(-LocPin)fn page_xform(&self, shape: ShapeRef) -> Xformthe transform of a shape's local coordinates to its page's (or master's): its own, then those of the groups around itfn arc_cubics(c: [f64; 2], r: f64, start: f64, sweep: f64, out: &mut Vec<Seg>)a circular arc (centre, radius, start angle, sweep in radians, positive counter-clockwise) as cubic pieces of at most 90 degreesstruct ConicAn ellipse and an arc of it: the points c + u cos t + v sin t for t fromt0tot0 + sweep(radians, positive counter-clockwise from u towards v; u and v are conjugate half axes, the half axes themselves for an upright ellipse). An affine map keeps the form: map() maps c, u and v and the parameters stay, so an arc of a turned, flipped or stretched shape is a Conic on the page too.c: [f64; 2]u: [f64; 2]v: [f64; 2]t0: f64sweep: f64
impl Conic
fn at(&self, t: f64) -> [f64; 2]the point at parameter tfn is_full(&self) -> boolthe whole ellipse (a sweep of a full turn)fn map(&self, m: &Xform) -> Conicthe same under an affine mapfn param(&self, p: [f64; 2]) -> Option<f64>the parameter of the point of the ellipse thatpprojects to from the centre (in the space where the ellipse is the unit circle); None for a degenerate ellipsefn axes(&self) -> (f64, f64, f64)the principal axes: the angle of the major axis (radians), the major and the minor half length (the singular value decomposition of the matrix [u v])fn bounds(&self) -> [f64; 4]the box of the arc (x0, y0, x1, y1): its ends and the extremes it passes
impl Document
fn row_conic(&self, sheet: SheetRef, sec: SecKey, key: crate::sheet::RowKey, from: [f64; 2], w: f64, h: f64) -> Option<Conic>(JD21) the ellipse arc a Geometry row draws, in local coordinates, the way section_path draws it: ArcTo, EllipticalArcTo and RelEllipticalArcTo fromfrom(the current point) to their X, Y, Ellipse as a whole;w,hthe shape's Width and Height. None for other rows and for arcs that are drawn as a line (a bow of 0, three points on a line)fn parse_args(text: &str, name: &str) -> Option<Vec<f64>>the numbers of a NURBS(...) or POLYLINE(...) value (None: not that function, or a part that is no number)struct Nurbsa B-spline (rational where the weights differ) on a full knot vectordegree: usizepoints: Vec<[f64; 2]>weights: Vec<f64>knots: Vec<f64>
impl Nurbs
fn valid(&self) -> booldegree 1 to 9, a positive weight per point, n + degree + 1 knots that do not fallfn segments(&self, out: &mut Vec<Seg>)the curve as pieces: exact cubic Béziers for a clamped polynomial spline of degree 1 to 3 (knots inserted until every piece is a Bézier), else straight pieces sampled on every knot span; the first piece starts at the curve's startfn at(&self, t: f64) -> [f64; 2]the point at parameter t (de Boor, in homogeneous coordinates)fn round_corners(path: &Path, r: f64) -> Paththe corners between two straight pieces rounded with radius r (the Rounding cell; at most half of each piece is taken), in every sub-pathfn cubic_at(p0: [f64; 2], p1: [f64; 2], p2: [f64; 2], p3: [f64; 2], t: f64) -> [f64; 2]the point of a cubic Bézier curve at t