Skip to main content

bearing

Macro bearing 

Source
macro_rules! bearing {
    (azimuth = deg($az:expr), elevation = deg($el:expr) $(,)?) => { ... };
    (azimuth = rad($az:expr), elevation = rad($el:expr) $(,)?) => { ... };
    (azimuth = deg($az:expr), elevation = deg($el:expr); in $system:ty) => { ... };
    (azimuth = rad($az:expr), elevation = rad($el:expr); in $system:ty) => { ... };
}
Expand description

Constructs a Bearing with compile-time validated angles using unit suffixes.

This macro provides a safe way to construct bearings with compile-time known angles, eliminating the need for .expect() calls on the elevation validation.

§Supported Units

  • deg - degrees
  • rad - radians

§Examples

use sguaba::{bearing, system};

system!(struct PlaneFrd using FRD);

// Using degrees with explicit coordinate system
let bearing1 = bearing!(azimuth = deg(20.0), elevation = deg(10.0); in PlaneFrd);

// Using degrees with inferred coordinate system (requires type annotation)
let bearing2: sguaba::Bearing<PlaneFrd> = bearing!(azimuth = deg(20.0), elevation = deg(10.0));

// Using radians
let bearing3 = bearing!(azimuth = rad(0.349), elevation = rad(0.175); in PlaneFrd);

§Compile-time validation

The following examples should fail to compile because elevation is out of range:

// Elevation > 90° should fail
let bearing = bearing!(azimuth = deg(0.0), elevation = deg(91.0); in PlaneFrd);
// Elevation < -90° should fail
let bearing = bearing!(azimuth = deg(0.0), elevation = deg(-91.0); in PlaneFrd);
// Elevation > π/2 radians should fail
let bearing = bearing!(azimuth = rad(0.0), elevation = rad(1.58); in PlaneFrd);
// Elevation < -π/2 radians should fail
let bearing = bearing!(azimuth = rad(0.0), elevation = rad(-1.58); in PlaneFrd);