Переглянути джерело

Make default constructors of color, vector, and matrix types initialize their underlying values.

Michael Ragazzon 6 роки тому
батько
коміт
733a944359

+ 5 - 3
Include/RmlUi/Core/Colour.h

@@ -44,14 +44,16 @@ template < typename ColourType, int AlphaDefault >
 class Colour
 {
 public:
-	/// Lightweight, non-initialising constructor.
-	inline Colour();
+	/// Initialising constructor.
+	/// @param[in] rgb Initial red, green and blue value of the colour.
+	/// @param[in] alpha Initial alpha value of the colour.
+	inline Colour(ColourType rgb = ColourType{ 0 }, ColourType alpha = ColourType{ AlphaDefault });
 	/// Initialising constructor.
 	/// @param[in] red Initial red value of the colour.
 	/// @param[in] green Initial green value of the colour.
 	/// @param[in] blue Initial blue value of the colour.
 	/// @param[in] alpha Initial alpha value of the colour.
-	inline Colour(ColourType red, ColourType green, ColourType blue, ColourType alpha = AlphaDefault);
+	inline Colour(ColourType red, ColourType green, ColourType blue, ColourType alpha = ColourType{ AlphaDefault });
 
 	/// Returns the sum of this colour and another. This does not saturate the channels.
 	/// @param[in] rhs The colour to add this to.

+ 4 - 6
Include/RmlUi/Core/Colour.inl

@@ -31,18 +31,16 @@ namespace Core {
 
 // Lightweight, non-initialising constructor.
 template < typename ColourType, int AlphaDefault >
-Colour< ColourType, AlphaDefault >::Colour()
+Colour< ColourType, AlphaDefault >::Colour(ColourType rgb, ColourType alpha) 
+	: red(rgb), green(rgb), blue(rgb), alpha(alpha)
 {
 }
 
 // Initialising constructor.
 template < typename ColourType, int AlphaDefault >
-Colour< ColourType, AlphaDefault >::Colour(ColourType _red, ColourType _green, ColourType _blue, ColourType _alpha)
+Colour< ColourType, AlphaDefault >::Colour(ColourType red, ColourType green, ColourType blue, ColourType alpha)
+	: red(red), green(green), blue(blue), alpha(alpha)
 {
-	red = _red;
-	green = _green;
-	blue = _blue;
-	alpha = _alpha;
 }
 
 // Returns the sum of this colour and another. This does not saturate the channels.

+ 2 - 2
Include/RmlUi/Core/Matrix4.h

@@ -294,10 +294,10 @@ class Matrix4
 		};
 
 	public:
-		/// Lightweight, non-initialising constructor.
+		/// Zero-initialising default constructor.
 		inline Matrix4() noexcept;
 
-		/// Initialising, copy constructor.
+		/// Copy constructor.
 		inline Matrix4(const ThisType& other) noexcept;
 		Matrix4(const TransposeType& other) noexcept;
 

+ 1 - 0
Include/RmlUi/Core/Matrix4.inl

@@ -47,6 +47,7 @@ Matrix4< Component, Storage >::Matrix4(
 // Default constructor.
 template< typename Component, class Storage >
 Matrix4< Component, Storage >::Matrix4() noexcept
+	: vectors{ VectorType{0}, VectorType{0}, VectorType{0}, VectorType{0} }
 {
 }
 

+ 3 - 2
Include/RmlUi/Core/Vector2.h

@@ -44,8 +44,9 @@ template < typename Type >
 class Vector2
 {
 	public:
-		/// Lightweight, non-initialising constructor.
-		inline Vector2();
+		/// Initialising constructor.
+		/// @param[in] v Initial value of each element in the vector.
+		inline Vector2(Type v = Type{ 0 });
 		/// Initialising constructor.
 		/// @param[in] x Initial x-value of the vector.
 		/// @param[in] y Initial y-value of the vector.

+ 3 - 5
Include/RmlUi/Core/Vector2.inl

@@ -29,18 +29,16 @@
 namespace Rml {
 namespace Core {
 
-// Default constructor.
+// Initialising constructor.
 template < typename Type >
-Vector2< Type >::Vector2()
+Vector2< Type >::Vector2(Type v) : x(v), y(v)
 {
 }
 
 // Initialising constructor.
 template < typename Type >
-Vector2< Type >::Vector2(Type _x, Type _y)
+Vector2< Type >::Vector2(Type x, Type y) : x(x), y(y)
 {
-	x = _x;
-	y = _y;
 }
 
 // Returns the magnitude of the vector.

+ 3 - 2
Include/RmlUi/Core/Vector3.h

@@ -44,8 +44,9 @@ template < typename Type >
 class Vector3
 {
 	public:
-		/// Lightweight, non-initialising constructor.
-		inline Vector3();
+		/// Initialising constructor.
+		/// @param[in] v Initial value of each element in the vector.
+		inline Vector3(Type v = Type{ 0 });
 		/// Initialising constructor.
 		/// @param[in] x Initial x-value of the vector.
 		/// @param[in] y Initial y-value of the vector.

+ 3 - 6
Include/RmlUi/Core/Vector3.inl

@@ -31,19 +31,16 @@
 namespace Rml {
 namespace Core {
 
-// Default constructor.
+// Initialising constructor.
 template < typename Type >
-Vector3< Type >::Vector3()
+Vector3< Type >::Vector3(Type v) : x(v), y(v), z(v)
 {
 }
 
 // Initialising constructor.
 template < typename Type >
-Vector3< Type >::Vector3(Type _x, Type _y, Type _z)
+Vector3< Type >::Vector3(Type x, Type y, Type z) : x(x), y(y), z(z)
 {
-	x = _x;
-	y = _y;
-	z = _z;
 }
 
 // Returns the magnitude of the vector.

+ 3 - 2
Include/RmlUi/Core/Vector4.h

@@ -45,8 +45,9 @@ template < typename Type >
 class Vector4
 {
 	public:
-		/// Lightweight, non-initialising constructor.
-		inline Vector4();
+		/// Initialising constructor.
+		/// @param[in] v Initial value of each element in the vector.
+		inline Vector4(Type v = Type{ 0 });
 		/// Initialising constructor.
 		/// @param[in] x Initial x-value of the vector.
 		/// @param[in] y Initial y-value of the vector.

+ 5 - 4
Include/RmlUi/Core/Vector4.inl

@@ -31,16 +31,17 @@
 namespace Rml {
 namespace Core {
 
-// Default constructor.
+// Initialising constructor.
 template < typename Type >
-Vector4< Type >::Vector4()
+Vector4< Type >::Vector4(Type v) 
+	: x(v), y(v), z(v), w(v)
 {
 }
 
 // Initialising constructor.
 template < typename Type >
-Vector4< Type >::Vector4(Type _x, Type _y, Type _z, Type _w)
-	: x(_x), y(_y), z(_z), w(_w)
+Vector4< Type >::Vector4(Type x, Type y, Type z, Type w)
+	: x(x), y(y), z(z), w(w)
 {
 }