Skip to main content

jet_cad_2d 0.7.1 copy "jet_cad_2d: ^0.7.1" to clipboard
jet_cad_2d: ^0.7.1 copied to clipboard

A pure-Dart 2D CAD engine and document model: a scene tree, columnar geometry, a spatial index with picking and snapping, undoable commands and a deterministic file format.

jet_cad_2d #

A pure-Dart 2D CAD engine and document model. It has no Flutter dependency, no FFI and no native build, and runs anywhere Dart runs: the VM, the web (JavaScript and Wasm) and every Flutter platform.

What it holds #

  • A document: a scene tree of groups, definitions and instances over columnar entity and geometry stores (points, lines, polylines, circles, arcs, text, attributes and fills), layers, linetypes and text styles, and typed components attached to nodes.
  • Commands with undo: every edit is a command run through the document's dispatcher, undoable and redoable, compound commands included.
  • A spatial index that follows each edit synchronously: rectangle queries, picking with the full path through nested instances, and object snapping. In steady state the frame-path queries allocate nothing per entity; a pick or a snap allocates a few objects per level of instance nesting, whatever the document's size.
  • A deterministic file format: a JSON codec that writes a document back byte for byte. It keeps the fields and components it does not recognise (another application's components, for instance) and writes them back unchanged; a file with a newer schema version is refused with SchemaVersionError.
  • A parametric layer: object types an application registers are regenerated inside the edit that changes them, in the same undo step.

Example #

The snippet uses vector_math for its points, so add both: dart pub add jet_cad_2d vector_math.

import 'package:jet_cad_2d/jet_cad_2d.dart';
import 'package:vector_math/vector_math_64.dart' show Vector2;

void main() {
  final doc = DraftDocument.empty();
  final circle = addDrafted(
      doc, EntityKind.circle, circlePayload(Vector2(300, 250), 50),
      layer: ReservedHandles.layerZero);
  doc.commands.execute(circle);

  final index = SpatialIndex(doc);
  final hit = HitPath();
  if (index.pickInto(Vector2(300, 301), 2, const QueryFilter.picking(), hit)) {
    print(hit.entity == circle.record.handle); // true
  }

  doc.commands.undo(); // the circle is gone, and the index knows it
  print(DraftDocumentCodec.encodeToString(doc));
}

The full walk-through, which also saves and reloads the document, is in example/jet_cad_2d_example.dart.

The API #

package:jet_cad_2d/jet_cad_2d.dart is the API. Nothing under src/ is. package:jet_cad_2d/testing.dart generates benchmark documents for this repository's own suites; it is not API and may change in any release.

While the version is 0.x, a minor release (0.8.0) may break the API, and a patch release (0.7.2) does not.

Where it comes from #

This package is the engine of jet-cad, a parametric floor planner. The Flutter packages that render and edit its documents live in that repository and are not published on pub.dev; an application that embeds the floor planner takes this engine with them, by git, and should not also depend on it from pub.dev.

License #

Apache License 2.0. See LICENSE.

1
likes
0
points
151
downloads

Publisher

unverified uploader

Weekly Downloads

A pure-Dart 2D CAD engine and document model: a scene tree, columnar geometry, a spatial index with picking and snapping, undoable commands and a deterministic file format.

Repository (GitHub)
View/report issues

Topics

#cad #geometry #spatial-index #drawing

License

unknown (license)

Dependencies

meta, vector_math

More

Packages that depend on jet_cad_2d