siderust-cpp
Header-only C++ wrapper for siderust
Loading...
Searching...
No Matches
cartesian.hpp
Go to the documentation of this file.
1#pragma once
2
9#include "../centers.hpp"
10#include "../ffi_core.hpp"
11#include "../frames.hpp"
12
13#include <qtty/qtty.hpp>
14
15namespace siderust {
16namespace cartesian {
17
26template <typename F>
27struct Direction {
28 static_assert(frames::is_frame_v<F>, "F must be a valid frame tag");
29
30 double x;
31 double y;
32 double z;
33
34 Direction() : x(0), y(0), z(0) {}
35 Direction(double x_, double y_, double z_) : x(x_), y(y_), z(z_) {}
36
37 static constexpr siderust_frame_t frame_id() {
39 }
40};
41
52template <typename C, typename F, typename U = qtty::Meter>
53struct Position {
54 static_assert(frames::is_frame_v<F>, "F must be a valid frame tag");
55 static_assert(centers::is_center_v<C>, "C must be a valid center tag");
56
60
62 : comp_x(U(0)), comp_y(U(0)), comp_z(U(0)) {}
63
64 Position(U x_, U y_, U z_)
65 : comp_x(x_), comp_y(y_), comp_z(z_) {}
66
67 Position(double x_, double y_, double z_)
68 : comp_x(U(x_)), comp_y(U(y_)), comp_z(U(z_)) {}
69
70 U x() const { return comp_x; }
71 U y() const { return comp_y; }
72 U z() const { return comp_z; }
73
74 static constexpr siderust_frame_t frame_id() { return frames::FrameTraits<F>::ffi_id; }
75 static constexpr siderust_center_t center_id() { return centers::CenterTraits<C>::ffi_id; }
76
78 siderust_cartesian_pos_t to_c() const {
79 return {comp_x.value(), comp_y.value(), comp_z.value(),
80 frame_id(), center_id()};
81 }
82
84 static Position from_c(const siderust_cartesian_pos_t& c) {
85 return Position(c.x, c.y, c.z);
86 }
87};
88
89} // namespace cartesian
90} // namespace siderust
A unit-vector direction in Cartesian form, compile-time frame-tagged.
Definition cartesian.hpp:27
double x
X component (unitless).
Definition cartesian.hpp:30
double y
Y component (unitless).
Definition cartesian.hpp:31
static constexpr siderust_frame_t frame_id()
Definition cartesian.hpp:37
Direction(double x_, double y_, double z_)
Definition cartesian.hpp:35
double z
Z component (unitless).
Definition cartesian.hpp:32
A 3D Cartesian position, compile-time tagged by center, frame, unit.
Definition cartesian.hpp:53
static constexpr siderust_center_t center_id()
Definition cartesian.hpp:75
siderust_cartesian_pos_t to_c() const
Convert to C FFI struct.
Definition cartesian.hpp:78
static Position from_c(const siderust_cartesian_pos_t &c)
Create from C FFI struct (ignoring runtime frame/center - trust the type).
Definition cartesian.hpp:84
Position(double x_, double y_, double z_)
Definition cartesian.hpp:67
Position(U x_, U y_, U z_)
Definition cartesian.hpp:64
static constexpr siderust_frame_t frame_id()
Definition cartesian.hpp:74
SFINAE helper: every frame tag must provide these static members.
Definition frames.hpp:28