Skip to main content

Scalar

Struct Scalar 

Source
pub struct Scalar {
    pub lo: f64,
    pub hi: f64,
}
Expand description

A number as the kernel computes with it: an interval [lo, hi] of f64 with outward-rounded arithmetic. The default is zero, [0, 0]. A plain value, borrowing nothing: what is worked out in one can be kept as any other value — a drawing’s views, in the session editing it.

Fields§

§lo: f64§hi: f64

Implementations§

Source§

impl Scalar

Source

pub const ZERO: Self

Source

pub const ONE: Self

Source

pub const TWO: Self

Source

pub const PI: Self

Source

pub const INFINITY: Self

Saturation sentinel — set on overflow.

Source

pub const ENTIRE: Self

The “entire” interval (-inf, inf) — the top element of the interval lattice. could_be_equal/could_be_greater/could_be_less against it are always true, and it never satisfies definitely_*. Used to represent a value or a whole curve/surface whose position is not yet known — an unsharp placeholder that automatically passes any overlap/equality check made against it.

Source

pub fn new(lo: f64, hi: f64) -> Self

Create a proper interval. Panics in debug if lo > hi.

Source

pub fn degenerate(v: f64) -> Self

Degenerate (point) interval.

Source

pub fn from_i64(v: i64) -> Self

Source

pub fn from_f64(v: f64) -> Self

Source

pub fn from_ratio(num: i64, den: i64) -> GeopResult<Self>

Source

pub fn to_f64(self) -> f64

Approximate f64 midpoint, (lo + hi) / 2. Used only for rendering/debugging.

Source

pub fn add(self, other: Self) -> Self

Source

pub fn sub(self, other: Self) -> Self

Source

pub fn mul(self, other: Self) -> Self

Source

pub fn neg(self) -> Self

Source

pub fn div(self, other: Self) -> GeopResult<Self>

Fails where the divisor could be zero.

Source

pub fn abs(self) -> Self

Source

pub fn sqrt(self) -> GeopResult<Self>

Source

pub fn sin(self) -> Self

Outward-rounded enclosure of sin over the whole interval (radians). Total — never fails, even for Scalar::ENTIRE or an Scalar::INFINITY-adjacent value, which just widen to [-1, 1].

Source

pub fn cos(self) -> Self

Outward-rounded enclosure of cos (see Scalar::sin).

Source

pub fn acos(self) -> GeopResult<Self>

Outward-rounded enclosure of acos over the interval, in [0, π]: the angle whose cosine it is. The part of the interval beyond [-1, 1] is left out; an interval with nothing in [-1, 1] fails.

Source

pub fn degrees_to_radians(self) -> GeopResult<Self>

The angle self, given in degrees, in radians.

Source

pub fn atan2(self, x: Self) -> Self

An enclosure of the angle of the point (x, self) from the x axis, in radians, in (-pi, pi]: of atan2(y, x) for every y in self and x in x. All of [-pi, pi] where that is not one range of angles: the box (x, self) holds the origin, or reaches across the negative x axis, where the angle jumps.

Over a box clear of the origin the angle is least and greatest at corners. Those are taken in f64 — free choices of where to put the bounds — and then each is proven, not trusted: a bound b holds when every point of the box lies on the far side of the ray at angle b, cos(b) y - sin(b) x definitely of the right sign, evaluated in the scalar’s own outward-rounded arithmetic. Where rounding leaves that undecided the bound moves outward, by steps that double, until it holds.

Source

pub fn could_be_equal(self, other: Self) -> bool

Source

pub fn definitely_not_equal(self, other: Self) -> bool

Source

pub fn could_be_greater(self, other: Self) -> bool

Source

pub fn definitely_greater(self, other: Self) -> bool

Source

pub fn could_be_less(self, other: Self) -> bool

Source

pub fn definitely_less(self, other: Self) -> bool

Source

pub fn is_zero(self) -> bool

Whether it is definitely zero — no value it could be is less or more than zero: an exact zero, such as the entry of a column a row has nothing in.

Source

pub fn definite_sign(self) -> Option<bool>

The sign it definitely has: Some(true) if it is definitely positive, Some(false) if definitely negative, None where it could be zero.

Source

pub fn is_infinite(self) -> bool

Source

pub fn is_finite(self) -> bool

Source

pub fn midpoint(self) -> Self

Source

pub fn is_sharp(self) -> bool

True iff this value carries no width — it’s a single, exactly-known point, not a genuine range of possibility.

Source

pub fn width(self) -> Self

How much possibility this enclosure carries: hi - lo, as a sharp, non-negative value. Zero exactly when Scalar::is_sharp.

This is how much a computed quantity is not known. Being sharp itself is what makes it usable as a threshold — comparing an uncertain width against an uncertain bound could never be decided three-valuedly (see validation::numerical_accuracy).

Source

pub fn lower(self) -> Self

The sharp lower endpoint of this enclosure. Every value self could be is >= lower() and <= upper(), so these are the outer bounds to cut at when a search restricts a domain to an enclosure of its answer: a cut there never loses a solution (unlike Scalar::sharpen, which would cut through the enclosure).

Source

pub fn upper(self) -> Self

The sharp upper endpoint (see Scalar::lower).

Source

pub fn sharpen(self) -> Self

Collapse to a single representative point (currently the midpoint, like Scalar::midpoint, but named for its distinct purpose: use this only when you are free to pick any value within self and don’t need to preserve which one — e.g. choosing where to place a new knot when subdividing a curve at an arbitrary interior point. Never use this to compress a value that represents a genuinely uncertain physical quantity (a search’s converged bound, a measured position) — that would silently discard real uncertainty rather than making an arbitrary, harmless choice.

Exists to break a specific class of interval blowup: repeatedly re-deriving a split point as (t0 + t1) / 2 from an already-widened domain propagates and compounds that width forever, even though nothing downstream actually cares which interior point was chosen — only that some valid one was. Sharpening throws that unneeded width away at the source instead of letting every later alpha = (t - e) / (s - e) division amplify it further.

Source

pub fn fraction(lo: Self, hi: Self, f: Self) -> Self

The point a fraction f of the way from lo to hi, sharp: a sample position, a free choice (see Scalar::sharpen) — not an enclosure of the point there, which Scalar::interpolate is.

Source

pub fn interpolate(a: Self, b: Self, alpha: Self) -> Self

Point a fraction alpha of the way from a to b: a at alpha=0, b at alpha=1.

Deliberately a.add(alpha.mul(b.sub(a))), not the equally-valid a.mul(Scalar::ONE.sub(alpha)).add(b.mul(alpha)) — both give the same exact real result, but the latter computes alpha and 1-alpha as two decorrelated intervals before ever relating a and b, so interval arithmetic can’t recognize when they cancel. This form computes b.sub(a) first: when a and b are honestly the same value (e.g. a weight that should stay exactly 1.0 across many subdivisions), that subtraction is exactly 0 regardless of alpha’s own width, and the whole expression collapses to exactly a instead of needlessly widening with every call.

Source

pub fn intersect(self, other: Self) -> Self

The largest value contained in both self and other — the dual of Scalar::union. Callers must only intersect two enclosures of the same underlying exact value (as Scalar::interpolate does); given that, the result is still an honest enclosure, just a tighter one. Returns the narrower input if the two somehow don’t overlap, rather than fabricating an empty/inverted interval.

Source

pub fn union(self, other: Self) -> Self

The smallest value definitely containing both self and other — the scalar-level analog of Set::union.

Source

pub fn is_subset_of(self, other: Self) -> bool

True iff self is contained in other as sets: other.lo <= self.lo and self.hi <= other.hi. This is the rigorous existence/uniqueness test a Krawczyk-style contraction relies on (K(X) ⊆ X) — distinct from Scalar::could_be_equal, which only asks whether the two enclosures overlap.

Source

pub fn is_exactly(self, other: Self) -> bool

Whether it is exactly other, as a set: both the same single value, or both the same range. A weight that is exactly one is skipped rather than multiplied by, since the product would only be widened by rounding.

Source

pub fn max(self, other: Self) -> Self

The larger of the two: an enclosure of max(a, b) for every a and b the two could be — sharp where both are.

Source

pub fn min(self, other: Self) -> Self

The smaller of the two (see Scalar::max).

Source

pub fn clamped(self, lo: Self, hi: Self) -> Self

Clamped into [lo, hi]: moved to a bound only where it is definitely beyond it, else left as it is.

Trait Implementations§

Source§

impl Bisect for Scalar

Sharp: which point is asked is the search’s own free choice, and a sharp middle keeps the bracket from widening as it shrinks.

Source§

fn strictly_between(lo: Self, mid: Self, hi: Self) -> bool

For lo below hi.

Source§

fn middle(lo: Self, hi: Self) -> GeopResult<Self>

The middle of lo and hi: where the next side is asked.
Source§

impl Clone for Scalar

Source§

fn clone(&self) -> Scalar

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for Scalar

Source§

impl Debug for Scalar

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Scalar

Source§

fn default() -> Scalar

Returns the “default value” for a type. Read more
Source§

impl Display for Scalar

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Exact for Scalar

A sharp scalar as its number, any other as [lo, hi]. Sharp to the bit: [-0, 0] is not sharp, and is written as both.

Source§

fn write<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error>

Source§

fn read<'de, D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>

Source§

impl Iterate for Scalar

Source§

fn same(&self, other: &Self) -> bool

Whether self and other are the same value — the same enclosure, not merely overlapping ones.
Source§

impl Mergeable for Scalar

Source§

fn could_be_equal(&self, other: &Self) -> bool

Source§

fn union(&self, other: &Self) -> Self

Source§

impl Newton1d for Scalar

Sharpened before clamping: clamped’s comparisons are exact on a sharp value, so the seed stays in the domain.

Source§

fn could_be_zero(self) -> bool

Whether self, a function’s value, could be zero.
Source§

fn step(value: Self, slope: Self) -> GeopResult<(Self, f64)>

The Newton step value / slope and its size, or why there is none.
Source§

fn settle(self, step: Self, lo: Self, hi: Self) -> Self

self - step, as the seed of the next step: clamped into (lo, hi), and sharp — it is a free choice.
Source§

impl Number for Scalar

Source§

const ZERO: Self = Scalar::ZERO

Source§

const ONE: Self = Scalar::ONE

Source§

const TWO: Self = Scalar::TWO

Source§

const PI: Self = Scalar::PI

Source§

fn from_i64(v: i64) -> Self

Source§

fn from_f64(v: f64) -> Self

Source§

fn from_scalar(s: Scalar) -> Self

The scalar s as a constant: depending on no variable.
Source§

fn from_ratio(num: i64, den: i64) -> GeopResult<Self>

Source§

fn to_f64(self) -> f64

The value’s midpoint, for rendering and debugging.
Source§

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

Source§

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

Source§

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

Source§

fn neg(self) -> Self

Source§

fn div(self, other: Self) -> GeopResult<Self>

Fails where the divisor could be zero.
Source§

fn abs(self) -> Self

Source§

fn sqrt(self) -> GeopResult<Self>

Source§

fn sin(self) -> Self

Source§

fn cos(self) -> Self

Source§

fn acos(self) -> GeopResult<Self>

Source§

fn degrees_to_radians(self) -> GeopResult<Self>

The angle self, given in degrees, in radians.
Source§

fn could_be_equal(self, other: Self) -> bool

Source§

fn definitely_not_equal(self, other: Self) -> bool

Source§

fn could_be_greater(self, other: Self) -> bool

Source§

fn definitely_greater(self, other: Self) -> bool

Source§

fn could_be_less(self, other: Self) -> bool

Source§

fn definitely_less(self, other: Self) -> bool

Source§

fn is_sharp(self) -> bool

Whether it is a single, exactly known point: a value that depends on no variable, and carries no width.
Source§

fn is_exactly(self, other: Self) -> bool

Whether its value is exactly other’s, as a set (see Scalar::is_exactly).
Source§

fn union(self, other: Self) -> Self

The smallest value containing both (see Scalar::union).
Source§

impl PartialEq for Scalar

Source§

fn eq(&self, other: &Scalar) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Scalar

Source§

impl Variable for Scalar

A number steps by what is added to it.

Source§

fn dimension(&self) -> usize

How many numbers a step of it takes. None, for a value no solve moves.
Source§

fn retract(&self, step: &[Scalar]) -> GeopResult<Scalar>

Where step — Variable::dimension numbers — takes it: the value a solver tries next, a free choice, so sharp.
Source§

fn retract_over(&self, step: &[Scalar]) -> GeopResult<Scalar>

Every value a step in the box step takes it to: an enclosure, nothing sharpened — of the value it stands for, which a sharp value may only approximate (a rotation’s unit quaternion).
Source§

fn differential(&self, step: &[Scalar]) -> GeopResult<Option<Vec<Vec<Scalar>>>>

The differential of the retraction over the box step: the matrix D, one row per number of a step, such that for every δ in the box a step dδ further, retract(δ + dδ), is to first order the step D dδ from retract(δ) — an enclosure for every δ in the box. None for the identity: a step that adds to the value.
Source§

fn stay(&self, at: &Scalar, _: Scalar) -> GeopResult<Rows>

What keeps it near at where nothing else decides where it goes: residuals that vanish there, each a length — a turn measured where it moves a point scale from its axis — and their derivatives by its step.
Source§

fn same(&self, other: &Scalar) -> bool

Whether it is no different from other: a step that changed nothing.
Source§

fn carried(&self, from: &Self, to: &Self) -> Option<Self>

Where it goes carried along by leader moving from from to to, as if fastened to it — a seed for a solve of what hangs off the leader (see Structure), a free choice, so sharp. None for a value nothing carries: a number.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.