use nalgebra::Vector3;
use crate::crate_utils::define_source;
define_source! {
CuboidMagnet
field_fn: cuboid_B
args: {
polarization:Vector3<T> = Vector3::z(),
dimensions:Vector3<T> = Vector3::from_element(T::one());
validate dimensions.iter().all(|&elem| elem >= T::zero());
error "Dimensions must be non-negative."
}
arg_display: "pol={}, dim={}";
arg_fmt: [format_vector3, format_vector3]
docs: {
new: {
}
}
}
#[cfg(all(test, feature = "std"))]
crate::testing_util::generate_tests! {
CuboidMagnet
filename: cuboid
params: { polarization: vector![1.0, 2.0, 3.0], dimensions: vector![0.1, 0.2, 0.3]}
rtols: {
static: 2e-10,
static_small: 2e-10,
translate: 2e-10,
rotate: 2e-10,
}
p95_rtols: {
static: 2e-10,
static_small: 2e-10,
translate: 2e-10,
rotate: 2e-10,
}
f32_rtols: {
static: 1e-4,
static_small: 2e-4,
translate: 1e-4,
rotate: 1e-4,
}
f32_p95_rtols: {
static: 1e-4,
static_small: 1e-4,
translate: 1e-4,
rotate: 1e-4,
}
}
#[cfg(test)]
mod tests {
use nalgebra::UnitQuaternion;
use crate::magnets::CuboidMagnet;
#[test]
#[should_panic]
fn test_init_validation() {
CuboidMagnet::<f64>::new(
[0.0; 3],
UnitQuaternion::identity(),
[0.0; 3],
[0.0, -1.0, -2.0],
);
}
#[test]
#[should_panic]
fn test_set_dimensions_validation() {
let mut magnet = CuboidMagnet::default();
magnet.set_dimensions([1.0, -1.0, 1.0]);
}
#[test]
#[should_panic]
fn test_with_dimensions_validation() {
let _ = CuboidMagnet::default().with_dimensions([-1.0, 1.0, 1.0]);
}
}