Viam C++ SDK current
Loading...
Searching...
No Matches
linear_algebra.hpp
1#pragma once
2
3#include <array>
4
5#include <boost/qvm/vec.hpp>
6#include <boost/qvm/vec_traits.hpp>
7
8#include <viam/sdk/common/proto_convert.hpp>
9
10namespace viam {
11namespace common {
12namespace v1 {
13
14class Vector3;
15}
16} // namespace common
17} // namespace viam
18
19namespace viam {
20namespace sdk {
21
22// In the future, we may wish to inline this whole class
23// for performance reasons.
24
25struct Vector3 {
26 using scalar_type = double;
27
28 scalar_type x() const;
29 scalar_type y() const;
30 scalar_type z() const;
32 Vector3& set_x(scalar_type x);
34 Vector3& set_y(scalar_type y);
36 Vector3& set_z(scalar_type z);
37
38 std::array<scalar_type, 3> data;
39};
40
41namespace proto_convert_details {
42
43template <>
45 void operator()(const Vector3&, common::v1::Vector3*) const;
46};
47
48template <>
49struct from_proto_impl<common::v1::Vector3> {
50 Vector3 operator()(const common::v1::Vector3*) const;
51};
52
53} // namespace proto_convert_details
54} // namespace sdk
55} // namespace viam
56
57namespace boost {
58namespace qvm {
59
60template <>
61struct vec_traits<viam::sdk::Vector3> {
62 static int const dim = 3;
64 using scalar_type = vec_type::scalar_type;
65
66 template <int I>
67 static inline scalar_type& write_element(vec_type& v) {
68 return v.data[I];
69 }
70
71 template <int I>
72 static inline scalar_type read_element(vec_type const& v) {
73 return v.data[I];
74 }
75
76 static inline scalar_type& write_element_idx(int i, vec_type& v) {
77 return v.data[i];
78 }
79
80 static inline scalar_type read_element_idx(int i, vec_type const& v) {
81 return v.data[i];
82 }
83};
84
85} // namespace qvm
86} // namespace boost
Definition linear_algebra.hpp:25
Vector3 & set_y(scalar_type y)
Set the y value of the vector (can be chained)
Vector3 & set_z(scalar_type z)
Set the z value of the vector (can be chained)
Vector3 & set_x(scalar_type x)
Set the x value of the vector (can be chained)