TraveSim Adapters  0.1
Protobuf adapters for TraveSim project
travesim::Vector2D Class Reference

Data structure to hold a two dimensional vector. More...

#include "entity_state.hpp"

Collaboration diagram for travesim::Vector2D:

Public Member Functions

 Vector2D (double x=0, double y=0)
 Construct a new Vector2D object. More...
 
void rotate (double theta)
 Perform a counter-clockwise rotation of the vector. More...
 

Public Attributes

double x
 Public attributes. More...
 
double y
 

Friends

std::ostream & operator<< (std::ostream &output, const Vector2D &vector_2d)
 Output stream operator overloading. More...
 

Detailed Description

Data structure to hold a two dimensional vector.

Definition at line 21 of file entity_state.hpp.

Constructor & Destructor Documentation

◆ Vector2D()

travesim::Vector2D::Vector2D ( double  x = 0,
double  y = 0 
)

Construct a new Vector2D object.

Parameters
xx quota
yy quota

Definition at line 21 of file entity_state.cpp.

21  {
22  this->x = x;
23  this->y = y;
24 }
double x
Public attributes.

References x, and y.

Member Function Documentation

◆ rotate()

void travesim::Vector2D::rotate ( double  theta)

Perform a counter-clockwise rotation of the vector.

Parameters
thetaRotation angle in radians

Definition at line 26 of file entity_state.cpp.

26  {
27  double old_x = this->x, old_y = this->y;
28 
29  this->x = cos(theta)*old_x + sin(theta)*old_y;
30  this->y = -sin(theta)*old_x + cos(theta)*old_y;
31 }
double x
Public attributes.

References x, and y.

Friends And Related Function Documentation

◆ operator<<

std::ostream& operator<< ( std::ostream &  output,
const Vector2D vector_2d 
)
friend

Output stream operator overloading.

Definition at line 33 of file entity_state.cpp.

33  {
34  output << std::fixed << std::setprecision(PRINTING_DECIMAL_PRECISION);
35 
36  output << "X: " << std::setw(PRINTING_MIN_WIDTH) << vector_2d.x << " | ";
37  output << "Y: " << std::setw(PRINTING_MIN_WIDTH) << vector_2d.y;
38 
39  return output;
40 }
#define PRINTING_DECIMAL_PRECISION
Definition: data_common.hpp:22
#define PRINTING_MIN_WIDTH
Printing output configuration constants.
Definition: data_common.hpp:21

Member Data Documentation

◆ x

double travesim::Vector2D::x

Public attributes.

Definition at line 48 of file entity_state.hpp.

◆ y

double travesim::Vector2D::y

Definition at line 49 of file entity_state.hpp.


The documentation for this class was generated from the following files: