PlotDirector/Docs/Maps/SharedBoundaries.md

7.4 KiB

Shared boundaries and snapping

Author workflow

Select a geographical area, choose Edit boundary / Edit shape, and drag control points. Snap to vertex and Snap to edge default on, with a 10-screen-pixel tolerance and a visible snap ring. Hold Alt during a point drag to suppress snapping; Alt + click on ordinary map content continues cycling overlapping pieces. Creating a piece or converting a settlement uses the same editor. Snapping alone changes only the edited point; it never creates a relationship or inserts a point into the neighbour.

Snap two endpoints to a neighbouring boundary, then choose Join boundaries in the boundary editor, Arrange group or piece context menu. The dialog identifies endpoints and the section on each area. Defaults use the shorter section; equally short alternatives require an explicit Forward/Backward choice. It retains the neighbour's existing curve by default, with an option to retain the selected area's geometry instead. Edge endpoints are inserted into the neighbour only at this deliberate join, preserving its visible curves. Different intermediate-point counts are supported. Existing shared sections cannot be overwritten; choose another section or unjoin first.

Shared points use distinct handles. Shared edges have a generous invisible hit target, can be selected through the boundary dropdown, and list their participating areas. Right-click a point to mark a join endpoint. A shared edge is drawn once, using the retained edge's border style, after the highest participating fill in the normal drawing order. Labels, anchors, selection overlays and manual Arrange ordering retain their existing roles.

Move, insert or remove shared control points from either area. Insertion subdivides the exact curve; deleting a degree-two intermediate vertex merges its curves. Junction endpoints cannot be deleted while unrelated segments meet there. Shared smoothing has one setting per shared edge; switching styles leaves its underlying curve controls intact. Unshared edges continue using their area treatment. Locks prevent shared edits affecting a locked participant.

Unjoin boundary detaches the selected area from that edge. Unjoin all boundaries makes the selected area independent. Visible curves and border styles are baked into private edge geometry, including stroke direction so dashed borders remain aligned. Other participants retain their relationships. Undo/Redo restores the complete geometry and topology together.

Representation and integration

No SQL migration is required. Optional additions to existing feature GeometryJson are:

  • Area geometry (root for Area, nested boundary for settlement Marker): vertexRefs, edgeRefs, edgeShapes, edgeStyles, each aligned with the existing control-point ring.
  • Root topologyStore: {version:1, vertices, edges}: definitions owned by existing geographical feature records. Definitions can be distributed across owners, but each vertex/edge ID has exactly one definition within a map.
  • A vertex definition contains one authoritative world position. A shared edge references two authoritative vertices and one immutable normalized cubic shape, plus current/base smoothing and retained style. Both rings resolve that definition, in either direction, rather than independently copying coordinates. Existing points entries at referenced vertices are fallback caches and are not rendering/editing authority.
  • Three-way and higher junctions reuse one vertex ID across incident edges. Joining a third area preserves existing shared sections. No FeatureID, LocationID, Location parent or road anchor is replaced or introduced.

Private edgeShapes retain subdivided/unjoined curves relative to their endpoints. This preserves the visible shape while returning them to independent editing. Ordinary maps without these additions keep their original renderer and storage. Filled areas with topology use the same SVG scene and editor, decomposing their strokes so a shared border is never painted twice. Containment and bounds resolve the same rendered geometry.

Server validation checks version, unique definitions, same-map references, consistent edge orientation, at least two participants per shared edge, no orphan definitions, finite bounded curves and permitted styles. The existing 64-control-point and 64 KB-per-feature geometry limits apply. Client operations validate affected polygons, reject collapsed/self-intersecting/ambiguous sections and commit only a complete valid result. Failed edits leave the previous state intact.

Movement, deletion and compatibility

Independent area movement is unchanged. Whole-area movement, rotation, resizing and Fit boundary are restricted while shared edges exist: explicitly unjoin first. Independent settlement anchor movement remains available because it leaves the boundary fixed. Ordinary vertex editing changes the authoritative geometry and updates all participating outlines without moving buildings or settlement anchors.

Geographical positioning and relationship arrangement translate shared vertices once when all incident areas receive the same displacement. Incompatible displacements block the complete proposal and identify the areas to unjoin. Independent hierarchy-aware positioning, path transformation and its atomic Apply/Undo semantics remain intact.

Duplicating an area bakes an independent copy of its current visible geometry, without references to the originals. Whole-map copies carry their complete graph scoped to the new map. Deleting an area removes only its participation, bakes singleton edges for survivors, transfers any surviving definitions it owned, and removes unreferenced definitions. Backup/restore and import/export retain the opaque geometry JSON and validate the complete graph.

Verification

  • Normal solution build and executable regression harness, including MapTopologyTests.
  • node PlotLine.Tests/Browser/maps-topology-engine.cjs: vertex/curved-edge snapping and zoom tolerance, explicit authority, differing point counts, shared editing/insertion/removal/smoothing, junctions, exact unjoin, ownership transfer/deletion, duplication, invalid geometry, compatible/conflicting geographical movement, and spatial-index performance.
  • node PlotLine.Tests/Browser/maps-topology.cjs: normal/PWA pointer interaction, join dialog, single border, shared control editing, Undo/Redo, movement restriction, Save/reopen, unjoin, three-way junction, duplication and deletion.
  • Existing settlement, drawing-order, hierarchy-geography and Maps workflows are regression gates.
  • --map-topology-database /tmp/pd-dev-browser-<fixture>/identity.json: dedicated Development account/project, complete shared graph with a three-way junction, real Save/reload and full project backup/export/import/restore, unchanged canonical hierarchy and road references.
  • node PlotLine.Tests/Browser/maps-topology-development.cjs /tmp/pd-dev-browser-<fixture>/identity.json: authenticated Development controls and real Save/reload, followed by the normal disposable-account cleanup.

Tests use isolated data and never open the author's actual Birmingham map. The model supports a single simple ring per area; holes, multipart polygons, snapping a whole edge in one gesture and dragging connected areas as a manual group are outside this change. Edit individual vertices, use explicit shared sections, and unjoin before independent whole-area movement. Existing shape/size limits may require simplifying a very detailed section before joining.