VR-Engage  2.2
Loading...
Searching...
No Matches
vector2DD.h
Go to the documentation of this file.
1/*********************************************************************************
2** Copyright (c) 2025 MAK Technologies
3** All rights reserved.
4*********************************************************************************/
5
6#pragma once
7
8//! \file vector2DD.h
9//! \brief Provides a class for 2D vector operations with double precision
10
11#include "vreUtil/export.h"
12
13namespace makVre
14{
15//! \brief Class representing a 2D vector with double precision
16//!
17//! This class provides functionality for working with 2D vectors including
18//! basic vector operations such as length calculation, normalization, and rotation.
20{
21public:
22 //! \brief Default constructor
23 //!
24 //! Creates a vector with coordinates (0,0)
26
27 //! \brief Constructor with x and y coordinates
28 //!
29 //! \param x The x coordinate
30 //! \param y The y coordinate
31 DtVector2DD(double x, double y);
32
33 //! \brief Copy constructor
34 //!
35 //! \param orig The vector to copy
37
38 //! \brief Assignment operator
39 //!
40 //! \param orig The vector to copy
41 //! \return Reference to this vector after assignment
42 const DtVector2DD& operator=(const DtVector2DD& orig);
43
44 //! \brief Division assignment operator
45 //!
46 //! Divides both x and y components by a scalar value
47 //!
48 //! \param scalar The scalar to divide by
49 //! \return Reference to this vector after division
50 inline DtVector2DD& operator/=(double scalar);
51
52 //! \brief Sets the x coordinate
53 //!
54 //! \param x The new x coordinate
55 void setX(double x);
56
57 //! \brief Gets the x coordinate
58 //!
59 //! \return The x coordinate
60 double x() const;
61
62 //! \brief Sets the y coordinate
63 //!
64 //! \param y The new y coordinate
65 void setY(double y);
66
67 //! \brief Gets the y coordinate
68 //!
69 //! \return The y coordinate
70 double y() const;
71
72 //! \brief Rotates the vector counter-clockwise
73 //!
74 //! \param rotationAngle The angle to rotate in radians
75 inline void rotate(double rotationAngle);
76
77 //! \brief Calculates the length/magnitude of the vector
78 //!
79 //! \return The length of the vector
80 inline double length() const;
81
82 //! \brief Calculates the squared length/magnitude of the vector
83 //!
84 //! This is more efficient than length() when comparing distances,
85 //! as it avoids the square root calculation
86 //!
87 //! \return The squared length of the vector
88 inline double lengthSquared() const;
89
90 //! \brief Normalizes the vector
91 //!
92 //! Adjusts the vector to have a length of 1 while preserving its direction
93 void normalize();
94
95protected:
96 //! \brief The x coordinate
97 double myX;
98
99 //! \brief The y coordinate
100 double myY;
101};
102
103//! \brief Stream insertion operator for DtVector2DD
104//!
105//! Allows for convenient printing of vectors to output streams
106//!
107//! \param str The output stream
108//! \param vec The vector to output
109//! \return Reference to the output stream
110inline std::ostream& operator<<(std::ostream& str, const makVre::DtVector2DD& vec)
111{
112 str << "[ x= " << vec.x() << " y= " << vec.y() << " ]";
113 return str;
114}
115} // namespace makVre
Class representing a 2D vector with double precision.
Definition vector2DD.h:20
void setY(double y)
Sets the y coordinate.
double x() const
Gets the x coordinate.
DtVector2DD & operator/=(double scalar)
Division assignment operator.
DtVector2DD(const DtVector2DD &orig)
Copy constructor.
double myY
The y coordinate.
Definition vector2DD.h:100
double length() const
Calculates the length/magnitude of the vector.
double myX
The x coordinate.
Definition vector2DD.h:97
const DtVector2DD & operator=(const DtVector2DD &orig)
Assignment operator.
void normalize()
Normalizes the vector.
double lengthSquared() const
Calculates the squared length/magnitude of the vector.
DtVector2DD(double x, double y)
Constructor with x and y coordinates.
double y() const
Gets the y coordinate.
DtVector2DD()
Default constructor.
void rotate(double rotationAngle)
Rotates the vector counter-clockwise.
void setX(double x)
Sets the x coordinate.
Defines export macros for the VREngage Utility library.
#define UTIL_DLL
Export/import macro for non-Windows platforms.
Definition export.h:39
Include export definitions for this library.
Definition glsVreMessageUtil.h:49
std::ostream & operator<<(std::ostream &str, const makVre::DtVector2DD &vec)
Stream insertion operator for DtVector2DD.
Definition vector2DD.h:110