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/api/common/v1/common.pb.h>
9namespace viam {
10namespace sdk {
11
12// In the future, we may wish to inline this whole class
13// for performance reasons.
14
15class Vector3 {
16 public:
17 using scalar_type = double;
18 Vector3(scalar_type x, scalar_type y, scalar_type z);
19 Vector3();
20
21 scalar_type x() const;
22 scalar_type y() const;
23 scalar_type z() const;
25 Vector3& set_x(scalar_type x);
27 Vector3& set_y(scalar_type y);
29 Vector3& set_z(scalar_type z);
30
31 const std::array<scalar_type, 3>& data() const;
32 std::array<scalar_type, 3>& data();
33 viam::common::v1::Vector3 to_proto() const;
34 static Vector3 from_proto(const viam::common::v1::Vector3& vec);
35
36 private:
37 std::array<scalar_type, 3> data_;
38};
39
40} // namespace sdk
41} // namespace viam
42
43namespace boost {
44namespace qvm {
45
46template <>
47struct vec_traits<viam::sdk::Vector3> {
48 static int const dim = 3;
50 using scalar_type = vec_type::scalar_type;
51
52 template <int I>
53 static inline scalar_type& write_element(vec_type& v) {
54 return v.data()[I];
55 }
56
57 template <int I>
58 static inline scalar_type read_element(vec_type const& v) {
59 return v.data()[I];
60 }
61
62 static inline scalar_type& write_element_idx(int i, vec_type& v) {
63 return v.data()[i];
64 }
65
66 static inline scalar_type read_element_idx(int i, vec_type const& v) {
67 return v.data()[i];
68 }
69};
70
71} // namespace qvm
72} // namespace boost
Definition linear_algebra.hpp:15
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)