Skip to content
cadkithome

Geometry with cadkit-geom

cadkit-geom is independent f64 geometry in a Cartesian plane whose units you choose. It depends on no other cadkit crate, so you can use it without any file format. Lengths are in your units, areas in squared units and angles in radians, positive counterclockwise from +x. Every operation takes an explicit GeometryTolerance and either returns a result or a typed GeometryError with a stable reason code; nothing is repaired silently. It is a Rust crate only: the Python, JavaScript and C packages do not expose it.

Cargo.toml
[dependencies]
cadkit-geom = "0.5.3"
src/main.rs
use cadkit_geom::{GeometryTolerance, LineSegment, Point2, Polygon, PolygonBooleanOptions};
fn main() -> Result<(), cadkit_geom::GeometryError> {
let t = GeometryTolerance::default(); // explicit linear, angular and area tolerances
// Offset a wall axis by half the wall thickness; a positive distance offsets to the left.
let axis = LineSegment { start: Point2::new(0.0, 0.0), end: Point2::new(4.0, 0.0) };
let face = axis.offset(0.1, &t)?;
println!("offset: {:?} -> {:?}", face.start, face.end);
// Rings close implicitly: do not repeat the first point.
let rect = |x0: f64, y0: f64, x1: f64, y1: f64| {
vec![Point2::new(x0, y0), Point2::new(x1, y0), Point2::new(x1, y1), Point2::new(x0, y1)]
};
let room = Polygon { exterior: rect(0.0, 0.0, 5.0, 4.0), holes: vec![rect(2.0, 1.5, 2.4, 1.9)] };
println!("room area: {:.2}", room.area(&t)?); // 20 - 0.16 square units
println!("{:?}", room.locate(Point2::new(1.0, 1.0), &t)?);
// Regularized union with explicit coordinate and area error budgets.
let annex = Polygon { exterior: rect(4.0, 1.0, 8.0, 3.0), holes: vec![] };
let union = room.union(&annex, PolygonBooleanOptions::default(), &t)?;
println!("union: {} polygon(s), area {:.2}", union.geometry.polygons.len(), union.area);
Ok(())
}

Running it prints the offset segment from (0, 0.1) to (4, 0.1), a room area of 19.84 (20 minus the 0.16 hole), Inside for the point (1, 1), and one union polygon of area 25.84.

  • Rings close implicitly. A Polygon ring lists each corner once; do not repeat the first point. (Polygon entities in the document model are different: their rings repeat it.)
  • Tolerances are separate budgets: linear (default 1e-8 units), angular (1e-10 rad) and area (1e-12 squared units, the smallest valid area). Defaults are numerical starting values, not physical accuracy guarantees.
  • Booleans (union, intersection, difference, or polygon_boolean for collections) are regularised area operations on linear rings, with a coordinate and an area error budget in PolygonBooleanOptions and caps on input, output and generated edges. The result carries measured errors and the provenance of every output edge. Curved and mesh booleans are not supported.

Curves (LineSegment, Arc, Circle, Ellipse, Bezier, Polyline and the Curve enum) with length, nearest point, intersections, trimming, extending, offsets and snap candidates; polygon slicing along zero-width separators; similarity and affine calibration from control points; and NURBS evaluation, tessellation and nearest-point search for the documented profile (degree 1 to 3, positive weights, open clamped knots). The supported profiles, error budgets and limits are specified in the geometry contracts; the API is on docs.rs/cadkit-geom.