Commonplace kernel API
    Preparing search index...

    Loading, host hooks and tolerances

    The kernel loads most of itself on demand: solvers, evaluators, the exact Boolean and the validator's later rules each sit in a part of their own. A host with no load-time budget (a script, a server, a test) imports the package's main entry and awaits loadKernel() once. A host that draws a first frame against a budget (a modeler in a browser) imports the lane-free entry instead and loads each capability when a tool first needs it. This page covers both, the hooks a host installs to hear about refusals the kernel makes on its own, and the tolerances a host reads and tunes.

    Entry What importing it does
    @commonplace-technologies/kernel Holds the whole kernel: every part the kernel otherwise loads on demand is imported statically, and the edit lane and the command passes register as it loads. await loadKernel() then loads nothing over the network, so it is safe at the top level of a bundled app.
    @commonplace-technologies/kernel/core The same names, registering nothing and holding no part. A name imported from here costs that name and what it imports.

    Both entries export exactly the same names, and the same objects: a mesh made through one is a mesh to the other. Only what loads with the entry differs.

    // First frame: the mesh and the read side, nothing else.
    import { HalfEdgeMesh, kernelQuery, loadEditLane } from '@commonplace-technologies/kernel/core';

    const mesh = new HalfEdgeMesh();
    // When the browser is first idle, or before the first edit or document read:
    await loadEditLane();

    The package's manifest lists precisely which files run for their effects (sideEffects), so a bundler that honors it keeps only what the names a host imports reach. Bundled by Rollup or Vite, importing HalfEdgeMesh from ./core keeps 0.23 MB up front, against 2.18 MB for the same import from the main entry, which holds the whole kernel (minified, measured by npm run test:kernel-package). esbuild keeps every listed file that the import graph reaches, used or not, so under it ./core is lighter than the main entry, but not by much.

    A part loaded from ./core is a chunk of its own in a bundled app, and it imports back from the chunk that holds the rest of the kernel. So with ./core, call a loader from a function or an event handler, not with a top-level await in the module that imports the kernel: under Rollup or Vite that module's chunk is the one the part imports back from, and an await there waits for itself. The main entry has no such parts.

    loadKernel() loads every part. Loading twice is harmless; a load that fails rejects, and the next call retries it. From then on nothing waits.

    For a host that loads as it goes, each capability has its own loader, which loads once however many callers it has, resolves to nothing, and retries on the next call after a failure. Each …Loaded() reader says whether that load has landed.

    Loader Reader What it loads Before it loads
    loadEditLane() editLaneLoaded() The edit lane and command passes: validation, repair, merge, every modeling operation an edit or a document read runs. A verb refuses with threw; a HalfEdgeMesh method that needs the lane throws EditLaneNotLoaded. Await it before the first edit or document read. Not needed after importing the main entry.
    loadRadialRing() The radial ring's checker and copier (validator rules 29 and 30, where three or more faces meet an edge). Loaded with the edit lane. A reading of the rings beside it is not available yet.
    loadCurveEvaluator() curveEvaluatorLoaded() Exact evaluation of developed arcs, trimmed rails and the curves a patch carries. A verb that must evaluate such a curve refuses with its own loading code (revolve: curve-evaluator-loading; refusalCodes(verb) lists each verb's); a read returns null; display draws the curve on its fallback.
    loadImprint() imprintLoaded() The imprint (the step that cuts every face a committed edit crosses) and its curve and face intersection solvers; it loads the curve evaluator too. A verb asked to imprint awaits it.
    loadSweepAlongPath() sweepAlongPathLoaded() sweep of a profile along a path of edges. The verb awaits it.
    loadCurvedOffset() curvedOffsetLoaded() What offset needs to push or drill a curved face: the trimmed-rail sweep, the drill and the exact Boolean they compose with. offset awaits it. Rejects in a build that holds it out (curvedOffsetHeld()), and offset then refuses such a push with a reason.
    loadMassProperties() kernelQuery(mesh).massProperties(). The read returns null and starts the load.
    loadUnfolding() kernelQuery(mesh).develop() and .unfold(). The reads return null and start the load.
    loadReplayStep() In-place undo and redo, started by the first history. Undo and redo restore a step's state whole: the same result, slower on a large mesh.
    loadGeometryClass() geometryClassLoaded() The surface analysis: surface and edge type, and the curvature map's samples. The tessellation's surfaceClass, edgeClass and curvatureSamples read null.
    loadSurfaceArea() surfaceAreaLoaded() The true area of a face, integrated on its surface. faceSurfaceAreaOrNull(mesh, face) reads null and starts the load.

    The kernel refuses some things without being asked, and says so on a channel a host may replace. A host installs a handler once, at start-up; null restores the default. A handler that throws is caught and logged: it never breaks the edit it reports on.

    Install with Hears about Default
    setMeshPostconditionRefusalHandler(fn) A committed edit refused because it would have left the model invalid (MeshPostconditionRefusal: the command, the new violations); the model was rolled back. console.error
    setMeshPostconditionSkipHandler(fn) The postcondition check switched off for a large model (MeshPostconditionSkip: why, the vertex count, the budget). console.warn

    setMeshPostconditionGate(enabled) turns the postcondition check itself on or off.

    toleranceContext holds the user-facing tolerances: the weld (linear), the angle and the pick apertures. A host scales linear to its model with contextLinearTolerance(scale, fallback, rel), where scale is the model's diagonal (scaleFor(points)).

    KERNEL_TOLERANCES holds the kernel's own defaults, frozen, for a host that derives bands of its own (snapping, display, typed input) that must agree with the kernel's: the weld and planarity ratios, the linear and parameter resolutions, the zero-vector length, the face-planarity band, the tangent-parallelism angle, the curve-split inset and the defaults of toleranceContext.

    Two multipliers can be tuned at run time:

    import { KERNEL_TOLERANCES, configureTolerances, toleranceSettings } from '@commonplace-technologies/kernel/core';

    configureTolerances({ linearRel: 2e-6 }); // { linearRel: 2e-6, planarityRel: 0.01 }
    toleranceSettings(); // the same
    configureTolerances(KERNEL_TOLERANCES); // back to the defaults

    A value that is not a finite positive number is ignored. A change applies to the next edit; it does not re-weld or re-check the model. Every other tolerance is the kernel's and is not configurable.