use ph_surfaces::{BilinearSurface, Boundary, BoundaryPolicy, SurfaceError};
static X: [u16; 2] = [100, 200];
static Y: [u16; 2] = [10, 30];
static VALUES: [[i32; 2]; 2] = [
[0, 100], [40, 180], ];
static STRICT: BilinearSurface<2, 2> = BilinearSurface::new(&X, &Y, &VALUES);
static FAIL_SAFE: BilinearSurface<2, 2> = BilinearSurface::new(&X, &Y, &VALUES).with_policy(
BoundaryPolicy::new()
.with_x_below(Boundary::Error)
.with_x_above(Boundary::Clamp)
.with_y_below(Boundary::Error)
.with_y_above(Boundary::Clamp),
);
fn main() {
assert_eq!(FAIL_SAFE.policy().x_below(), Boundary::Error);
assert_eq!(FAIL_SAFE.policy().x_above(), Boundary::Clamp);
assert_eq!(FAIL_SAFE.policy().y_below(), Boundary::Error);
assert_eq!(FAIL_SAFE.policy().y_above(), Boundary::Clamp);
assert_eq!(FAIL_SAFE.evaluate(125, 20), Ok(50));
assert_eq!(FAIL_SAFE.evaluate(125, 20), STRICT.evaluate(125, 20));
assert_eq!(
FAIL_SAFE.evaluate(0, 20),
Err(SurfaceError::XBelow {
coordinate: 0,
bound: 100
})
);
assert_eq!(
FAIL_SAFE.evaluate(125, 0),
Err(SurfaceError::YBelow {
coordinate: 0,
bound: 10
})
);
assert_eq!(FAIL_SAFE.evaluate(4_000, 20), FAIL_SAFE.evaluate(200, 20));
assert_eq!(FAIL_SAFE.evaluate(125, 4_000), FAIL_SAFE.evaluate(125, 30));
assert_eq!(FAIL_SAFE.evaluate(4_000, 20), Ok(140));
assert_eq!(FAIL_SAFE.evaluate(125, 4_000), Ok(75));
assert_eq!(
STRICT.evaluate(0, 0),
Err(SurfaceError::XBelow {
coordinate: 0,
bound: 100
})
);
assert_eq!(
FAIL_SAFE.evaluate(4_000, 0),
Err(SurfaceError::YBelow {
coordinate: 0,
bound: 10
})
);
}