JFLib

diagram_core/src/ops/points.rs#

Source: lib/diagram_core/src/ops/points.rs

ops::points -- control points (SP-04) and vertices (SP-05) of a shape

  controls(doc, shape) -> Vec<Control>         the visible control points on the page
  set_control(tx, eng, shape, row, at)         a control point dragged to a page point
  vertices(doc, shape) -> Vec<Vertex>          the points of the Geometry rows on the page
  set_vertex / insert_vertex / delete_vertex   move one, add one after a row, take one out
  move_vertices / delete_vertices              (JD21, SP-05) several of one shape together
                                               (Visio: chosen with Shift)

A control point is a row of the Controls section: X and Y in local coordinates, XDyn/YDyn
the point its rubber band starts from, XCon/YCon how it behaves ([MS-VSDX] Controls; the
Visio constants visCtlProportional 0, visCtlLocked 1, visCtlOffsetMin 2, visCtlOffsetMid 3,
visCtlOffsetMax 4, the same plus 5 for a hidden point), CanGlue, Prompt (the tip).  Dragging
writes X and Y the way Visio does (seen in the local files: X "Width*0.6734" for 0,
"Width-0.217DL" for 4, a BOUND(...) keeps its form and gets the new value as its first
argument): proportional "Width*k" / "Height*k" for 0, the value for 2, "Width*0.5+dDL" for 3,
"Width-dDL" for 4; a locked direction stays.  A glued control point (a Connect entry with
FromCell Controls.<row>) is let go.

Vertices are the end points of the Geometry rows that have one (MoveTo, LineTo, ArcTo,
EllipticalArcTo, NURBSTo, PolylineTo, the spline rows, the relative rows; not Ellipse and
InfiniteLine); the last row of a closed sub-path, which repeats its start, is not a vertex of
its own and moves with the start.  Relative rows keep fractions of Width and Height,
absolute rows keep the proportional form of their formulas (Visio's "Width*0.5").  Adding and
taking out a vertex inserts or removes a row in the middle of the section
(Transaction::insert_row / remove_row: the rows after it are renumbered, formulas follow, an
instance's inherited section becomes its own).  LockVtxEdit refuses (Invalid).  (JD21, SP-05)
After each of them the box follows the geometry (shapeops::fit_frame: Width, Height, Pin and
the rows into the box of the geometry, the shape stays on the page; not with LockCalcWH), as
Visio does after a vertex edit.
  • struct Control a control point of a shape

    • row: RowKey -- its row of the Controls section (set_control takes it back)
    • name: String -- the row name (Row_1, TextPosition ...)
    • at: [f64; 2] -- where it is on the page
    • anchor: [f64; 2] -- where its rubber band starts on the page (XDyn, YDyn)
    • tip: String -- the tip (Prompt)
    • can_glue: bool -- whether it can glue to other shapes (CanGlue)
    • x_locked: bool -- whether it cannot move sideways (XCon 1 or 6)
    • y_locked: bool -- whether it cannot move up and down (YCon 1 or 6)
  • fn controls(doc: &Document, shape: ShapeRef) -> Vec<Control> the visible control points of a shape on the page (hidden ones, XCon or YCon 5 to 9, left out)

  • fn set_control(tx: &mut Transaction, eng: &mut Engine, shape: ShapeRef, row: RowKey, at: [f64; 2]) -> Result<(), EditError> drag a control point (its row from controls()) to the page point at: X and Y as Visio writes them for the point's behaviour (see the module comment), the point let go when it was glued

  • struct Vertex a vertex of a shape: Geometry section (0-based index, Geometry1 is 0), row (IX) and where it is on the page

    • section: u32 -- the Geometry section's index
    • row: u32 -- the row's IX
    • at: [f64; 2] -- where it is on the page
  • fn vertices(doc: &Document, shape: ShapeRef) -> Vec<Vertex> the vertices of a shape on the page, section by section (hidden sections left out)

  • fn set_vertex(tx: &mut Transaction, eng: &mut Engine, shape: ShapeRef, section: u32, row: u32, at: [f64; 2]) -> Result<(), EditError> move a vertex to the page point at; the start of a closed sub-path takes its closing row along

  • fn insert_vertex(tx: &mut Transaction, eng: &mut Engine, shape: ShapeRef, section: u32, after: u32, at: [f64; 2]) -> Result<u32, EditError> add a vertex at the page point at after row after (on the segment to the next row): a LineTo (RelLineTo among relative rows) at IX after + 1 -> its IX

  • fn delete_vertex(tx: &mut Transaction, eng: &mut Engine, shape: ShapeRef, section: u32, row: u32) -> Result<(), EditError> take a vertex out; at the start of a sub-path the next vertex becomes the start (and the closing row of a closed one goes there); a sub-path keeps at least two vertices (Invalid)

  • fn move_vertices(tx: &mut Transaction, eng: &mut Engine, shape: ShapeRef, list: &[(u32, u32)], d: [f64; 2]) -> Result<(), EditError> (JD21, SP-05) move several vertices of a shape (section, row) together by d (page): each as set_vertex moves it (the start of a closed sub-path takes its closing row along), the box follows once at the end; vertices that are not there are left out

  • fn delete_vertices(tx: &mut Transaction, eng: &mut Engine, shape: ShapeRef, list: &[(u32, u32)]) -> Result<(), EditError> (JD21, SP-05) take several vertices of a shape out, the last rows first so the others keep their numbers; a vertex its sub-path cannot spare (two left) stays

Source: docs/API.md in the JFLib repository.