Quickstart: Rust
Eunoia is the pure-Rust core. Every other binding (JavaScript, R, Python, Julia) wraps the same engine. You describe a diagram with set sizes, pick a shape type, and fit. You get back fitted shapes plus goodness-of-fit metrics and, optionally, the region polygons to draw.
The diagram fitted by the first example below.
Install
Or add it to Cargo.toml directly:
[]
= "1.10"
The crate is pure Rust with no system dependencies. Edition 2024, MSRV 1.88.
Fit a Diagram
Building a diagram is two steps: describe what to draw with DiagramSpecBuilder (shape-agnostic), then fit it with Fitter<S>, choosing the shape type S at fit time.
use Circle;
use ;
let spec = new
.set
.set
.intersection
.input_type
.build
.expect;
let layout = new.seed.fit.expect;
.set names a set and its size; .intersection names the size of an overlap. Values are exclusive by default: the part of A outside B is 5, the overlap is 1.5. Pass InputType::Inclusive instead if your numbers are full set unions and eunoia will decompose them.
.seed(u64) makes the (stochastic, multi-restart) fit reproducible; omit it for a fresh layout each run.
For shapes with analytic gradients, the default optimizer is Optimizer::CmaEsBoundedLm: an LM baseline, a bounded LM retry, and CMA-ES escape with bounded LM polishing when needed. To select bounded LM alone, use .optimizer(Optimizer::BoundedLevenbergMarquardt). The old names Optimizer::CmaEsTrf and Optimizer::Trf remain accepted as deprecated synonyms, with the same fitting behavior.
Read the Result
fit() returns a Layout<S> carrying the fitted shapes and fit metrics:
for circle in layout.shapes
layout.loss; // objective value (lower is better)
layout.stress; // goodness-of-fit, à la venneuler
layout.diag_error; // largest single-region error
layout.iterations; // optimizer iterations of the kept restart
layout.requested; // target per-region areas
layout.fitted; // achieved per-region areas
Pick a Different Shape
The shape is the generic parameter on Fitter; the spec doesn't change:
use Ellipse;
let layout = new.fit.expect;
Circle, Ellipse, Square, Rectangle, and RotatedRectangle all live in eunoia::geometry::shapes. Ellipses have more freedom than circles and often fit three or more sets noticeably better; see Shapes.
Rotated rectangles add an orientation angle to the width and height and use derivative-free fitting:
use RotatedRectangle;
let layout = new.fit.expect;
Regions for Rendering
To draw the diagram, decompose it into the exclusive regions (A only, A&B, …) as polygons. Each region comes back as one or more polygons sampled at the given vertex count:
let regions = layout.region_polygons;
for in ®ions
Complement (the "Universe")
To fit a bounding container whose leftover area matches a target (items outside every set), opt in with .complement:
let spec = new
.set
.set
.intersection
.complement
.build
.expect;
let layout = new.fit.expect;
layout.container; // Some(rect): the jointly-fitted bounding box
See Complement for what this means.
Next Steps
The full API (every builder method, optimizer, loss function, and shape trait) is on docs.rs/eunoia. The in-tree examples/ directory has runnable programs (e.g. plotting_demo.rs). For how the fit actually works, read the Fitter Pipeline and Goodness of Fit chapters.
