Expand description
Exact geometric predicates for f64 input.
orient2d, incircle, orient3d and insphere return the sign
of their determinant exactly, for every finite input: any magnitudes,
subnormals and exactly degenerate configurations included. A NaN or
infinite coordinate returns NonFinite rather than a plausible-looking
Sign.
use arithmetica::{Sign, orient2d};
assert_eq!(orient2d([0.0, 0.0], [1.0, 0.0], [0.0, 1.0]), Ok(Sign::Positive));
assert_eq!(orient2d([0.0, 0.0], [1.0, 1.0], [2.0, 2.0]), Ok(Sign::Zero));
assert!(orient2d([f64::NAN, 0.0], [1.0, 0.0], [0.0, 1.0]).is_err());§Contents
- Predicates:
orient2d,incircle,orient3d,insphere. - Exact 2D constructions:
RationalCoord2d, built fromf64input or as the exact intersection of two lines, with the exact predicatesrational_coords_equal,rational_compare_alongandorient2d_rational.RationalCoord2d::f64_bracketreports the twof64neighbors of an exact coordinate and its exact position between them; no function in the crate returns an approximation of a value. - Expansion arithmetic: the error-free primitives in
expansion, exact under the conditions their documentation states. - Stage counters:
counters, behind thestage-countersfeature.
§How the predicates stay exact
Each predicate is a ladder of stages, and each stage either certifies a sign or passes the input on:
- a filter in native
f64with the underflow-protected error bound of Bartels, Fisikopoulos and Weiser (2023), valid for every finite input; - Shewchuk’s adaptive expansion stages, run only inside an exactness window of magnitudes where binary64 provably behaves as his unbounded-exponent model, with input moved there by an exact power-of-two rescale when possible;
- exact fixed-width integer arithmetic for everything else.
The README and docs/exactness_window.md in the repository give the full
argument and the references.
Re-exports§
pub use rational::RationalCoord2d;pub use rational::orient2d_rational;pub use rational::rational_compare_along;pub use rational::rational_coords_equal;
Modules§
- counters
- Optional counters recording how often each predicate reaches its exact fallback.
- expansion
- Low-level floating-point expansion arithmetic primitives.
- rational
- Exact predicates over constructed points.
Structs§
- F64Bracket
- The two representable
f64values that bracket an exact value, and the value’s exact position between them. - NonFinite
- Error returned by a geometric predicate when an input coordinate is not
finite (NaN,
+∞, or−∞).
Enums§
- Bracket
Position - Where an exact value sits relative to its two nearest representable
f64neighbors. - Sign
- All predicates in this crate return
Signrather thanf64orbool. The three variants correspond to the three mathematically distinct outcomes of a predicate determinant.
Functions§
- incircle
- Tests whether point
pdlies inside the circumcircle of trianglepa,pb,pc. - insphere
- Tests whether
pelies inside the circumsphere ofpa,pb,pc,pd. - orient2d
- Tests the orientation of the triangle formed by
pa,pb, andpc. - orient3d
- Tests the orientation of the tetrahedron formed by four 3D points.