JFLib

diagram_core/src/dock.rs#

Source: lib/diagram_core/src/dock.rs

dock -- 2-D shapes that snap onto connection points (JD13; SP-12, CN-04 "Andocken und
Einrasten": equipment into racks, later doors into walls, valves into pipes)

  snap(doc, owner, shapes, reach) -> Option<Snap>   the move that puts an outward point of
                                   one of `shapes` on an inward point of another shape
  dock(tx, eng, owner, shapes, reach) -> Option<Snap>   ... and do it (ops::move_shapes of the
                                   shapes and what they carry; connectors follow in the app)
  reach(doc, owner, paper)         a distance on paper in the page's drawing units

Visio's point-to-point glue of 2-D shapes: a connection point of Type 1 ("outward") or 2
("both", JD21) on the shape that moves meets one of Type 0 or 2 ("inward", "both") on another
shape.  The nearest
pair within `reach` (page units) wins.  A container that would take the shape (its
categories, structure::accepts) and holds the middle of the shape's box is reached from
anywhere inside it: a server dropped anywhere over a rack goes onto the nearest unit of its
rail.  The shapes themselves, what they carry (members, callouts) and 1-D shapes are no
targets; only top-level shapes of the owner dock and are docked on.

Nothing here records glue: membership in the container (structure::settle after the move)
keeps a device with its rack, in JFDiagrammer as in Visio.
  • struct Snap a move that docks a shape

    • d: [f64; 2] -- the move (page units)
    • shape: ShapeRef -- the shape whose outward point docks, and the IX of that point's row
    • point: u32
    • target: ShapeRef -- the shape it docks on, and the IX of the inward point's row
    • target_point: u32
  • fn snap(doc: &Document, owner: Owner, shapes: &[ShapeRef], reach: f64) -> Option<Snap> the move that docks one of shapes (2-D shapes with an outward point) on the nearest inward point of another top-level shape of owner within reach, or anywhere inside a container that takes it; None: nothing to dock on

  • fn reach(doc: &Document, owner: Owner, paper: f64) -> f64 paper inches on the paper of owner's page in its drawing units (the page's scale; a master or a page without scale: 1:1) -- the reach of a gesture that ends on the page

  • fn dock(tx: &mut Transaction, eng: &mut Engine, owner: Owner, shapes: &[ShapeRef], reach: f64) -> Result<Option<Snap>, EditError> dock shapes (see snap) and move them with what they carry; None: nothing moved

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