Procházet zdrojové kódy

Add min()/max() to vector types

Daniele Bartolini před 10 roky
rodič
revize
0f3bffd753
3 změnil soubory, kde provedl 60 přidání a 0 odebrání
  1. 18 0
      src/core/math/vector2.h
  2. 20 0
      src/core/math/vector3.h
  3. 22 0
      src/core/math/vector4.h

+ 18 - 0
src/core/math/vector2.h

@@ -149,6 +149,24 @@ inline float angle(const Vector2& a, const Vector2& b)
 	return acos(dot(a, b) / (length(a) * length(b)));
 }
 
+/// Returns a vector that contains the largest value for each component from @a a and @a b.
+inline Vector2 max(const Vector2& a, const Vector2& b)
+{
+	Vector2 v;
+	v.x = fmax(a.x, b.x);
+	v.y = fmax(a.y, b.y);
+	return v;
+}
+
+/// Returns a vector that contains the smallest value for each component from @a a and @a b.
+inline Vector2 min(const Vector2& a, const Vector2& b)
+{
+	Vector2 v;
+	v.x = fmin(a.x, b.x);
+	v.y = fmin(a.y, b.y);
+	return v;
+}
+
 /// Returns the pointer to the data of @a a.
 inline float* to_float_ptr(Vector2& a)
 {

+ 20 - 0
src/core/math/vector3.h

@@ -163,6 +163,26 @@ inline float angle(const Vector3& a, const Vector3& b)
 	return acos(dot(a, b) / (length(a) * length(b)));
 }
 
+/// Returns a vector that contains the largest value for each component from @a a and @a b.
+inline Vector3 max(const Vector3& a, const Vector3& b)
+{
+	Vector3 v;
+	v.x = fmax(a.x, b.x);
+	v.y = fmax(a.y, b.y);
+	v.z = fmax(a.z, b.z);
+	return v;
+}
+
+/// Returns a vector that contains the smallest value for each component from @a a and @a b.
+inline Vector3 min(const Vector3& a, const Vector3& b)
+{
+	Vector3 v;
+	v.x = fmin(a.x, b.x);
+	v.y = fmin(a.y, b.y);
+	v.z = fmin(a.z, b.z);
+	return v;
+}
+
 /// Returns the pointer to the data of @a a.
 inline float* to_float_ptr(Vector3& a)
 {

+ 22 - 0
src/core/math/vector4.h

@@ -181,6 +181,28 @@ inline float angle(const Vector4& a, const Vector4& b)
 	return acos(dot(a, b) / (length(a) * length(b)));
 }
 
+/// Returns a vector that contains the largest value for each component from @a a and @a b.
+inline Vector4 max(const Vector4& a, const Vector4& b)
+{
+	Vector4 v;
+	v.x = fmax(a.x, b.x);
+	v.y = fmax(a.y, b.y);
+	v.z = fmax(a.z, b.z);
+	v.w = fmax(a.w, b.w);
+	return v;
+}
+
+/// Returns a vector that contains the smallest value for each component from @a a and @a b.
+inline Vector4 min(const Vector4& a, const Vector4& b)
+{
+	Vector4 v;
+	v.x = fmin(a.x, b.x);
+	v.y = fmin(a.y, b.y);
+	v.z = fmin(a.z, b.z);
+	v.w = fmin(a.w, b.w);
+	return v;
+}
+
 /// Returns the pointer to the data of @a a.
 inline float* to_float_ptr(Vector4& a)
 {