Skip to content
This repository was archived by the owner on Jan 5, 2024. It is now read-only.

Commit 1fe943e

Browse files
committed
Any method that can, returns reference to this Vector
1 parent aa6f16b commit 1fe943e

File tree

1 file changed

+29
-17
lines changed

1 file changed

+29
-17
lines changed

System/Vector.h

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,15 @@ namespace RTE {
5858
/// Sets the X value of this Vector.
5959
/// </summary>
6060
/// <param name="newX">A float value that the X value will be set to.</param>
61-
void SetX(const float newX) { m_X = newX; }
61+
/// <returns>Vector reference to this after the operation.</returns>
62+
Vector & SetX(const float newX) { m_X = newX; return *this; }
6263

6364
/// <summary>
6465
/// Sets the X value of this Vector.
6566
/// </summary>
6667
/// <param name="newX">An int value that the X value will be set to.</param>
67-
void SetIntX(const int newX) { m_X = static_cast<float>(newX); }
68+
/// <returns>Vector reference to this after the operation.</returns>
69+
Vector & SetIntX(const int newX) { m_X = static_cast<float>(newX); return *this; }
6870

6971
/// <summary>
7072
/// Gets the Y value of this Vector.
@@ -76,27 +78,31 @@ namespace RTE {
7678
/// Sets the Y value of this Vector.
7779
/// </summary>
7880
/// <param name="newY">A float value that the Y value will be set to.</param>
79-
void SetY(const float newY) { m_Y = newY; }
81+
/// <returns>Vector reference to this after the operation.</returns>
82+
Vector & SetY(const float newY) { m_Y = newY; return *this; }
8083

8184
/// <summary>
8285
/// Sets the Y value of this Vector.
8386
/// </summary>
8487
/// <param name="newY">An int value that the Y value will be set to.</param>
85-
void SetIntY(const int newY) { m_Y = static_cast<float>(newY); }
88+
/// <returns>Vector reference to this after the operation.</returns>
89+
Vector & SetIntY(const int newY) { m_Y = static_cast<float>(newY); return *this; }
8690

8791
/// <summary>
8892
/// Sets both the X and Y values of this Vector.
8993
/// </summary>
9094
/// <param name="newX">A float value that the X value will be set to.</param>
9195
/// <param name="newY">A float value that the Y value will be set to.</param>
92-
void SetXY(const float newX, const float newY) { m_X = newX; m_Y = newY; }
96+
/// <returns>Vector reference to this after the operation.</returns>
97+
Vector & SetXY(const float newX, const float newY) { m_X = newX; m_Y = newY; return *this; }
9398

9499
/// <summary>
95100
/// Sets both the X and Y values of this Vector.
96101
/// </summary>
97102
/// <param name="newX">An int value that the X value will be set to.</param>
98103
/// <param name="newY">An int value that the Y value will be set to.</param>
99-
void SetIntXY(const int newX, const int newY) { m_X = static_cast<float>(newX); m_Y = static_cast<float>(newY); }
104+
/// <returns>Vector reference to this after the operation.</returns>
105+
Vector & SetIntXY(const int newX, const int newY) { m_X = static_cast<float>(newX); m_Y = static_cast<float>(newY); return *this; }
100106

101107
/// <summary>
102108
/// Gets the absolute largest of the two elements. Will always be positive.
@@ -121,7 +127,8 @@ namespace RTE {
121127
/// Flips the X element of this Vector.
122128
/// </summary>
123129
/// <param name="flipX">Whether or not to flip the X element or not.</param>
124-
void FlipX(const bool flipX = true) { *this = GetXFlipped(flipX); }
130+
/// <returns>Vector reference to this after the operation.</returns>
131+
Vector & FlipX(const bool flipX = true) { *this = GetXFlipped(flipX); return *this; }
125132

126133
/// <summary>
127134
/// Gets a Vector identical to this except that its Y component is flipped.
@@ -134,7 +141,8 @@ namespace RTE {
134141
/// Flips the Y element of this Vector.
135142
/// </summary>
136143
/// <param name="flipY">Whether or not to flip the Y element or not.</param>
137-
void FlipY(const bool flipY = true) { *this = GetYFlipped(flipY); }
144+
/// <returns>Vector reference to this after the operation.</returns>
145+
Vector & FlipY(const bool flipY = true) { *this = GetYFlipped(flipY); return *this; }
138146

139147
/// <summary>
140148
/// Indicates whether the X component of this Vector is 0.
@@ -173,14 +181,14 @@ namespace RTE {
173181
/// Sets the magnitude of this Vector. A negative magnitude will invert the Vector's direction.
174182
/// </summary>
175183
/// <param name="newMag">A float value that the magnitude will be set to.</param>
176-
/// <returns>A reference to this after the change.</returns>
184+
/// <returns>Vector reference to this after the operation.</returns>
177185
Vector & SetMagnitude(const float newMag);
178186

179187
/// <summary>
180188
/// Caps the magnitude of this Vector to a max value and keeps its angle intact.
181189
/// </summary>
182190
/// <param name="capMag">A float value that the magnitude will be capped by.</param>
183-
/// <returns>A reference to this after the change.</returns>
191+
/// <returns>Vector reference to this after the operation.</returns>
184192
Vector & CapMagnitude(const float capMag);
185193

186194
/// <summary>
@@ -213,21 +221,21 @@ namespace RTE {
213221
/// Rotate this Vector relatively by an angle in radians.
214222
/// </summary>
215223
/// <param name="angle">The angle in radians to rotate by. Positive angles rotate counter-clockwise, and negative angles clockwise.</param>
216-
/// <returns>This vector, rotated.</returns>
224+
/// <returns>Vector reference to this after the operation.</returns>
217225
Vector & RadRotate(const float angle);
218226

219227
/// <summary>
220228
/// Rotate this Vector relatively by an angle in degrees.
221229
/// </summary>
222230
/// <param name="angle">The angle in degrees to rotate by. Positive angles rotate counter-clockwise, and negative angles clockwise.</param>
223-
/// <returns>This vector, rotated.</returns>
231+
/// <returns>Vector reference to this after the operation.</returns>
224232
Vector & DegRotate(const float angle) { return RadRotate(angle * c_PI / 180.0F); }
225233

226234
/// <summary>
227235
/// Set this Vector to an absolute rotation based on the absolute rotation of another Vector.
228236
/// </summary>
229237
/// <param name="refVector">The reference Vector whose absolute angle from positive X (0 degrees) this Vector will be rotated to.</param>
230-
/// <returns>This vector, rotated.</returns>
238+
/// <returns>Vector reference to this after the operation.</returns>
231239
Vector & AbsRotateTo(const Vector &refVector) { return RadRotate(refVector.GetAbsRadAngle() - GetAbsRadAngle()); }
232240

233241
/// <summary>
@@ -247,22 +255,26 @@ namespace RTE {
247255
/// <summary>
248256
/// Rounds the X and Y values of this Vector upwards. E.g. 0.49 -> 0.0 and 0.5 -> 1.0.
249257
/// </summary>
250-
void Round() { *this = GetRounded(); }
258+
/// <returns>Vector reference to this after the operation.</returns>
259+
Vector & Round() { *this = GetRounded(); return *this; }
251260

252261
/// <summary>
253262
/// Sets the X and Y of this Vector to the nearest half value. E.g. 1.0 -> 1.5 and 0.9 -> 0.5.
254263
/// </summary>
255-
void ToHalf() { m_X = std::round(m_X * 2) / 2; m_Y = std::round(m_Y * 2) / 2; }
264+
/// <returns>Vector reference to this after the operation.</returns>
265+
Vector & ToHalf() { m_X = std::round(m_X * 2) / 2; m_Y = std::round(m_Y * 2) / 2; return *this; }
256266

257267
/// <summary>
258268
/// Sets the X and Y of this Vector to the greatest integers that are not greater than their original values. E.g. -1.02 becomes -2.0.
259269
/// </summary>
260-
void Floor() { *this = GetFloored(); }
270+
/// <returns>Vector reference to this after the operation.</returns>
271+
Vector & Floor() { *this = GetFloored(); return *this; }
261272

262273
/// <summary>
263274
/// Sets the X and Y of this Vector to the lowest integers that are not less than their original values. E.g. -1.02 becomes -1.0.
264275
/// </summary>
265-
void Ceiling() { *this = GetCeilinged(); }
276+
/// <returns>Vector reference to this after the operation.</returns>
277+
Vector & Ceiling() { *this = GetCeilinged(); return *this; }
266278

267279
/// <summary>
268280
/// Returns a rounded copy of this Vector. Does not alter this Vector.

0 commit comments

Comments
 (0)