[Bf-blender-cvs] [2e950e3b890] functions: move float2 to separate file

Jacques Lucke noreply at git.blender.org
Thu Feb 13 18:58:43 CET 2020


Commit: 2e950e3b89072f1570d4bdce141496b39fe1b86b
Author: Jacques Lucke
Date:   Thu Feb 13 17:47:04 2020 +0100
Branches: functions
https://developer.blender.org/rB2e950e3b89072f1570d4bdce141496b39fe1b86b

move float2 to separate file

===================================================================

A	source/blender/blenlib/BLI_float2.h
M	source/blender/blenlib/BLI_math_cxx.h

===================================================================

diff --git a/source/blender/blenlib/BLI_float2.h b/source/blender/blenlib/BLI_float2.h
new file mode 100644
index 00000000000..eb2890fce87
--- /dev/null
+++ b/source/blender/blenlib/BLI_float2.h
@@ -0,0 +1,70 @@
+#ifndef __BLI_FLOAT2_H__
+#define __BLI_FLOAT2_H__
+
+namespace BLI {
+
+struct float2 {
+  float x, y;
+
+  float2() = default;
+
+  float2(const float *ptr) : x{ptr[0]}, y{ptr[1]}
+  {
+  }
+
+  float2(float x, float y) : x(x), y(y)
+  {
+  }
+
+  float2(float3 other);
+
+  operator float *()
+  {
+    return &x;
+  }
+
+  float2 clamped(float min, float max)
+  {
+    return {std::min(std::max(x, min), max), std::min(std::max(y, min), max)};
+  }
+
+  float2 clamped_01()
+  {
+    return this->clamped(0, 1);
+  }
+
+  friend float2 operator+(float2 a, float2 b)
+  {
+    return {a.x + b.x, a.y + b.y};
+  }
+
+  friend float2 operator-(float2 a, float2 b)
+  {
+    return {a.x - b.x, a.y - b.y};
+  }
+
+  friend float2 operator*(float2 a, float b)
+  {
+    return {a.x * b, a.y * b};
+  }
+
+  friend float2 operator/(float2 a, float b)
+  {
+    return {a.x / b, a.y / b};
+  }
+
+  friend float2 operator*(float a, float2 b)
+  {
+    return b * a;
+  }
+
+  friend std::ostream &operator<<(std::ostream &stream, float2 v)
+  {
+    stream << "(" << v.x << ", " << v.y << ")";
+    return stream;
+  }
+};
+
+}  // namespace BLI
+
+#endif /* __BLI_FLOAT2_H__ */
diff --git a/source/blender/blenlib/BLI_math_cxx.h b/source/blender/blenlib/BLI_math_cxx.h
index 177a2a885cb..59becd4c9ba 100644
--- a/source/blender/blenlib/BLI_math_cxx.h
+++ b/source/blender/blenlib/BLI_math_cxx.h
@@ -29,75 +29,13 @@
 #include "BLI_math_vector.h"
 #include "BLI_math_matrix.h"
 #include "BLI_float3.h"
+#include "BLI_float2.h"
 
 namespace BLI {
 
-struct float2;
 struct rgba_f;
 struct rgba_b;
 
-struct float2 {
-  float x, y;
-
-  float2() = default;
-
-  float2(const float *ptr) : x{ptr[0]}, y{ptr[1]}
-  {
-  }
-
-  float2(float x, float y) : x(x), y(y)
-  {
-  }
-
-  float2(float3 other);
-
-  operator float *()
-  {
-    return &x;
-  }
-
-  float2 clamped(float min, float max)
-  {
-    return {std::min(std::max(x, min), max), std::min(std::max(y, min), max)};
-  }
-
-  float2 clamped_01()
-  {
-    return this->clamped(0, 1);
-  }
-
-  friend float2 operator+(float2 a, float2 b)
-  {
-    return {a.x + b.x, a.y + b.y};
-  }
-
-  friend float2 operator-(float2 a, float2 b)
-  {
-    return {a.x - b.x, a.y - b.y};
-  }
-
-  friend float2 operator*(float2 a, float b)
-  {
-    return {a.x * b, a.y * b};
-  }
-
-  friend float2 operator/(float2 a, float b)
-  {
-    return {a.x / b, a.y / b};
-  }
-
-  friend float2 operator*(float a, float2 b)
-  {
-    return b * a;
-  }
-
-  friend std::ostream &operator<<(std::ostream &stream, float2 v)
-  {
-    stream << "(" << v.x << ", " << v.y << ")";
-    return stream;
-  }
-};
-
 struct float4x4 {
   float values[4][4];



More information about the Bf-blender-cvs mailing list