ternary_contours/lib.rs
1//! Backend-independent regular-grid ternary fields and isoline construction.
2//!
3//! `ternary-contours` owns regular-lattice indexing, scalar-field validation,
4//! directed cubic-alpha interpolation, topology extraction, deterministic path
5//! assembly, optional arc-length regularization, and implicit-level projection.
6//! It has no dependency on Plotters, drawing backends, screen coordinates, or
7//! viewport clipping.
8//!
9//! The regular lattice stores finite samples at `i + j + k = n` in the ordering
10//! documented by [`RegularTernaryScalarField`]. With `cubic-alpha`, shared
11//! directed edge intervals use
12//! `y0*(1-t) + y1*t + (1-t)*t*(alpha0 + alpha1*t)`.
13//!
14//! Scope is deliberately limited to regular two-dimensional ternary grids.
15//! Piecewise-linear isolines and filled bands are available. Irregular
16//! triangulations, arbitrary-dimensional grids, Kuhn simplices, viewport
17//! clipping, rendering, and cubic-alpha filled bands are intentionally excluded.
18
19pub mod contour;
20mod error;
21pub mod field;
22pub mod grid;
23pub mod interpolation;
24
25/// A semantic `(a, b, c)` composition coordinate owned by the numerical core.
26///
27/// [`ContourSet`] returns finite normalized coordinates. `new` itself is an
28/// unchecked low-level constructor used by numerical algorithms; scalar-field
29/// and contour APIs validate all public input before producing paths.
30#[derive(Clone, Copy, Debug, PartialEq)]
31pub struct TernaryCoordinate {
32 a: f64,
33 b: f64,
34 c: f64,
35}
36
37impl TernaryCoordinate {
38 /// Construct an unchecked semantic A/B/C coordinate.
39 pub const fn new(a: f64, b: f64, c: f64) -> Self {
40 Self { a, b, c }
41 }
42
43 /// Return the semantic components in canonical A/B/C order.
44 pub const fn as_array(self) -> [f64; 3] {
45 [self.a, self.b, self.c]
46 }
47}
48
49impl From<[f64; 3]> for TernaryCoordinate {
50 fn from([a, b, c]: [f64; 3]) -> Self {
51 Self::new(a, b, c)
52 }
53}
54
55impl From<TernaryCoordinate> for [f64; 3] {
56 fn from(value: TernaryCoordinate) -> Self {
57 value.as_array()
58 }
59}
60
61pub use contour::{
62 AdaptiveContourOptions, ContourBand, ContourBandOptions, ContourBandSet, ContourError,
63 ContourFragment, ContourInterpolation, ContourLevel, ContourOptions, ContourPath,
64 ContourRegion, ContourRegularization, ContourSet, CubicAlphaOptions, CubicContourDiagnostics,
65};
66pub use error::{FieldError, GridEvaluationError};
67pub use grid::{GridVertexId, LatticeCoordinate, RegularTernaryGrid, RegularTernaryScalarField};
68pub use interpolation::{BinaryExtrapolation, CubicAlphaMethod, CubicBoundaryPolicy};