JNGL
Vec2.hpp
Go to the documentation of this file.
1 // Copyright 2018-2020 Jan Niklas Hasse <[email protected]>
2 // For conditions of distribution and use, see copyright notice in LICENSE.txt
4 #pragma once
5 
6 #if !defined(__has_include) || __has_include("boost/version.hpp")
7 #include <boost/version.hpp>
8 #endif
9 #include <iosfwd>
10 
11 namespace jngl {
12 
14 class Vec2 {
15 public:
17  Vec2();
18 
20  Vec2(double x, double y);
21 
23  double x = 0;
24 
26  double y = 0;
27 
29  template <class Archive> void serialize(Archive& ar, const unsigned int) {
30  ar(x, y);
31  }
32 };
33 
34 } // namespace jngl
35 
36 std::ostream& operator<<(std::ostream&, const jngl::Vec2&);
37 
38 #if BOOST_VERSION >= 106200 || __has_include("boost/qvm/vec_traits.hpp")
39 #include <boost/qvm/vec_traits.hpp>
40 
41 namespace boost::qvm {
42 template <> struct vec_traits<jngl::Vec2> {
43  static int const dim = 2;
44  using scalar_type = double;
45 
46  template <int I> static inline scalar_type& write_element(jngl::Vec2& v) {
47  return (&v.x)[I];
48  }
49  template <int I> static inline scalar_type read_element(const jngl::Vec2& v) {
50  return (&v.x)[I];
51  }
52 
53  static inline scalar_type& write_element_idx(int i, jngl::Vec2& v) {
54  return (&v.x)[i];
55  }
56  static inline scalar_type read_element_idx(int i, jngl::Vec2 const& v) {
57  return (&v.x)[i];
58  }
59 };
60 } // namespace boost::qvm
61 
62 #include <boost/qvm/vec_operations.hpp>
63 
64 using boost::qvm::operator+=;
65 using boost::qvm::operator*=;
66 using boost::qvm::operator/=;
67 using boost::qvm::operator-=;
68 using boost::qvm::operator==;
69 using boost::qvm::operator!=;
70 using boost::qvm::operator+;
71 using boost::qvm::operator-;
72 using boost::qvm::operator/;
73 using boost::qvm::operator*;
74 #endif
iosfwd
jngl::Vec2::serialize
void serialize(Archive &ar, const unsigned int)
Helper function to use with cereal or Boost.Serialization.
Definition: Vec2.hpp:29
jngl
JNGL's main namespace.
Definition: App.hpp:9
std::ostream
jngl::Vec2::x
double x
x component
Definition: Vec2.hpp:23
jngl::Vec2::y
double y
y component
Definition: Vec2.hpp:26
jngl::Vec2::Vec2
Vec2(double x, double y)
Creates a vector {x, y}.
jngl::Vec2
Two-dimensional vector.
Definition: Vec2.hpp:14
jngl::Vec2::Vec2
Vec2()
Null vector.