Skip to main content

Crate affn

Crate affn 

Source
Expand description

§affn - Affine Geometry Primitives

This crate provides strongly-typed coordinate systems with compile-time safety for scientific computing applications. It defines the mathematical foundation for working with positions, directions, and displacements in various reference frames.

§Domain-Agnostic Design

affn is a pure geometry kernel that contains no domain-specific vocabulary. Concrete frame and center types (e.g., astronomical frames, robotic frames) should be defined in downstream crates that depend on affn.

§Core Concepts

§Reference Centers

A ReferenceCenter defines the origin point of a coordinate system. Some centers require runtime parameters (stored in ReferenceCenter::Params).

§Reference Frames

A ReferenceFrame defines the orientation of coordinate axes.

§Coordinate Types

  • Position: An affine point in space (center + frame + distance)
  • Direction: A unit vector representing orientation (frame only)
  • Displacement/Velocity: Free vectors (frame + magnitude)

§Creating Custom Frames and Centers

Use derive macros for convenient definitions:

use affn::prelude::*;

#[derive(Debug, Copy, Clone, ReferenceFrame)]
struct MyFrame;

#[derive(Debug, Copy, Clone, ReferenceCenter)]
struct MyCenter;

assert_eq!(MyFrame::frame_name(), "MyFrame");
assert_eq!(MyCenter::center_name(), "MyCenter");

§Algebraic Rules

The type system enforces mathematical correctness:

OperationResultMeaning
Position - PositionDisplacementDisplacement between points
Position + DisplacementPositionTranslate point
Displacement + DisplacementDisplacementAdd displacements
Direction * LengthDisplacementScale direction
normalize(Displacement)DirectionExtract orientation

§Example

use affn::cartesian::{Position, Displacement};
use affn::frames::ReferenceFrame;
use affn::centers::ReferenceCenter;
use qtty::*;

// Define domain-specific types
#[derive(Debug, Copy, Clone)]
struct WorldFrame;
impl ReferenceFrame for WorldFrame {
    fn frame_name() -> &'static str { "WorldFrame" }
}

#[derive(Debug, Copy, Clone)]
struct WorldOrigin;
impl ReferenceCenter for WorldOrigin {
    type Params = ();
    fn center_name() -> &'static str { "WorldOrigin" }
}

let a = Position::<WorldOrigin, WorldFrame, Kilometer>::new(100.0, 200.0, 300.0);
let b = Position::<WorldOrigin, WorldFrame, Kilometer>::new(150.0, 250.0, 350.0);

// Positions subtract to give displacements
let displacement: Displacement<WorldFrame, Kilometer> = b - a;

Re-exports§

pub use centers::AffineCenter;
pub use centers::NoCenter;
pub use centers::ReferenceCenter;
pub use frames::ReferenceFrame;
pub use ops::Isometry3;
pub use ops::Rotation3;
pub use ops::Translation3;
pub use cartesian::CenterParamsMismatchError;
pub use cartesian::Direction as CartesianDirection;
pub use cartesian::Displacement;
pub use cartesian::Position;
pub use cartesian::Vector;
pub use cartesian::Velocity;
pub use spherical::Direction as SphericalDirection;
pub use spherical::Position as SphericalPosition;
pub use ellipsoidal::Position as EllipsoidalPosition;

Modules§

cartesian
Cartesian Coordinates Module
centers
Reference Centers Module
ellipsoid
Ellipsoid Module
ellipsoidal
Ellipsoidal coordinate types.
frames
Reference Frames Module
ops
Affine Operators Module
prelude
Prelude module for convenient imports.
spherical
Spherical coordinate types.

Derive Macros§

DeriveReferenceCenter
Derive macro for implementing ReferenceCenter.
DeriveReferenceFrame
Derive macro for implementing ReferenceFrame.