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
41inline bool operator==(const Vector3& a, const Vector3& b) {
42 return a.data == b.data;
43}
44
45inline bool operator!=(const Vector3& a, const Vector3& b) {
46 return !(a == b);
47}
48
49namespace proto_convert_details {
50
51template <>
53 void operator()(const Vector3&, common::v1::Vector3*) const;
54};
55
56template <>
57struct from_proto_impl<common::v1::Vector3> {
58 Vector3 operator()(const common::v1::Vector3*) const;
59};
60
61} // namespace proto_convert_details
62} // namespace sdk
63} // namespace viam
64
65namespace boost {
66namespace qvm {
67
68template <>
69struct vec_traits<viam::sdk::Vector3> {
70 static int const dim = 3;
72 using scalar_type = vec_type::scalar_type;
73
74 template <int I>
75 static inline scalar_type& write_element(vec_type& v) {
76 return v.data[I];
77 }
78
79 template <int I>
80 static inline scalar_type read_element(vec_type const& v) {
81 return v.data[I];
82 }
83
84 static inline scalar_type& write_element_idx(int i, vec_type& v) {
85 return v.data[i];
86 }
87
88 static inline scalar_type read_element_idx(int i, vec_type const& v) {
89 return v.data[i];
90 }
91};
92
93} // namespace qvm
94} // 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)