moonbitTolerance

Deterministic mechanical tolerance stack-up analysis for MoonBit.

tolerance
mechanical
dimension-chain
engineering
moon add gckbbrant/moonbitTolerance@0.3.0
Download zip
Author
Version
0.3.0
License
Apache-2.0
Last updated
11 hours ago
Downloads
5
README

#moonbitTolerance

Deterministic mechanical tolerance stack-up analysis for MoonBit. The library is a reusable calculation kernel for CAD-adjacent tools, process planning, inspection software, and manufacturing data pipelines.

#Project positioning

moonbitTolerance keeps geometry, statistical assumptions, constraint evaluation, and reporting separate from any CAD file format. It is suitable when a host application needs reproducible one-dimensional or projected two-dimensional tolerance calculations with explicit assumptions.

#Core capabilities

  • Signed one-dimensional dimension chains with worst-case, RSS, and seeded Monte Carlo analysis.
  • Two-dimensional vector dimensions and projected stack-up intervals.
  • Uniform, triangular, and bounded normal-approximation sampling policies.
  • Process capability indices (Cp, Cpu, Cpl, and Cpk).
  • Gap constraints with satisfied, violated, and inconclusive outcomes.
  • CSV result export for small downstream reporting adapters.
  • Acceptance-window simulation summaries with deterministic seeds.
  • Conservative interval arithmetic, correlation-aware RSS propagation, and uncertainty budgets.
  • Hole/shaft fit classification, datum-frame feature checks, specification reports, and gauge R&R studies.
  • Scenario comparison, process trends, sample-size planning, tolerance allocation, and tightening recommendations.
  • Millimeter/inch/micrometer normalization with engineering-safe reporting rounding.
  • Native CLI demonstration and benchmark suite.

#Quick start

Requirements: MoonBit stable toolchain and a native-capable host for the CLI.

moon test --target wasm-gc --deny-warn moon run cmd/main

let chain = @moonbitTolerance.Chain::new("shaft", [
@moonbitTolerance.Dimension::new("housing", 20.0, 0.05),
@moonbitTolerance.Dimension::new(
"cover", 0.2, 0.02,
direction=@moonbitTolerance.negative_direction(),
),
])
let result = chain.monte_carlo(10000, seed=42U)

#CLI

moon run cmd/main prints a small RSS analysis and runs the deterministic benchmark suite. The CLI is intentionally a host-integration example; applications should import the root package and keep their own I/O boundary.

#Architecture

The root package owns the public engineering types. tolerance.mbt contains the one-dimensional kernel; interval.mbt, geometry.mbt, matrix.mbt, and correlation.mbt contain conservative numeric propagation; distributions.mbt, simulation.mbt, scenario.mbt, and planning.mbt contain deterministic analysis workflows; statistics.mbt, engineering.mbt, measurement.mbt, capability.mbt, and process.mbt contain inspection and process analytics; assembly.mbt, gdt.mbt, geometric.mbt, and specification.mbt contain manufacturing acceptance checks; allocation.mbt, optimizer.mbt, uncertainty.mbt, units.mbt, and rounding.mbt support design decisions and host integration. reporting.mbt and validation.mbt keep text output and preflight checks at the boundary. cmd/main is an executable consumer of the package.

#Benchmark

The benchmark suite uses the same public API as an application: five chains with 4, 8, 16, 32, and 64 contributors, each sampled with an explicit seed. Run it with:

moon run cmd/main

The output is deterministic for a fixed toolchain, sample count, and seed. The acceptance window is deliberately narrower than the physical worst-case interval so the benchmark exercises both passing and failing samples. The repository does not claim a hardware-independent throughput number; wall-clock measurements belong to the machine and backend that produced them.

#Testing

moon fmt --check moon check --deny-warn moon test --target wasm-gc --deny-warn moon test --target native --deny-warn moon info

Tests cover invalid-input guards, signed dimensions, deterministic sampling, distribution differences, acceptance-window yield, interval arithmetic, covariance and correlation propagation, quantiles, process capability edges, measurement studies, fit classification, datum-frame checks, trend analysis, allocation planning, units, reporting, and constraints.

#CI

GitHub Actions runs formatting, warning-free type checking, generated-interface drift detection, coverage analysis, wasm-gc tests, and native tests on Linux, macOS, and Windows. The workflow installs the current MoonBit stable toolchain using the official installer and keeps the generated interface under review.

#License

Apache-2.0. See LICENSE.

#Development

See CONTRIBUTING.md for the local validation loop and docs/assumptions.md for modeling assumptions.

#
AcceptanceWindow

pub struct AcceptanceWindow {
lower : Double
upper : Double
} derive(Eq,
Debug
)

#
AcceptanceWindow::contains

fn AcceptanceWindow::contains(self : AcceptanceWindow, value : Double) -> Bool

#
AcceptanceWindow::new

fn AcceptanceWindow::new(lower : Double, upper : Double) -> AcceptanceWindow

#
AllocationItem

pub struct AllocationItem {
name : String
nominal : Double
allocated_tolerance : Double
variance_fraction : Double
weight : Double
} derive(Eq,
Debug
)

One allocated dimension in a tolerance budget plan.

#
AllocationReport

pub struct AllocationReport {
items : Array[AllocationItem]
total_nominal : Double
total_rss : Double
worst_case_span : Double
strategy : AllocationStrategy
} derive(Eq,
Debug
)

A complete RSS allocation and its resulting worst-case span.

#
AllocationReport::interval

Return the conservative interval resulting from an allocation plan.

#
AllocationReport::largest_contributor

fn AllocationReport::largest_contributor(self : AllocationReport) -> AllocationItem

Return the largest allocated contributor.

#
AllocationStrategy

pub enum AllocationStrategy {
Equal
Proportional
Sensitivity
} derive(Eq,
Debug
)

Strategies for distributing a total RSS tolerance budget.

#
AnalysisResult

pub struct AnalysisResult {
nominal : Double
lower : Double
upper : Double
mean : Double
standard_deviation : Double
yield_rate : Double
sensitivity : Array[(String, Double)]
} derive(
Debug
)

#
Angle

pub struct Angle {
radians : Double
} derive(Eq,
Debug
)

An angle normalized to radians.

#
Angle::add

fn Angle::add(self : Angle, other : Angle) -> Angle

Add two angles.

#
Angle::direction

fn Angle::direction(self : Angle) -> Vector2

Return a unit direction vector for the angle.

#
Angle::from_degrees

fn Angle::from_degrees(degrees : Double) -> Angle

Construct an angle from degrees.

#
Angle::from_radians

fn Angle::from_radians(radians : Double) -> Angle

Construct an angle from radians.

#
Angle::to_degrees

fn Angle::to_degrees(self : Angle) -> Double

Return the angle in degrees.

#
Angle::to_radians

fn Angle::to_radians(self : Angle) -> Double

Return the angle in radians.

#
BenchmarkCase

pub struct BenchmarkCase {
name : String
dimensions : Int
tolerance : Double
seed : UInt
} derive(
Debug
)

#
BenchmarkCase::chain

fn BenchmarkCase::chain(self : BenchmarkCase) -> Chain

#
BiasReport

pub struct BiasReport {
count : Int
reference : Double
mean : Double
bias : Double
standard_deviation : Double
maximum_absolute_error : Double
} derive(Eq,
Debug
)

A measured bias relative to a reference value.

#
CapabilityReport

pub struct CapabilityReport {
statistics : SampleStatistics
cp : Double
cpu : Double
cpl : Double
cpk : Double
observed_yield : Double
} derive(Eq,
Debug
)

#
Chain

pub struct Chain {
name : String
dimensions : Array[Dimension]
} derive(
Debug
)

#
Chain::monte_carlo

fn Chain::monte_carlo(self : Chain, samples : Int, seed? : UInt) -> AnalysisResult

#
Chain::new

fn Chain::new(name : String, dimensions : Array[Dimension]) -> Chain

#
Chain::nominal

fn Chain::nominal(self : Chain) -> Double

#
Chain::rss

fn Chain::rss(self : Chain) -> AnalysisResult

#
Chain::simulate

fn Chain::simulate(self : Chain, samples : Int, policy : SamplingPolicy, window : AcceptanceWindow) -> SimulationSummary

#
Chain::worst_case

fn Chain::worst_case(self : Chain) -> AnalysisResult

#
ConstraintReport

pub struct ConstraintReport {
passed : Int
failed : Int
inconclusive : Int
statuses : Array[(String, ConstraintStatus)]
} derive(
Debug
)

#
ConstraintStatus

pub enum ConstraintStatus {
Satisfied
Violated
Inconclusive
} derive(Eq,
Debug
)

#
ControlLimits

pub struct ControlLimits {
center : Double
lower : Double
upper : Double
standard_deviation : Double
sigma_multiplier : Double
} derive(Eq,
Debug
)

Three-sigma control limits around an observed center line.

#
CorrelatedRSSReport

pub struct CorrelatedRSSReport {
independent_variance : Double
correlation_adjustment : Double
variance : Double
standard_deviation : Double
} derive(Eq,
Debug
)

RSS variation after applying pairwise correlation adjustments.

#
CorrelationTerm

pub struct CorrelationTerm {
first : Int
second : Int
coefficient : Double
} derive(Eq,
Debug
)

A pairwise correlation coefficient between two dimension contributors.

#
CorrelationTerm::new

fn CorrelationTerm::new(first : Int, second : Int, coefficient : Double) -> CorrelationTerm

Construct a correlation term with a coefficient in [-1, 1].

#
Covariance2

pub struct Covariance2 {
xx : Double
xy : Double
yy : Double
} derive(Eq,
Debug
)

#
Covariance2::variance_along

fn Covariance2::variance_along(self : Covariance2, direction : Vector2) -> Double

#
DatumFrame

pub struct DatumFrame {
primary : DatumReference
secondary : DatumReference
tertiary : DatumReference
} derive(Eq,
Debug
)

A primary/secondary/tertiary datum reference frame.

#
DatumFrame::is_complete

fn DatumFrame::is_complete(self : DatumFrame) -> Bool

Return whether all three datum slots contain labels.

#
DatumFrame::label

fn DatumFrame::label(self : DatumFrame) -> String

Return a compact datum-frame label for reports.

#
DatumFrame::new

fn DatumFrame::new(primary : DatumReference, secondary : DatumReference, tertiary : DatumReference) -> DatumFrame

Construct a complete datum frame.

#
DatumFrame::single

fn DatumFrame::single(primary : DatumReference) -> DatumFrame

Construct a frame containing only a primary datum.

#
DatumReference

pub struct DatumReference {
label : String
order : Int
} derive(Eq,
Debug
)

A datum label and its precedence in a datum reference frame.

#
DatumReference::new

fn DatumReference::new(label : String, order : Int) -> DatumReference

Create a datum reference. Orders are normally one, two, and three.

#
Dimension

pub struct Dimension {
name : String
nominal : Double
tolerance : Double
direction : Direction
} derive(Eq,
Debug
)

#
Dimension::new

fn Dimension::new(name : String, nominal : Double, tolerance : Double, direction? : Direction) -> Dimension

#
Direction

pub enum Direction {
Positive
Negative
} derive(Eq,
Debug
)

#
Distribution

pub enum Distribution {
Uniform
Triangular
NormalApproximation
} derive(Eq,
Debug
)

#
FeasibilityReport

pub struct FeasibilityReport {
nominal : Double
window : AcceptanceWindow
worst_case_interval : Interval
rss_interval : Interval
worst_case_margin : Double
rss_margin : Double
worst_case_passes : Bool
rss_passes : Bool
} derive(Eq,
Debug
)

Worst-case and RSS feasibility against one acceptance window.

#
FeatureControlFrame

pub struct FeatureControlFrame {
mode : GeometricMode
tolerance : Double
datum_frame : DatumFrame
} derive(Eq,
Debug
)

A geometric characteristic attached to a datum frame.

#
FeatureControlFrame::concentricity

fn FeatureControlFrame::concentricity(tolerance : Double, datum_frame : DatumFrame) -> FeatureControlFrame

Create a concentricity control frame.

#
FeatureControlFrame::position

fn FeatureControlFrame::position(tolerance : Double, datum_frame : DatumFrame) -> FeatureControlFrame

Create a position control frame.

#
FeatureControlFrame::runout

fn FeatureControlFrame::runout(tolerance : Double, datum_frame : DatumFrame) -> FeatureControlFrame

Create a circular runout control frame.

#
FeatureEvaluation

pub struct FeatureEvaluation {
name : String
status : ConstraintStatus
deviation : Double
margin : Double
datum_label : String
} derive(Eq,
Debug
)

Evaluation of one feature-control frame.

#
FeatureEvaluationReport

pub struct FeatureEvaluationReport {
total : Int
passed : Int
failed : Int
evaluations : Array[FeatureEvaluation]
} derive(Eq,
Debug
)

Aggregate feature-control evaluations for a measurement batch.

#
FeatureMeasurement

pub struct FeatureMeasurement {
name : String
nominal : Vector2
measured : Vector2
} derive(Eq,
Debug
)

A measured feature center or radial reference.

#
FeatureMeasurement::new

fn FeatureMeasurement::new(name : String, nominal : Vector2, measured : Vector2) -> FeatureMeasurement

Create a measured feature record.

#
FitAnalysis

pub struct FitAnalysis {
hole_nominal : Double
shaft_nominal : Double
nominal_clearance : Double
minimum_clearance : Double
maximum_clearance : Double
classification : FitClassification
} derive(Eq,
Debug
)

Worst-case clearance analysis for a cylindrical fit.

#
FitAnalysis::accepts

fn FitAnalysis::accepts(self : FitAnalysis, requested : Interval) -> Bool

Return whether every possible fit outcome lies in the requested interval.

#
FitAnalysis::clearance

fn FitAnalysis::clearance(self : FitAnalysis) -> Interval

Return the complete clearance interval for a fit.

#
FitAnalysis::guarantees_clearance

fn FitAnalysis::guarantees_clearance(self : FitAnalysis, minimum : Double) -> Bool

Return whether the fit guarantees at least the requested clearance.

#
FitAnalysis::limits_clearance

fn FitAnalysis::limits_clearance(self : FitAnalysis, maximum : Double) -> Bool

Return whether the fit guarantees no more than the requested clearance.

#
FitAnalysis::margin

fn FitAnalysis::margin(self : FitAnalysis, requested : Interval) -> Double

Return the signed margin to the requested clearance interval.

#
FitClassification

pub enum FitClassification {
Clearance
Transition
Interference
} derive(Eq,
Debug
)

The three practical fit outcomes for a hole and shaft pair.

#
FitRequirement

pub struct FitRequirement {
name : String
minimum_clearance : Double
maximum_clearance : Double
} derive(Eq,
Debug
)

A named assembly fit requirement for batch evaluation.

#
FitRequirement::evaluate

Evaluate a fit against a named requirement.

#
FitRequirement::new

fn FitRequirement::new(name : String, minimum_clearance : Double, maximum_clearance : Double) -> FitRequirement

Create a fit requirement with explicit lower and upper bounds.

#
FitRequirementReport

pub struct FitRequirementReport {
passed : Int
failed : Int
inconclusive : Int
statuses : Array[(String, ConstraintStatus)]
} derive(Eq,
Debug
)

Summarize a collection of fit requirements for one analyzed fit.

#
GapConstraint

pub struct GapConstraint {
name : String
minimum : Double
maximum : Double
} derive(
Debug
)

#
GapConstraint::evaluate

#
GapConstraint::new

fn GapConstraint::new(name : String, minimum : Double, maximum : Double) -> GapConstraint

#
GaugeRRReport

pub struct GaugeRRReport {
part_count : Int
operator_count : Int
repeat_count : Int
total_measurements : Int
repeatability : Double
reproducibility : Double
part_to_part : Double
total_variation : Double
percent_tolerance : Double
ndc : Double
} derive(Eq,
Debug
)

Gauge repeatability and reproducibility results for a crossed study.

#
GeometricMode

pub enum GeometricMode {
Position
Concentricity
Runout
} derive(Eq,
Debug
)

#
GeometricTolerance

pub struct GeometricTolerance {
mode : GeometricMode
zone : Double
} derive(Eq,
Debug
)

#
GeometricTolerance::evaluate

fn GeometricTolerance::evaluate(self : GeometricTolerance, measured : Vector2, nominal : Vector2) -> ConstraintStatus

#
GeometricTolerance::new

fn GeometricTolerance::new(mode : GeometricMode, zone : Double) -> GeometricTolerance

#
Histogram

pub struct Histogram {
bins : Array[HistogramBin]
total : Int
minimum : Double
maximum : Double
} derive(Eq,
Debug
)

A deterministic equal-width histogram of measured values.

#
Histogram::bin_for

fn Histogram::bin_for(self : Histogram, value : Double) -> Int

Return the bin index containing a value, clamped to the histogram range.

#
Histogram::counted_samples

fn Histogram::counted_samples(self : Histogram) -> Int

Count all observations represented by the bins.

#
Histogram::cumulative_fraction

fn Histogram::cumulative_fraction(self : Histogram, value : Double) -> Double

Return the fraction of observations at or below a value.

#
Histogram::frequency

fn Histogram::frequency(self : Histogram, index : Int) -> Int

Return the count of one bin by index.

#
Histogram::percentile

fn Histogram::percentile(self : Histogram, probability : Double) -> Double

Estimate a percentile by interpolating within its containing bin.

#
HistogramBin

pub struct HistogramBin {
lower : Double
upper : Double
count : Int
} derive(Eq,
Debug
)

One closed-open histogram bin, with the final bin closed at the maximum.

#
InspectionReport

pub struct InspectionReport {
statistics : SampleStatistics
window : AcceptanceWindow
accepted : Int
rejected : Int
yield_rate : Double
capability : CapabilityReport
} derive(Eq,
Debug
)

A batch inspection report against an explicit acceptance window.

#
Interval

pub struct Interval {
lower : Double
upper : Double
} derive(Eq,
Debug
)

A closed numeric interval used for conservative tolerance propagation.

#
Interval::absolute

fn Interval::absolute(self : Interval) -> Interval

Return the absolute-value enclosure of the interval.

#
Interval::add

fn Interval::add(self : Interval, other : Interval) -> Interval

Add two intervals.

#
Interval::contains

fn Interval::contains(self : Interval, value : Double) -> Bool

Return whether the value is inside the closed interval.

#
Interval::distance_to

fn Interval::distance_to(self : Interval, value : Double) -> Double

Return the distance from a value to this interval, or zero when contained.

#
Interval::divide

fn Interval::divide(self : Interval, denominator : Interval) -> Interval?

Divide by an interval. Division is undefined when the denominator contains zero.

#
Interval::hull

fn Interval::hull(self : Interval, other : Interval) -> Interval

Return the smallest interval containing both operands.

#
Interval::intersection

fn Interval::intersection(self : Interval, other : Interval) -> Interval?

Return the overlap of two intervals, if one exists.

#
Interval::intersects

fn Interval::intersects(self : Interval, other : Interval) -> Bool

Return whether two closed intervals overlap or touch.

#
Interval::midpoint

fn Interval::midpoint(self : Interval) -> Double

Return the interval midpoint.

#
Interval::mul

fn Interval::mul(self : Interval, other : Interval) -> Interval

Multiply two intervals using all endpoint combinations.

#
Interval::negate

fn Interval::negate(self : Interval) -> Interval

Negate an interval.

#
Interval::new

fn Interval::new(lower : Double, upper : Double) -> Interval

Construct an interval. Bounds are inclusive and must be ordered.

#
Interval::point

fn Interval::point(value : Double) -> Interval

Construct an interval containing a single value.

#
Interval::scale

fn Interval::scale(self : Interval, factor : Double) -> Interval

Scale an interval, preserving its ordering for negative factors.

#
Interval::sub

fn Interval::sub(self : Interval, other : Interval) -> Interval

Subtract two intervals.

#
Interval::width

fn Interval::width(self : Interval) -> Double

Return the interval width.

#
IntervalVector2

pub struct IntervalVector2 {
x : Interval
y : Interval
} derive(Eq,
Debug
)

A two-dimensional rectangular interval.

#
IntervalVector2::add

Add rectangular vector intervals component by component.

#
IntervalVector2::magnitude_bounds

fn IntervalVector2::magnitude_bounds(self : IntervalVector2) -> Interval

Return conservative lower and upper bounds for vector magnitude.

#
IntervalVector2::new

Construct a rectangular vector interval.

#
Length

pub struct Length {
millimeters : Double
} derive(Eq,
Debug
)

A length normalized to millimeters at the library boundary.

#
Length::add

fn Length::add(self : Length, other : Length) -> Length

Add two normalized lengths.

#
Length::from_inches

fn Length::from_inches(inches : Double) -> Length

Construct a length from international inches.

#
Length::from_micrometers

fn Length::from_micrometers(micrometers : Double) -> Length

Construct a length from micrometers.

#
Length::from_millimeters

fn Length::from_millimeters(millimeters : Double) -> Length

Construct a normalized length in millimeters.

#
Length::scale

fn Length::scale(self : Length, factor : Double) -> Length

Scale a normalized length.

#
Length::sub

fn Length::sub(self : Length, other : Length) -> Length

Subtract two normalized lengths.

#
Length::to_inches

fn Length::to_inches(self : Length) -> Double

Return the length in international inches.

#
Length::to_micrometers

fn Length::to_micrometers(self : Length) -> Double

Return the length in micrometers.

#
Length::to_millimeters

fn Length::to_millimeters(self : Length) -> Double

Return the length in millimeters.

#
LengthTolerance

pub struct LengthTolerance {
nominal : Length
lower : Length
upper : Length
} derive(Eq,
Debug
)

A tolerance expressed in the normalized length unit.

#
LengthTolerance::interval

fn LengthTolerance::interval(self : LengthTolerance) -> Interval

Return the corresponding interval in millimeters.

#
LengthTolerance::symmetric

fn LengthTolerance::symmetric(nominal : Length, tolerance : Length) -> LengthTolerance

Construct a symmetric length tolerance around a nominal value.

#
Matrix2

pub struct Matrix2 {
m11 : Double
m12 : Double
m21 : Double
m22 : Double
} derive(Eq,
Debug
)

A compact two-by-two matrix for projected tolerance transforms.

#
Matrix2::apply

fn Matrix2::apply(self : Matrix2, vector : Vector2) -> Vector2

Apply the matrix to a vector.

#
Matrix2::determinant

fn Matrix2::determinant(self : Matrix2) -> Double

Return the determinant.

#
Matrix2::identity

fn Matrix2::identity() -> Matrix2

Construct the identity matrix.

#
Matrix2::inverse

fn Matrix2::inverse(self : Matrix2) -> Matrix2?

Return the inverse, if the determinant is non-zero.

#
Matrix2::is_orthonormal

fn Matrix2::is_orthonormal(self : Matrix2) -> Bool

Return the matrix as an orthonormal transform within tolerance.

#
Matrix2::multiply

fn Matrix2::multiply(self : Matrix2, other : Matrix2) -> Matrix2

Multiply two matrices.

#
Matrix2::new

fn Matrix2::new(m11 : Double, m12 : Double, m21 : Double, m22 : Double) -> Matrix2

Construct a matrix from row-major entries.

#
Matrix2::rotation

fn Matrix2::rotation(angle_radians : Double) -> Matrix2

Construct a two-dimensional rotation matrix.

#
Matrix2::scale

fn Matrix2::scale(x : Double, y : Double) -> Matrix2

Construct a diagonal scale matrix.

#
Matrix2::transpose

fn Matrix2::transpose(self : Matrix2) -> Matrix2

Return the transpose.

#
ProcessCapability

pub struct ProcessCapability {
lower_spec : Double
upper_spec : Double
mean : Double
standard_deviation : Double
} derive(
Debug
)

#
ProcessCapability::cp

fn ProcessCapability::cp(self : ProcessCapability) -> Double

#
ProcessCapability::cpk

fn ProcessCapability::cpk(self : ProcessCapability) -> Double

#
ProcessCapability::cpl

fn ProcessCapability::cpl(self : ProcessCapability) -> Double

#
ProcessCapability::cpu

fn ProcessCapability::cpu(self : ProcessCapability) -> Double

#
ProcessCapability::new

fn ProcessCapability::new(lower_spec : Double, upper_spec : Double, mean : Double, standard_deviation : Double) -> ProcessCapability

#
ProcessPerformance

pub struct ProcessPerformance {
statistics : SampleStatistics
accepted : Int
rejected : Int
lower_defects : Int
upper_defects : Int
observed_yield : Double
defect_rate : Double
capability : CapabilityReport
} derive(Eq,
Debug
)

Process performance facts for an inspection batch.

#
ProjectedDimension

pub struct ProjectedDimension {
name : String
vector : Vector2
tolerance : Double
} derive(
Debug
)

#
ProjectedDimension::new

fn ProjectedDimension::new(name : String, vector : Vector2, tolerance : Double) -> ProjectedDimension

#
ProjectedResult

pub struct ProjectedResult {
nominal : Vector2
lower_x : Double
upper_x : Double
lower_y : Double
upper_y : Double
radial_tolerance : Double
sensitivity : Array[(String, Double)]
} derive(
Debug
)

#
RoundingMode

pub enum RoundingMode {
Nearest
Down
Up
TowardZero
} derive(Eq,
Debug
)

Reporting rounding policies for engineering values.

#
RunningStatistics

pub struct RunningStatistics {
count : Int
mean : Double
second_moment : Double
minimum : Double
maximum : Double
} derive(Eq,
Debug
)

A mergeable accumulator for numerically stable sample statistics.

#
RunningStatistics::add

fn RunningStatistics::add(self : RunningStatistics, value : Double) -> RunningStatistics

Add a value and return the updated accumulator.

#
RunningStatistics::add_all

fn RunningStatistics::add_all(self : RunningStatistics, values : Array[Double]) -> RunningStatistics

Add all values from an array.

#
RunningStatistics::finish

Finalize the accumulator as the package's sample-statistics type.

#
RunningStatistics::merge

Merge two accumulators without replaying their original samples.

#
RunningStatistics::new

Create an empty running accumulator.

#
SamplePlan

pub struct SamplePlan {
expected_yield : Double
confidence : Double
margin : Double
z_score : Double
samples : Int
expected_half_width : Double
} derive(Eq,
Debug
)

A sample-size plan for estimating an acceptance yield.

#
SampleStatistics

pub struct SampleStatistics {
count : Int
mean : Double
variance : Double
standard_deviation : Double
minimum : Double
maximum : Double
} derive(Eq,
Debug
)

#
SamplingPolicy

pub struct SamplingPolicy {
distribution : Distribution
sigma_factor : Double
seed : UInt
} derive(
Debug
)

#
SamplingPolicy::new

fn SamplingPolicy::new(distribution? : Distribution, sigma_factor? : Double, seed? : UInt) -> SamplingPolicy

#
ScenarioComparison

pub struct ScenarioComparison {
baseline_name : String
candidate_name : String
nominal_delta : Double
standard_deviation_delta : Double
yield_delta : Double
interval_overlap : Bool
} derive(Eq,
Debug
)

Comparison of two normalized scenario outcomes.

#
ScenarioMethod

pub enum ScenarioMethod {
WorstCase
RSS
MonteCarlo
AcceptanceSimulation
} derive(Eq,
Debug
)

Analysis methods available to a repeatable engineering scenario.

#
ScenarioResult

pub struct ScenarioResult {
name : String
analysis_method : ScenarioMethod
nominal : Double
lower : Double
upper : Double
mean : Double
standard_deviation : Double
yield_rate : Double
sensitivity : Array[(String, Double)]
} derive(Eq,
Debug
)

A normalized result independent of the selected analysis method.

#
ScenarioResult::interval

fn ScenarioResult::interval(self : ScenarioResult) -> Interval

Return the method-independent interval of a scenario result.

#
ScenarioResult::within_window

fn ScenarioResult::within_window(self : ScenarioResult, window : AcceptanceWindow) -> Bool

Return whether a scenario interval remains inside an acceptance window.

#
ScenarioSpec

pub struct ScenarioSpec {
name : String
chain : Chain
analysis_method : ScenarioMethod
samples : Int
window : AcceptanceWindow
policy : SamplingPolicy
} derive(
Debug
)

Inputs for a named, reproducible analysis scenario.

#
ScenarioSpec::new

fn ScenarioSpec::new(name : String, chain : Chain, analysis_method : ScenarioMethod, samples : Int, window : AcceptanceWindow) -> ScenarioSpec

Construct a scenario with a default seeded uniform sampling policy.

#
ScenarioSpec::with_policy

fn ScenarioSpec::with_policy(self : ScenarioSpec, policy : SamplingPolicy) -> ScenarioSpec

Replace the default policy while preserving the other scenario inputs.

#
SensitivityItem

pub struct SensitivityItem {
name : String
contribution : Double
fraction : Double
} derive(Eq,
Debug
)

#
SimulationSummary

pub struct SimulationSummary {
nominal : Double
minimum : Double
maximum : Double
mean : Double
standard_deviation : Double
yield_rate : Double
samples : Int
sensitivity : Array[(String, Double)]
} derive(
Debug
)

#
Specification

pub struct Specification {
lower : Double
upper : Double
nominal : Double
} derive(Eq,
Debug
)

A nominal value with explicit lower and upper specification limits.

#
Specification::classify

fn Specification::classify(self : Specification, value : Double) -> SpecificationStatus

Classify a measurement against both limits.

#
Specification::contains

fn Specification::contains(self : Specification, value : Double) -> Bool

Return whether a value is within specification.

#
Specification::margin

fn Specification::margin(self : Specification, value : Double) -> Double

Return the signed margin to the nearest limit.

#
Specification::new

fn Specification::new(lower : Double, upper : Double, nominal : Double) -> Specification

Construct a specification band.

#
Specification::window

Return the specification as an acceptance window.

#
SpecificationReport

pub struct SpecificationReport {
count : Int
accepted : Int
lower_failures : Int
upper_failures : Int
yield_rate : Double
mean_margin : Double
} derive(Eq,
Debug
)

Aggregated specification results for an inspection batch.

#
SpecificationStatus

pub enum SpecificationStatus {
BelowLower
WithinSpecification
AboveUpper
} derive(Eq,
Debug
)

Classification of one measurement against a specification band.

#
TighteningItem

pub struct TighteningItem {
name : String
current_tolerance : Double
proposed_tolerance : Double
expected_reduction : Double
priority : Double
} derive(Eq,
Debug
)

One contributor in a tolerance-tightening recommendation.

#
TighteningPlan

pub struct TighteningPlan {
current_rss : Double
target_rss : Double
projected_rss : Double
items : Array[TighteningItem]
} derive(Eq,
Debug
)

A ranked plan for reducing a chain's RSS variation.

#
TighteningPlan::largest_reduction

fn TighteningPlan::largest_reduction(self : TighteningPlan) -> TighteningItem

Return the largest proposed tolerance change.

#
TighteningPlan::projected_variance

fn TighteningPlan::projected_variance(self : TighteningPlan) -> Double

Return the sum of squared proposed tolerances in a plan.

#
Transform2

pub struct Transform2 {
linear : Matrix2
translation : Vector2
} derive(Eq,
Debug
)

A rigid or affine two-dimensional transform.

#
Transform2::apply

fn Transform2::apply(self : Transform2, point : Vector2) -> Vector2

Apply a transform to a point.

#
Transform2::compose

fn Transform2::compose(self : Transform2, other : Transform2) -> Transform2

Compose this transform after another transform.

#
Transform2::inverse

fn Transform2::inverse(self : Transform2) -> Transform2?

Return the inverse transform when its linear part is invertible.

#
Transform2::new

fn Transform2::new(linear : Matrix2, translation : Vector2) -> Transform2

Construct a transform from a linear matrix and translation.

#
TrendReport

pub struct TrendReport {
count : Int
slope : Double
intercept : Double
r_squared : Double
} derive(Eq,
Debug
)

A least-squares linear trend over equally spaced observations.

#
UncertaintyBudget

pub struct UncertaintyBudget {
contributors : Array[UncertaintyContribution]
combined : Double
total_variance : Double
} derive(Eq,
Debug
)

Combined RSS uncertainty and its named contributors.

#
UncertaintyBudget::interval

fn UncertaintyBudget::interval(self : UncertaintyBudget, nominal : Double, coverage_factor : Double) -> Interval

Return a symmetric interval at a requested coverage multiplier.

#
UncertaintyBudget::largest

Return the largest effective uncertainty contributor.

#
UncertaintyBudget::ranked

Return contributors ordered by variance fraction.

#
UncertaintyContribution

pub struct UncertaintyContribution {
name : String
effective_uncertainty : Double
variance : Double
fraction : Double
} derive(Eq,
Debug
)

One propagated contribution in an uncertainty budget.

#
UncertaintySource

pub struct UncertaintySource {
name : String
standard_uncertainty : Double
sensitivity : Double
} derive(Eq,
Debug
)

One independent uncertainty source and its local sensitivity.

#
UncertaintySource::new

fn UncertaintySource::new(name : String, standard_uncertainty : Double, sensitivity : Double) -> UncertaintySource

Construct an uncertainty source.

#
ValidationIssue

pub struct ValidationIssue {
scope : String
message : String
} derive(Eq,
Debug
)

A non-throwing validation message for host applications.

#
ValidationReport

pub struct ValidationReport {
valid : Bool
issue_count : Int
issues : Array[ValidationIssue]
} derive(Eq,
Debug
)

Result of preflight validation before running an analysis.

#
Vector2

pub struct Vector2 {
x : Double
y : Double
} derive(Eq,
Debug
)

#
Vector2::add

fn Vector2::add(self : Vector2, other : Vector2) -> Vector2

#
Vector2::dot

fn Vector2::dot(self : Vector2, other : Vector2) -> Double

#
Vector2::length

fn Vector2::length(self : Vector2) -> Double

#
Vector2::length_squared

fn Vector2::length_squared(self : Vector2) -> Double

#
Vector2::new

fn Vector2::new(x : Double, y : Double) -> Vector2

#
Vector2::normalize

fn Vector2::normalize(self : Vector2) -> Vector2

#
Vector2::scale

fn Vector2::scale(self : Vector2, factor : Double) -> Vector2

#
Vector2::sub

fn Vector2::sub(self : Vector2, other : Vector2) -> Vector2

#
Vector2::zero

fn Vector2::zero() -> Vector2

#
YieldEstimate

pub struct YieldEstimate {
accepted : Int
total : Int
rate : Double
lower_bound : Double
upper_bound : Double
} derive(Eq,
Debug
)

An approximate normal confidence interval for an observed yield.

#
acceptance_simulation_method

fn acceptance_simulation_method() -> ScenarioMethod

Select distribution-aware acceptance-window simulation.

#
allocate_chain

fn allocate_chain(chain : Chain, total_rss : Double, strategy : AllocationStrategy) -> AllocationReport

Allocate an RSS budget while preserving contributor names and nominal values.

#
allocation_to_csv

fn allocation_to_csv(report : AllocationReport) -> String

Serialize an allocation plan as a stable CSV table.

#
analyze_fit

fn analyze_fit(hole : Dimension, shaft : Dimension) -> FitAnalysis

Analyze the complete worst-case range of a hole and shaft fit.

#
benchmark_suite

fn benchmark_suite() -> Array[BenchmarkCase]

#
capability_report

fn capability_report(values : Array[Double], window : AcceptanceWindow) -> CapabilityReport

#
capability_to_csv

fn capability_to_csv(report : CapabilityReport) -> String

#
centering_margin

fn centering_margin(mean : Double, window : AcceptanceWindow) -> Double

Return the signed distance from a process mean to the nearest specification edge.

#
chain_interval

fn chain_interval(chain : Chain) -> Interval

Propagate a dimension chain with interval arithmetic.

#
classify_clearance

fn classify_clearance(clearance : Interval) -> FitClassification

Classify a clearance interval by its position relative to zero.

#
combine_validation

fn combine_validation(first : ValidationReport, second : ValidationReport) -> ValidationReport

Combine validation reports from a chain and measurement batch.

#
compare_scenarios

fn compare_scenarios(baseline : ScenarioResult, candidate : ScenarioResult) -> ScenarioComparison

Compare nominal, variation, yield, and interval overlap between scenarios.

#
concentricity_tolerance

fn concentricity_tolerance(zone : Double) -> GeometricTolerance

Construct a concentricity tolerance zone.

#
control_limit_violations

fn control_limit_violations(values : Array[Double], limits : ControlLimits) -> Int

Count observations outside the control limits.

#
control_limits

fn control_limits(values : Array[Double], sigma_multiplier? : Double) -> ControlLimits

Calculate symmetric control limits from a batch of observations.

#
correlated_interval

fn correlated_interval(chain : Chain, terms : Array[CorrelationTerm], coverage_factor : Double) -> Interval

Return a nominal interval using a correlation-aware standard deviation.

#
correlated_rss

fn correlated_rss(dimensions : Array[Dimension], terms : Array[CorrelationTerm]) -> CorrelatedRSSReport

Calculate a correlation-aware RSS uncertainty estimate.

#
correlated_standard_deviation

fn correlated_standard_deviation(chain : Chain, terms : Array[CorrelationTerm]) -> Double

Return the correlation-adjusted standard deviation for a chain.

#
covariance_of

fn covariance_of(dimensions : Array[ProjectedDimension]) -> Covariance2

#
defects_per_million

fn defects_per_million(report : ProcessPerformance) -> Double

Convert an observed defect rate to parts per million.

#
deterministic_uniform

fn deterministic_uniform(seed : UInt) -> (UInt, Double)

#
dimension_interval

fn dimension_interval(dimension : Dimension) -> Interval

Return the one-dimensional conservative interval for a signed dimension.

#
down_rounding

fn down_rounding() -> RoundingMode

Select downward rounding.

#
equal_allocation

fn equal_allocation() -> AllocationStrategy

Create an equal-contribution allocation strategy.

#
equal_rss_budget

fn equal_rss_budget(chain : Chain, total_rss : Double) -> Array[(String, Double)]

#
equal_tolerance_for_budget

fn equal_tolerance_for_budget(chain : Chain, total_rss : Double) -> AllocationReport

Allocate the same tolerance to every contributor for a requested RSS budget.

#
estimate_yield

fn estimate_yield(values : Array[Double], window : AcceptanceWindow) -> YieldEstimate

Estimate yield and a 95% normal-approximation confidence interval.

#
evaluate_constraints

fn evaluate_constraints(result : AnalysisResult, constraints : Array[GapConstraint]) -> ConstraintReport

#
evaluate_feature

fn evaluate_feature(control : FeatureControlFrame, measurement : FeatureMeasurement) -> FeatureEvaluation

Evaluate a measured feature against its control frame.

#
evaluate_features

fn evaluate_features(controls : Array[FeatureControlFrame], measurements : Array[FeatureMeasurement]) -> FeatureEvaluationReport

Evaluate corresponding controls and measurements in order.

#
evaluate_fit_requirements

fn evaluate_fit_requirements(fit : FitAnalysis, requirements : Array[FitRequirement]) -> FitRequirementReport

Evaluate all requirements while preserving their names.

#
evaluate_specification

fn evaluate_specification(values : Array[Double], specification : Specification) -> SpecificationReport

Evaluate every value and preserve lower/upper defect directions.

#
feasibility_report

fn feasibility_report(chain : Chain, window : AcceptanceWindow) -> FeasibilityReport

Compare conservative worst-case and three-sigma RSS intervals.

#
fit_to_csv

fn fit_to_csv(fit : FitAnalysis) -> String

Serialize the complete fit range and classification.

#
gauge_rr

fn gauge_rr(values : Array[Double], part_count : Int, operator_count : Int, repeat_count : Int, tolerance_width : Double) -> GaugeRRReport

Calculate a crossed gauge R&R study.

Values are ordered part-major, then operator-major, then repeat-major.

#
histogram

fn histogram(values : Array[Double], bin_count : Int) -> Histogram

Build an equal-width histogram with a fixed number of bins.

#
histogram_to_csv

fn histogram_to_csv(value : Histogram) -> String

Serialize histogram bins as a stable CSV table.

#
inspect_batch

fn inspect_batch(values : Array[Double], window : AcceptanceWindow) -> InspectionReport

Inspect a batch and combine observed yield with process capability.

#
interval_contains

fn interval_contains(result : AnalysisResult, value : Double) -> Bool

#
interval_width

fn interval_width(result : AnalysisResult) -> Double

#
linear_trend

fn linear_trend(values : Array[Double]) -> TrendReport

Calculate an equally-spaced least-squares process trend.

#
mean_absolute_error

fn mean_absolute_error(values : Array[Double], reference : Double) -> Double

Return the average absolute error against a reference.

#
measurement_bias

fn measurement_bias(values : Array[Double], reference : Double) -> BiasReport

Calculate mean bias and maximum absolute error against a reference.

#
measurement_yield

fn measurement_yield(values : Array[Double], window : AcceptanceWindow) -> Double

Return the percentage of measurements inside an interval.

#
monte_carlo_method

fn monte_carlo_method() -> ScenarioMethod

Select seeded Monte Carlo analysis.

#
moving_average

fn moving_average(values : Array[Double], window : Int) -> Array[Double]

Calculate simple trailing moving averages.

#
nearest_rounding

fn nearest_rounding() -> RoundingMode

Select nearest-half-up rounding.

#
negative_direction

fn negative_direction() -> Direction

#
normal_approximation_policy

fn normal_approximation_policy(seed? : UInt) -> SamplingPolicy

#
outlier_indices

fn outlier_indices(values : Array[Double], lower : Double, upper : Double) -> Array[Int]

Return the indices of values outside a closed screening band.

#
position_tolerance

fn position_tolerance(zone : Double) -> GeometricTolerance

Construct a position tolerance zone.

#
process_performance

fn process_performance(values : Array[Double], window : AcceptanceWindow) -> ProcessPerformance

Count accepted, lower-side, and upper-side observations.

#
project_chain

fn project_chain(dimensions : Array[ProjectedDimension]) -> ProjectedResult

#
project_direction

fn project_direction(angle_radians : Double) -> Vector2

#
project_signed

fn project_signed(value : Double, angle_radians : Double) -> Vector2

#
projected_standard_deviation

fn projected_standard_deviation(covariance : Covariance2, direction : Vector2) -> Double

#
proportional_allocation

fn proportional_allocation() -> AllocationStrategy

Create a strategy proportional to each current tolerance.

#
propose_tightening

fn propose_tightening(chain : Chain, target_rss : Double, max_changes : Int) -> Array[TighteningItem]

Recommend the contributors that most efficiently reduce RSS variation.

#
quantile

fn quantile(values : Array[Double], probability : Double) -> Double

#
required_rss_budget

fn required_rss_budget(chain : Chain, window : AcceptanceWindow, coverage_factor : Double) -> Double

Return the maximum RSS standard deviation allowed by a window at a coverage factor.

#
result_to_csv

fn result_to_csv(result : AnalysisResult) -> String

#
round_interval

fn round_interval(value : Interval, decimals : Int) -> Interval

Round an interval outward so it remains conservative.

#
round_statistics

fn round_statistics(statistics : SampleStatistics, decimals : Int) -> SampleStatistics

Round a sample summary while preserving its count and extrema semantics.

#
round_to

fn round_to(value : Double, decimals : Int, mode : RoundingMode) -> Double

Round a value to a fixed number of decimal places.

#
round_values

fn round_values(values : Array[Double], decimals : Int, mode : RoundingMode) -> Array[Double]

Apply reporting rounding to a measurement array without changing its order.

#
rss_budget_is_feasible

fn rss_budget_is_feasible(chain : Chain, window : AcceptanceWindow, standard_deviation : Double, coverage_factor : Double) -> Bool

Return whether a proposed RSS standard deviation meets a window.

#
rss_method

fn rss_method() -> ScenarioMethod

Select root-sum-square analysis.

#
run_acceptance_benchmark_case

fn run_acceptance_benchmark_case(case : BenchmarkCase, samples : Int) -> SimulationSummary

#
run_benchmark_case

fn run_benchmark_case(case : BenchmarkCase, samples : Int) -> AnalysisResult

#
run_scenario

fn run_scenario(spec : ScenarioSpec) -> ScenarioResult

Execute a scenario using its declared method and deterministic inputs.

#
running_statistics

fn running_statistics(values : Array[Double]) -> RunningStatistics

Calculate a mergeable accumulator from all values.

#
runout_tolerance

fn runout_tolerance(zone : Double) -> GeometricTolerance

Construct a circular runout tolerance zone.

#
sample_deviation

fn sample_deviation(policy : SamplingPolicy, unit : Double, tolerance : Double) -> Double

#
sample_deviation_with_state

fn sample_deviation_with_state(policy : SamplingPolicy, state : UInt, tolerance : Double) -> (UInt, Double)

#
sample_plan

fn sample_plan(expected_yield : Double, margin : Double, z_score : Double) -> SamplePlan

Calculate a conservative normal-approximation sample-size plan.

#
sample_sequence

fn sample_sequence(policy : SamplingPolicy, count : Int, tolerance : Double) -> Array[Double]

#
scenario_to_csv

fn scenario_to_csv(result : ScenarioResult) -> String

Serialize a scenario result for downstream comparison reports.

#
sensitivity_allocation

fn sensitivity_allocation() -> AllocationStrategy

Create a strategy that emphasizes contributors with larger variance.

#
sensitivity_items

fn sensitivity_items(result : AnalysisResult) -> Array[SensitivityItem]

#
sensitivity_tolerance_for_budget

fn sensitivity_tolerance_for_budget(chain : Chain, total_rss : Double) -> AllocationReport

Allocate the requested RSS budget according to current tolerance sensitivity.

#
simulation_to_csv

fn simulation_to_csv(summary : SimulationSummary) -> String

#
summarize_samples

fn summarize_samples(values : Array[Double]) -> SampleStatistics

#
tightening_plan

fn tightening_plan(chain : Chain, target_rss : Double) -> TighteningPlan

Return a complete tightening plan, including unchanged contributors.

#
toward_zero_rounding

fn toward_zero_rounding() -> RoundingMode

Select truncation toward zero.

#
triangular_policy

fn triangular_policy(seed? : UInt) -> SamplingPolicy

#
uncertainty_budget

fn uncertainty_budget(sources : Array[UncertaintySource]) -> UncertaintyBudget

Combine independent uncertainty sources by root-sum-square propagation.

#
uncertainty_to_csv

fn uncertainty_to_csv(budget : UncertaintyBudget) -> String

Serialize uncertainty contributions as a stable CSV table.

#
uncertainty_without

fn uncertainty_without(budget : UncertaintyBudget, source_name : String) -> Double

Calculate the reduction in combined uncertainty after removing a source.

#
up_rounding

fn up_rounding() -> RoundingMode

Select upward rounding.

#
validate_chain

fn validate_chain(chain : Chain) -> ValidationReport

Validate a dimension chain without aborting on the first issue.

#
validate_measurements

fn validate_measurements(values : Array[Double], window : AcceptanceWindow) -> ValidationReport

Validate a batch and its acceptance window before inspection.

#
validate_window

fn validate_window(window : AcceptanceWindow) -> ValidationReport

Validate an acceptance window without modifying it.

#
within_control_limits

fn within_control_limits(value : Double, limits : ControlLimits) -> Bool

Return whether an observation remains within control limits.

#
worst_case_method

fn worst_case_method() -> ScenarioMethod

Select worst-case interval analysis.