Skip to content
0:00 / 0:00

#rust#sguaba#spatialmath

Sguaba: Type-safe spatial math in Rust

Jon Gjengset

111K subscribers • 38 videos on Hallway

YouTube

Advanced. Deep dive for people who know the field.

22K views1 year ago3 recommendations

Programming languagesComputer scienceRustMath for programmers

Jon Gjengset explains how to design a type-safe library for spatial coordinate systems and transformations in Rust.

There are a wide variety of ways to describe the locations of objects in space. To name a few, there is: WGS84, the well-known Earth-bound system of latitude and longitude; ECEF (“Earth-centered, Earth-fixed”), a Cartesian coordinate system fixed to Earth’s axes; NED (“North, East, Down”), a coordinate system that describes where in compass directions a given object is relative to an observer; or FRD (“Front, Right, Down”), which describes where a given object is relative to the facing direction of an observer. And to make matters worse, points in all of these systems except WGS84 can be expressed in Cartesian coordinates (ie, X, Y, and Z), spherical coordinates (ie, angle to pole, angle on XY plane, and radius), or horizontal coordinates (ie, azimuth, elevation, and distance). When we write software for systems that have to handle real-world coordinates, the question of what coordinate system those coordinates are in, and how they’re represented, comes up a lot. And getting it wrong in even a single place opens the door to disastrous consequences. To that end, for work, I wrote the now-open-source crate Sguaba (named after the self-navigating boat of the Celtic deity Manannán mac Lir that is navigated solely by the thoughts of its pilot). Sguaba is a Rust crate that strongly types coordinates and vectors with their respective coordinate system, and implements conversions between them. In this talk, presented at the Rust Amsterdam meetup @ BlockTech, I go into the complexities of spatial math, as well as how we can use the type system to encode those complexities away. Plus, answers to lots of questions! Sguaba open-source announcement from Helsing: blog.helsing.ai/sguaba-hard-to-misuse-rigid-body-transforms-… Sguaba on GitHub: github.com/helsing-ai/sguaba You can find the slides at jon.thesquareplanet.com/slides/sguaba/ (or an export at jon.thesquareplanet.com/slides/sguaba/export.pdf). Introduction Talk Q&A

Why it's here

3 people recommend this

What people say. Recommended as an excellent deep dive into using Rust's type system to enforce correctness in spatial math.

Moments people linked to

u/grizwakoin r/rust • Recommends

On “15 most-watched Rust talks of 2025 (so far)”

…of meetups with top quality talks. Not all of them have dedicated youtube channels, sometimes authors post videos on their personal channels. And there is even larger number of great videos which are not "conference/meetup" which differ from conference videos mainly in them not being recorded at conference/meetup :) Specific author I mentioned: [video…

Glaeqenon Lobsters • Recommends

Sguaba: Type-safe spatial math in Rust

u/Table-Games-Dealerin r/rust • Recommends

On “Unsafe fields”

In this Sguaba: Type-safe spatial math in Rust John Gjengset explains his use of unsafe in the translation of spacial formats, which have explicit invariances that cannot be reasoned through the type system and compiler. >**Should it be unsafe?** Unsafe is traditionally for **memory** safety, In Sguaba, unsafe operations can cause invalid transformations, which will violate **type** safety. >Thus, Sguaba's use of unsafe is non-idiomatic, but **extremely helpful** \- it highlights the brittle code. Other Sguaba code is *unlikely* to contain errors. >
1View on Reddit