JNGL
Easy to use cross-platform 2D game library
Loading...
Searching...
No Matches
Vec2.hpp
Go to the documentation of this file.
1// Copyright 2018-2023 Jan Niklas Hasse <jhasse@bixense.com>
2// For conditions of distribution and use, see copyright notice in LICENSE.txt
5#pragma once
6
7#include <boost/qvm_lite.hpp>
8#include <iosfwd>
9
10namespace jngl {
11
32class Vec2 {
33public:
36
38 Vec2(double x, double y);
39
41 double x = 0;
42
44 double y = 0;
45
47 bool isNull() const;
48
50 template <class Archive> void serialize(Archive& ar, const unsigned int) {
51 ar(x, y);
52 }
53};
54
57
58} // namespace jngl
59
60namespace boost::qvm {
61template <> struct vec_traits<jngl::Vec2> {
62 static int const dim = 2;
63 using scalar_type = double;
64
65 template <int I> static inline scalar_type& write_element(jngl::Vec2& v) {
66 return (&v.x)[I];
67 }
68 template <int I> static inline scalar_type read_element(const jngl::Vec2& v) {
69 return (&v.x)[I];
70 }
71
72 static inline scalar_type& write_element_idx(int i, jngl::Vec2& v) {
73 return (&v.x)[i];
74 }
75 static inline scalar_type read_element_idx(int i, jngl::Vec2 const& v) {
76 return (&v.x)[i];
77 }
78};
79} // namespace boost::qvm
80
81namespace jngl {
82using boost::qvm::operator+=;
83using boost::qvm::operator*=;
84using boost::qvm::operator/=;
85using boost::qvm::operator-=;
86using boost::qvm::operator==;
87using boost::qvm::operator!=;
88using boost::qvm::operator+;
89using boost::qvm::operator-;
90using boost::qvm::operator/;
91using boost::qvm::operator*;
92} // namespace jngl
Two-dimensional vector.
Definition: Vec2.hpp:32
Vec2()
Null vector.
double y
y component
Definition: Vec2.hpp:44
bool isNull() const
returns true if both x and y are exactly 0
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:41
JNGL's main namespace.
Definition: Achievement.hpp:10
std::ostream & operator<<(std::ostream &, const Vec2 &)
Prints the vector like this: [x=…, y=…].