macro_rules! vector {
($x:tt = $xx:expr, $y:tt = $yy:expr, $z:tt = $zz:expr $(,)?) => { ... };
(n = $n:expr, e = $e:expr, d = $d:expr; in $in:ty) => { ... };
(e = $e:expr, n = $n:expr, u = $u:expr; in $in:ty) => { ... };
(f = $f:expr, r = $r:expr, d = $d:expr; in $in:ty) => { ... };
(x = $x:expr, y = $y:expr, z = $z:expr; in $in:ty) => { ... };
}Expand description
Quickly construct a Vector using named components.
This macro allows constructing Vectors for a coordinate system by naming the arguments
according to its CoordinateSystem::Convention. Using the wrong named arguments (eg, trying
to make a NedLike Vector using f = ) will produce an error at compile-time.
For NedLike, use:
vector! {
n = Length::new::<meter>(1.),
e = Length::new::<meter>(2.),
d = Length::new::<meter>(3.),
}For FrdLike, use:
vector! {
f = Length::new::<meter>(1.),
r = Length::new::<meter>(2.),
d = Length::new::<meter>(3.),
}For RightHandedXyzLike, use:
vector! {
x = Length::new::<meter>(1.),
y = Length::new::<meter>(2.),
z = Length::new::<meter>(3.),
}The macro also allows explicitly specifying the coordinate system In for the returned
Vector (which is otherwise inferred) by suffixing the component list with ; in System,
like so:
system!(struct Frd using FRD);
vector! {
f = Length::new::<meter>(1.),
r = Length::new::<meter>(2.),
d = Length::new::<meter>(3.);
in Frd
}The macro automatically determines the vector unit type based on the units provided:
// Creates Vector<PlaneFrd, Z0> / LengthVector (length vector)
let position = vector!(
f = Length::new::<meter>(1.0),
r = Length::new::<meter>(0.0),
d = Length::new::<meter>(0.0);
in PlaneFrd
);
// Creates Vector<PlaneFrd, N1> / VelocityVector (velocity vector)
let velocity = vector!(
f = Velocity::new::<meter_per_second>(5.0),
r = Velocity::new::<meter_per_second>(0.0),
d = Velocity::new::<meter_per_second>(0.0);
in PlaneFrd
);
// Creates Vector<PlaneFrd, N2> / AccelerationVector (acceleration vector)
let acceleration = vector!(
f = Acceleration::new::<meter_per_second_squared>(2.0),
r = Acceleration::new::<meter_per_second_squared>(0.0),
d = Acceleration::new::<meter_per_second_squared>(0.0);
in PlaneFrd
);