This repository was archived by the owner on Jan 5, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +12
-10
lines changed Expand file tree Collapse file tree 2 files changed +12
-10
lines changed Original file line number Diff line number Diff line change @@ -35,9 +35,11 @@ namespace RTE {
35
35
// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
36
36
37
37
Vector & Vector::SetMagnitude (float newMag) {
38
- Vector temp (*this );
39
- SetXY (newMag, 0 );
40
- AbsRotateTo (temp);
38
+ if (IsZero ()) {
39
+ SetXY (newMag, 0 .0F );
40
+ } else {
41
+ *this *= (newMag / GetMagnitude ());
42
+ }
41
43
return *this ;
42
44
}
43
45
@@ -52,16 +54,16 @@ namespace RTE {
52
54
// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
53
55
54
56
float Vector::GetAbsRadAngle () const {
55
- float radAngle = -std::atan2 (m_Y, m_X);
57
+ const float radAngle = -std::atan2 (m_Y, m_X);
56
58
return (radAngle < -c_HalfPI) ? (radAngle + c_TwoPI) : radAngle;
57
59
}
58
60
59
61
// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
60
62
61
63
Vector & Vector::RadRotate (float angle) {
62
64
angle = -angle;
63
- float tempX = m_X * std::cos (angle) - m_Y * std::sin (angle);
64
- float tempY = m_X * std::sin (angle) + m_Y * std::cos (angle);
65
+ const float tempX = m_X * std::cos (angle) - m_Y * std::sin (angle);
66
+ const float tempY = m_X * std::sin (angle) + m_Y * std::cos (angle);
65
67
m_X = tempX;
66
68
m_Y = tempY;
67
69
@@ -86,7 +88,7 @@ namespace RTE {
86
88
for (const Vector &vector : rhs) {
87
89
*this += vector;
88
90
}
89
- *this /= rhs.size ();
91
+ *this /= static_cast < float >( rhs.size () );
90
92
}
91
93
return *this ;
92
94
}
Original file line number Diff line number Diff line change @@ -190,7 +190,7 @@ namespace RTE {
190
190
float GetMagnitude () const { return std::sqrt (std::pow (m_X, 2 .0F ) + std::pow (m_Y, 2 .0F )); }
191
191
192
192
// / <summary>
193
- // / Sets the magnitude of this Vector and keeps its angle intact .
193
+ // / Sets the magnitude of this Vector. A negative magnitude will invert the Vector's direction .
194
194
// / </summary>
195
195
// / <param name="newMag">A float value that the magnitude will be set to.</param>
196
196
// / <returns>A reference to this after the change.</returns>
@@ -312,13 +312,13 @@ namespace RTE {
312
312
// / Returns the greatest integer that is not greater than the X value of this Vector.
313
313
// / </summary>
314
314
// / <returns>An int value that represents the X value of this Vector.</returns>
315
- int GetFloorIntX () const { return static_cast <int >(std::floor ( m_X) ); }
315
+ int GetFloorIntX () const { return static_cast <int >(m_X); }
316
316
317
317
// / <summary>
318
318
// / Returns the greatest integer that is not greater than the Y value of this Vector.
319
319
// / </summary>
320
320
// / <returns>An int value that represents the Y value of this Vector.</returns>
321
- int GetFloorIntY () const { return static_cast <int >(std::floor ( m_Y) ); }
321
+ int GetFloorIntY () const { return static_cast <int >(m_Y); }
322
322
323
323
// / <summary>
324
324
// / Returns a ceilinged copy of this Vector. Does not alter this Vector.
You can’t perform that action at this time.
0 commit comments