Skip to main content

BoundaryPolicy

Struct BoundaryPolicy 

Source
pub struct BoundaryPolicy { /* private fields */ }
Expand description

The four independent Boundary selections of one surface.

Every side defaults to Boundary::Error, so a surface rejects out-of-domain coordinates unless the definition opts into clamping. The four sides are named rather than positional: there is no tuple of booleans to memorise the order of.

§Examples

use ph_surfaces::{Boundary, BoundaryPolicy};

const POLICY: BoundaryPolicy = BoundaryPolicy::new()
    .with_x_below(Boundary::Clamp)
    .with_y_above(Boundary::Clamp);

assert_eq!(POLICY.x_below(), Boundary::Clamp);
assert_eq!(POLICY.x_above(), Boundary::Error);
assert_eq!(POLICY.y_below(), Boundary::Error);
assert_eq!(POLICY.y_above(), Boundary::Clamp);

Implementations§

Source§

impl BoundaryPolicy

Source

pub const fn new() -> Self

Returns the policy that rejects every out-of-domain coordinate.

This is the same value as BoundaryPolicy::default, but it is usable in a constant or static definition.

Examples found in repository?
examples/fail_safe_boundaries.rs (line 25)
24static FAIL_SAFE: BilinearSurface<2, 2> = BilinearSurface::new(&X, &Y, &VALUES).with_policy(
25    BoundaryPolicy::new()
26        .with_x_below(Boundary::Error)
27        .with_x_above(Boundary::Clamp)
28        .with_y_below(Boundary::Error)
29        .with_y_above(Boundary::Clamp),
30);
Source

pub const fn with_x_below(self, boundary: Boundary) -> Self

Returns this policy with the selection for X below the domain replaced.

Examples found in repository?
examples/fail_safe_boundaries.rs (line 26)
24static FAIL_SAFE: BilinearSurface<2, 2> = BilinearSurface::new(&X, &Y, &VALUES).with_policy(
25    BoundaryPolicy::new()
26        .with_x_below(Boundary::Error)
27        .with_x_above(Boundary::Clamp)
28        .with_y_below(Boundary::Error)
29        .with_y_above(Boundary::Clamp),
30);
Source

pub const fn with_x_above(self, boundary: Boundary) -> Self

Returns this policy with the selection for X above the domain replaced.

Examples found in repository?
examples/fail_safe_boundaries.rs (line 27)
24static FAIL_SAFE: BilinearSurface<2, 2> = BilinearSurface::new(&X, &Y, &VALUES).with_policy(
25    BoundaryPolicy::new()
26        .with_x_below(Boundary::Error)
27        .with_x_above(Boundary::Clamp)
28        .with_y_below(Boundary::Error)
29        .with_y_above(Boundary::Clamp),
30);
Source

pub const fn with_y_below(self, boundary: Boundary) -> Self

Returns this policy with the selection for Y below the domain replaced.

Examples found in repository?
examples/fail_safe_boundaries.rs (line 28)
24static FAIL_SAFE: BilinearSurface<2, 2> = BilinearSurface::new(&X, &Y, &VALUES).with_policy(
25    BoundaryPolicy::new()
26        .with_x_below(Boundary::Error)
27        .with_x_above(Boundary::Clamp)
28        .with_y_below(Boundary::Error)
29        .with_y_above(Boundary::Clamp),
30);
Source

pub const fn with_y_above(self, boundary: Boundary) -> Self

Returns this policy with the selection for Y above the domain replaced.

Examples found in repository?
examples/fail_safe_boundaries.rs (line 29)
24static FAIL_SAFE: BilinearSurface<2, 2> = BilinearSurface::new(&X, &Y, &VALUES).with_policy(
25    BoundaryPolicy::new()
26        .with_x_below(Boundary::Error)
27        .with_x_above(Boundary::Clamp)
28        .with_y_below(Boundary::Error)
29        .with_y_above(Boundary::Clamp),
30);
Source

pub const fn x_below(&self) -> Boundary

Returns the selection for an X coordinate below the first X knot.

Examples found in repository?
examples/fail_safe_boundaries.rs (line 33)
32fn main() {
33    assert_eq!(FAIL_SAFE.policy().x_below(), Boundary::Error);
34    assert_eq!(FAIL_SAFE.policy().x_above(), Boundary::Clamp);
35    assert_eq!(FAIL_SAFE.policy().y_below(), Boundary::Error);
36    assert_eq!(FAIL_SAFE.policy().y_above(), Boundary::Clamp);
37
38    // In-domain: policy is idle.
39    assert_eq!(FAIL_SAFE.evaluate(125, 20), Ok(50));
40    assert_eq!(FAIL_SAFE.evaluate(125, 20), STRICT.evaluate(125, 20));
41
42    // Reject uncharacterized low codes.
43    assert_eq!(
44        FAIL_SAFE.evaluate(0, 20),
45        Err(SurfaceError::XBelow {
46            coordinate: 0,
47            bound: 100
48        })
49    );
50    assert_eq!(
51        FAIL_SAFE.evaluate(125, 0),
52        Err(SurfaceError::YBelow {
53            coordinate: 0,
54            bound: 10
55        })
56    );
57
58    // Hold the last characterized high edge; nothing is extrapolated.
59    assert_eq!(FAIL_SAFE.evaluate(4_000, 20), FAIL_SAFE.evaluate(200, 20));
60    assert_eq!(FAIL_SAFE.evaluate(125, 4_000), FAIL_SAFE.evaluate(125, 30));
61    assert_eq!(FAIL_SAFE.evaluate(4_000, 20), Ok(140));
62    assert_eq!(FAIL_SAFE.evaluate(125, 4_000), Ok(75));
63
64    // Both outside Error sides: X wins and Y is not reported.
65    assert_eq!(
66        STRICT.evaluate(0, 0),
67        Err(SurfaceError::XBelow {
68            coordinate: 0,
69            bound: 100
70        })
71    );
72    // X clamps, Y still errors.
73    assert_eq!(
74        FAIL_SAFE.evaluate(4_000, 0),
75        Err(SurfaceError::YBelow {
76            coordinate: 0,
77            bound: 10
78        })
79    );
80}
Source

pub const fn x_above(&self) -> Boundary

Returns the selection for an X coordinate above the last X knot.

Examples found in repository?
examples/fail_safe_boundaries.rs (line 34)
32fn main() {
33    assert_eq!(FAIL_SAFE.policy().x_below(), Boundary::Error);
34    assert_eq!(FAIL_SAFE.policy().x_above(), Boundary::Clamp);
35    assert_eq!(FAIL_SAFE.policy().y_below(), Boundary::Error);
36    assert_eq!(FAIL_SAFE.policy().y_above(), Boundary::Clamp);
37
38    // In-domain: policy is idle.
39    assert_eq!(FAIL_SAFE.evaluate(125, 20), Ok(50));
40    assert_eq!(FAIL_SAFE.evaluate(125, 20), STRICT.evaluate(125, 20));
41
42    // Reject uncharacterized low codes.
43    assert_eq!(
44        FAIL_SAFE.evaluate(0, 20),
45        Err(SurfaceError::XBelow {
46            coordinate: 0,
47            bound: 100
48        })
49    );
50    assert_eq!(
51        FAIL_SAFE.evaluate(125, 0),
52        Err(SurfaceError::YBelow {
53            coordinate: 0,
54            bound: 10
55        })
56    );
57
58    // Hold the last characterized high edge; nothing is extrapolated.
59    assert_eq!(FAIL_SAFE.evaluate(4_000, 20), FAIL_SAFE.evaluate(200, 20));
60    assert_eq!(FAIL_SAFE.evaluate(125, 4_000), FAIL_SAFE.evaluate(125, 30));
61    assert_eq!(FAIL_SAFE.evaluate(4_000, 20), Ok(140));
62    assert_eq!(FAIL_SAFE.evaluate(125, 4_000), Ok(75));
63
64    // Both outside Error sides: X wins and Y is not reported.
65    assert_eq!(
66        STRICT.evaluate(0, 0),
67        Err(SurfaceError::XBelow {
68            coordinate: 0,
69            bound: 100
70        })
71    );
72    // X clamps, Y still errors.
73    assert_eq!(
74        FAIL_SAFE.evaluate(4_000, 0),
75        Err(SurfaceError::YBelow {
76            coordinate: 0,
77            bound: 10
78        })
79    );
80}
Source

pub const fn y_below(&self) -> Boundary

Returns the selection for a Y coordinate below the first Y knot.

Examples found in repository?
examples/fail_safe_boundaries.rs (line 35)
32fn main() {
33    assert_eq!(FAIL_SAFE.policy().x_below(), Boundary::Error);
34    assert_eq!(FAIL_SAFE.policy().x_above(), Boundary::Clamp);
35    assert_eq!(FAIL_SAFE.policy().y_below(), Boundary::Error);
36    assert_eq!(FAIL_SAFE.policy().y_above(), Boundary::Clamp);
37
38    // In-domain: policy is idle.
39    assert_eq!(FAIL_SAFE.evaluate(125, 20), Ok(50));
40    assert_eq!(FAIL_SAFE.evaluate(125, 20), STRICT.evaluate(125, 20));
41
42    // Reject uncharacterized low codes.
43    assert_eq!(
44        FAIL_SAFE.evaluate(0, 20),
45        Err(SurfaceError::XBelow {
46            coordinate: 0,
47            bound: 100
48        })
49    );
50    assert_eq!(
51        FAIL_SAFE.evaluate(125, 0),
52        Err(SurfaceError::YBelow {
53            coordinate: 0,
54            bound: 10
55        })
56    );
57
58    // Hold the last characterized high edge; nothing is extrapolated.
59    assert_eq!(FAIL_SAFE.evaluate(4_000, 20), FAIL_SAFE.evaluate(200, 20));
60    assert_eq!(FAIL_SAFE.evaluate(125, 4_000), FAIL_SAFE.evaluate(125, 30));
61    assert_eq!(FAIL_SAFE.evaluate(4_000, 20), Ok(140));
62    assert_eq!(FAIL_SAFE.evaluate(125, 4_000), Ok(75));
63
64    // Both outside Error sides: X wins and Y is not reported.
65    assert_eq!(
66        STRICT.evaluate(0, 0),
67        Err(SurfaceError::XBelow {
68            coordinate: 0,
69            bound: 100
70        })
71    );
72    // X clamps, Y still errors.
73    assert_eq!(
74        FAIL_SAFE.evaluate(4_000, 0),
75        Err(SurfaceError::YBelow {
76            coordinate: 0,
77            bound: 10
78        })
79    );
80}
Source

pub const fn y_above(&self) -> Boundary

Returns the selection for a Y coordinate above the last Y knot.

Examples found in repository?
examples/fail_safe_boundaries.rs (line 36)
32fn main() {
33    assert_eq!(FAIL_SAFE.policy().x_below(), Boundary::Error);
34    assert_eq!(FAIL_SAFE.policy().x_above(), Boundary::Clamp);
35    assert_eq!(FAIL_SAFE.policy().y_below(), Boundary::Error);
36    assert_eq!(FAIL_SAFE.policy().y_above(), Boundary::Clamp);
37
38    // In-domain: policy is idle.
39    assert_eq!(FAIL_SAFE.evaluate(125, 20), Ok(50));
40    assert_eq!(FAIL_SAFE.evaluate(125, 20), STRICT.evaluate(125, 20));
41
42    // Reject uncharacterized low codes.
43    assert_eq!(
44        FAIL_SAFE.evaluate(0, 20),
45        Err(SurfaceError::XBelow {
46            coordinate: 0,
47            bound: 100
48        })
49    );
50    assert_eq!(
51        FAIL_SAFE.evaluate(125, 0),
52        Err(SurfaceError::YBelow {
53            coordinate: 0,
54            bound: 10
55        })
56    );
57
58    // Hold the last characterized high edge; nothing is extrapolated.
59    assert_eq!(FAIL_SAFE.evaluate(4_000, 20), FAIL_SAFE.evaluate(200, 20));
60    assert_eq!(FAIL_SAFE.evaluate(125, 4_000), FAIL_SAFE.evaluate(125, 30));
61    assert_eq!(FAIL_SAFE.evaluate(4_000, 20), Ok(140));
62    assert_eq!(FAIL_SAFE.evaluate(125, 4_000), Ok(75));
63
64    // Both outside Error sides: X wins and Y is not reported.
65    assert_eq!(
66        STRICT.evaluate(0, 0),
67        Err(SurfaceError::XBelow {
68            coordinate: 0,
69            bound: 100
70        })
71    );
72    // X clamps, Y still errors.
73    assert_eq!(
74        FAIL_SAFE.evaluate(4_000, 0),
75        Err(SurfaceError::YBelow {
76            coordinate: 0,
77            bound: 10
78        })
79    );
80}

Trait Implementations§

Source§

impl Clone for BoundaryPolicy

Source§

fn clone(&self) -> BoundaryPolicy

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 BoundaryPolicy

Source§

impl Debug for BoundaryPolicy

Source§

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

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

impl Default for BoundaryPolicy

Source§

fn default() -> BoundaryPolicy

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

impl Eq for BoundaryPolicy

Source§

impl Hash for BoundaryPolicy

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for BoundaryPolicy

Source§

fn eq(&self, other: &BoundaryPolicy) -> 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 BoundaryPolicy

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, 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.