-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathobjects.hpp
More file actions
76 lines (56 loc) · 2.15 KB
/
objects.hpp
File metadata and controls
76 lines (56 loc) · 2.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#ifndef objects_hpp
#define objects_hpp
#include <cmath>
// The class vector_2d defines a two dimensional vector useful to take care of
// the position and velocity of the boids, the methods included allow to get the
// private members of the class and apply basic math operation between vectors
class Vector_2d {
double m_x;
double m_y;
public:
Vector_2d(double x = 0., double y = 0.) : m_x{x}, m_y{y} {}
double xcomp() const;
double ycomp() const;
double norm() const;
Vector_2d& operator+=(Vector_2d const& v);
Vector_2d& operator*=(double k);
void setx(double x);
void sety(double y);
};
// Symmetric operators operator@ are implemented in terms of member
// operator@= (e.g. operator+ implemented in terms of operator+=)
Vector_2d operator-(Vector_2d const& v);
Vector_2d operator+(Vector_2d const& l, Vector_2d const& r);
Vector_2d operator-(Vector_2d const& l, Vector_2d const& r);
Vector_2d operator*(Vector_2d const& l, double k);
// Implemented comparison of vectors in order to use it for some tests
bool operator==(Vector_2d const& l, Vector_2d const& r);
bool operator!=(Vector_2d const& l, Vector_2d const& r);
// Boid and predator struct are basically the same but are defined separatly
// allowing an easier management of the two
struct Boid {
Vector_2d pos{};
Vector_2d vel{};
};
struct Predator {
Vector_2d pos{};
Vector_2d vel{};
};
// Stats is a struct that allow to define functions taking less input, e.g. if a
// function needed both a parameter s and d_s it's possible two use a single
// variable stats instead of two different ones
struct Stats {
double d_s{}; // Distance at which sep gets activated
double d{}; // Distance of influence between boids
double s{}; // Separation parameter
double a{}; // Alignment parameter
double c{}; // Cohesion parameter
double l_b{}; // Left bound
double r_b{}; // Right bound
double u_b{}; // Upper bound
double b_b{}; // Bottom bound
double d_pred{}; // Distance at which the effect of the predator is activated
double v_max{}; // Maximum velocity of the boids
double v_min{}; // Minimum velocity of the boids
};
#endif