Orrery
A GPU-accelerated N-body gravitational simulator
Loading...
Searching...
No Matches
vec3.hpp File Reference

A three-component vector for interfaces, not for storage. More...

#include <cmath>
#include "orrery/core/types.hpp"

Go to the source code of this file.

Classes

struct  orrery::core::Vec3
 A vector in three-dimensional Euclidean space. More...

Functions

constexpr Vec3 orrery::core::operator+ (Vec3 a, Vec3 b) noexcept
constexpr Vec3 orrery::core::operator- (Vec3 a, Vec3 b) noexcept
constexpr Vec3 orrery::core::operator- (Vec3 v) noexcept
constexpr Vec3 orrery::core::operator* (Vec3 v, Real scale) noexcept
constexpr Vec3 orrery::core::operator* (Real scale, Vec3 v) noexcept
constexpr Vec3 orrery::core::operator/ (Vec3 v, Real divisor) noexcept
constexpr Real orrery::core::dot (Vec3 a, Vec3 b) noexcept
constexpr Vec3 orrery::core::cross (Vec3 a, Vec3 b) noexcept
constexpr Real orrery::core::squared_norm (Vec3 v) noexcept
 The squared length.
Real orrery::core::norm (Vec3 v) noexcept
 The length.

Detailed Description

A three-component vector for interfaces, not for storage.

Particles are stored as separate component arrays rather than as vectors (ADR-0004), so this type never appears in the inner loop of a force kernel. It exists so that setup code, diagnostics and tests can pass a position or a velocity as one value rather than as three loose scalars, which is where transposed arguments come from. Every operation is constexpr so that an analytic configuration, a Kepler orbit among them, can be written down at compile time and checked by the compiler rather than at run time.

Function Documentation

◆ squared_norm()

Real orrery::core::squared_norm ( Vec3 v)
nodiscardconstexprnoexcept

The squared length.

Named separately rather than left as dot(v, v) because the squared length is what the physics actually wants nearly everywhere. A gravitational force falls as the inverse square of the separation, so a kernel that took a square root only to square it again would pay for the most expensive operation in the loop and then discard it.

◆ norm()

Real orrery::core::norm ( Vec3 v)
inlinenodiscardnoexcept

The length.

Not constexpr: std::sqrt only becomes usable in constant expressions in C++26, and this project is C++20. The compile-time configurations that need a magnitude can use squared_norm instead.