JNGL
Vec2.hpp
Go to the documentation of this file.
1 // Copyright 2018-2021 Jan Niklas Hasse <[email protected]>
2 // For conditions of distribution and use, see copyright notice in LICENSE.txt
5 #pragma once
6 
7 #if !defined(__has_include) || __has_include("boost/version.hpp")
8 #include <boost/version.hpp>
9 #endif
10 #include <iosfwd>
11 
12 namespace jngl {
13 
35 class Vec2 {
36 public:
38  Vec2();
39 
41  Vec2(double x, double y);
42 
44  double x = 0;
45 
47  double y = 0;
48 
50  template <class Archive> void serialize(Archive& ar, const unsigned int) {
51  ar(x, y);
52  }
53 };
54 
55 } // namespace jngl
56 
59 
60 #if BOOST_VERSION >= 106200 || __has_include("boost/qvm/vec_traits.hpp")
61 #include <boost/qvm/vec_traits.hpp>
62 
63 namespace boost::qvm {
64 template <> struct vec_traits<jngl::Vec2> {
65  static int const dim = 2;
66  using scalar_type = double;
67 
68  template <int I> static inline scalar_type& write_element(jngl::Vec2& v) {
69  return (&v.x)[I];
70  }
71  template <int I> static inline scalar_type read_element(const jngl::Vec2& v) {
72  return (&v.x)[I];
73  }
74 
75  static inline scalar_type& write_element_idx(int i, jngl::Vec2& v) {
76  return (&v.x)[i];
77  }
78  static inline scalar_type read_element_idx(int i, jngl::Vec2 const& v) {
79  return (&v.x)[i];
80  }
81 };
82 } // namespace boost::qvm
83 
84 #include <boost/qvm/vec_operations.hpp>
85 
86 using boost::qvm::operator+=;
87 using boost::qvm::operator*=;
88 using boost::qvm::operator/=;
89 using boost::qvm::operator-=;
90 using boost::qvm::operator==;
91 using boost::qvm::operator!=;
92 using boost::qvm::operator+;
93 using boost::qvm::operator-;
94 using boost::qvm::operator/;
95 using boost::qvm::operator*;
96 #endif
std::ostream & operator<<(std::ostream &, const jngl::Vec2 &)
Prints the vector like this: [x=…, y=…].
Two-dimensional vector.
Definition: Vec2.hpp:35
Vec2()
Null vector.
double y
y component
Definition: Vec2.hpp:47
Vec2(double x, double y)
Creates a vector {x, y}.
void serialize(Archive &ar, const unsigned int)
Helper function to use with cereal or Boost.Serialization.
Definition: Vec2.hpp:50
double x
x component
Definition: Vec2.hpp:44
JNGL's main namespace.
Definition: App.hpp:10