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
impl BoundaryPolicy
Sourcepub const fn new() -> Self
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.
Sourcepub const fn with_x_below(self, boundary: Boundary) -> Self
pub const fn with_x_below(self, boundary: Boundary) -> Self
Returns this policy with the selection for X below the domain replaced.
Sourcepub const fn with_x_above(self, boundary: Boundary) -> Self
pub const fn with_x_above(self, boundary: Boundary) -> Self
Returns this policy with the selection for X above the domain replaced.
Sourcepub const fn with_y_below(self, boundary: Boundary) -> Self
pub const fn with_y_below(self, boundary: Boundary) -> Self
Returns this policy with the selection for Y below the domain replaced.
Sourcepub const fn with_y_above(self, boundary: Boundary) -> Self
pub const fn with_y_above(self, boundary: Boundary) -> Self
Returns this policy with the selection for Y above the domain replaced.
Sourcepub const fn x_below(&self) -> Boundary
pub const fn x_below(&self) -> Boundary
Returns the selection for an X coordinate below the first X knot.
Examples found in repository?
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}Sourcepub const fn x_above(&self) -> Boundary
pub const fn x_above(&self) -> Boundary
Returns the selection for an X coordinate above the last X knot.
Examples found in repository?
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}Sourcepub const fn y_below(&self) -> Boundary
pub const fn y_below(&self) -> Boundary
Returns the selection for a Y coordinate below the first Y knot.
Examples found in repository?
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}Sourcepub const fn y_above(&self) -> Boundary
pub const fn y_above(&self) -> Boundary
Returns the selection for a Y coordinate above the last Y knot.
Examples found in repository?
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
impl Clone for BoundaryPolicy
Source§fn clone(&self) -> BoundaryPolicy
fn clone(&self) -> BoundaryPolicy
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more