From 77f8a79a96a84b929aaebc1830fc2ff688782d70 Mon Sep 17 00:00:00 2001 From: Hans Goudey Date: Fri, 23 Feb 2024 12:32:35 -0500 Subject: [PATCH] Cleanup: Use named function for math::Axis char constructor It was too easy for implicit conversions to use this constructor by mistake, when values are often 0,1,2 in enum properties. --- source/blender/blenlib/BLI_math_basis_types.hh | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/source/blender/blenlib/BLI_math_basis_types.hh b/source/blender/blenlib/BLI_math_basis_types.hh index 49ed8d4a86c..4bb4afbd3fd 100644 --- a/source/blender/blenlib/BLI_math_basis_types.hh +++ b/source/blender/blenlib/BLI_math_basis_types.hh @@ -61,9 +61,11 @@ class Axis { constexpr Axis(const Value axis) : axis_(axis){}; /** Convert an uppercase axis character 'X', 'Y' or 'Z' to an enum value. */ - constexpr explicit Axis(char axis_char) : axis_(static_cast(axis_char - 'X')) + constexpr static Axis from_char(char axis_char) { - BLI_assert(Value::X <= axis_ && axis_ <= Value::Z); + const Axis axis = static_cast(axis_char - 'X'); + BLI_assert(int(Value::X) <= axis.as_int() && axis.as_int() <= int(Value::Z)); + return axis; } /** Allow casting from DNA enums stored as short / int. */ @@ -180,12 +182,12 @@ class AxisSigned { friend std::ostream &operator<<(std::ostream &stream, const AxisSigned axis); }; -constexpr static bool operator<=(const Axis::Value a, const Axis::Value b) +constexpr bool operator<=(const Axis::Value a, const Axis::Value b) { return int(a) <= int(b); } -constexpr static bool operator<=(const AxisSigned::Value a, const AxisSigned::Value b) +constexpr bool operator<=(const AxisSigned::Value a, const AxisSigned::Value b) { return int(a) <= int(b); }