Changeset View
Changeset View
Standalone View
Standalone View
source/blender/nodes/intern/type_conversions.cc
| Show First 20 Lines • Show All 57 Lines • ▼ Show 20 Lines | |||||
| static int32_t float_to_int(const float &a) | static int32_t float_to_int(const float &a) | ||||
| { | { | ||||
| return (int32_t)a; | return (int32_t)a; | ||||
| } | } | ||||
| static bool float_to_bool(const float &a) | static bool float_to_bool(const float &a) | ||||
| { | { | ||||
| return a > 0.0f; | return a > 0.0f; | ||||
| } | } | ||||
| static Color4f float_to_color(const float &a) | static ColorGeometry float_to_color(const float &a) | ||||
| { | { | ||||
| return Color4f(a, a, a, 1.0f); | return ColorGeometry(a, a, a, 1.0f); | ||||
| } | } | ||||
| static float3 float2_to_float3(const float2 &a) | static float3 float2_to_float3(const float2 &a) | ||||
| { | { | ||||
| return float3(a.x, a.y, 0.0f); | return float3(a.x, a.y, 0.0f); | ||||
| } | } | ||||
| static float float2_to_float(const float2 &a) | static float float2_to_float(const float2 &a) | ||||
| { | { | ||||
| return (a.x + a.y) / 2.0f; | return (a.x + a.y) / 2.0f; | ||||
| } | } | ||||
| static int float2_to_int(const float2 &a) | static int float2_to_int(const float2 &a) | ||||
| { | { | ||||
| return (int32_t)((a.x + a.y) / 2.0f); | return (int32_t)((a.x + a.y) / 2.0f); | ||||
| } | } | ||||
| static bool float2_to_bool(const float2 &a) | static bool float2_to_bool(const float2 &a) | ||||
| { | { | ||||
| return !is_zero_v2(a); | return !is_zero_v2(a); | ||||
| } | } | ||||
| static Color4f float2_to_color(const float2 &a) | static ColorGeometry float2_to_color(const float2 &a) | ||||
| { | { | ||||
| return Color4f(a.x, a.y, 0.0f, 1.0f); | return ColorGeometry(a.x, a.y, 0.0f, 1.0f); | ||||
| } | } | ||||
| static bool float3_to_bool(const float3 &a) | static bool float3_to_bool(const float3 &a) | ||||
| { | { | ||||
| return !is_zero_v3(a); | return !is_zero_v3(a); | ||||
| } | } | ||||
| static float float3_to_float(const float3 &a) | static float float3_to_float(const float3 &a) | ||||
| { | { | ||||
| return (a.x + a.y + a.z) / 3.0f; | return (a.x + a.y + a.z) / 3.0f; | ||||
| } | } | ||||
| static int float3_to_int(const float3 &a) | static int float3_to_int(const float3 &a) | ||||
| { | { | ||||
| return (int)((a.x + a.y + a.z) / 3.0f); | return (int)((a.x + a.y + a.z) / 3.0f); | ||||
| } | } | ||||
| static float2 float3_to_float2(const float3 &a) | static float2 float3_to_float2(const float3 &a) | ||||
| { | { | ||||
| return float2(a); | return float2(a); | ||||
| } | } | ||||
| static Color4f float3_to_color(const float3 &a) | static ColorGeometry float3_to_color(const float3 &a) | ||||
| { | { | ||||
| return Color4f(a.x, a.y, a.z, 1.0f); | return ColorGeometry(a.x, a.y, a.z, 1.0f); | ||||
| } | } | ||||
| static bool int_to_bool(const int32_t &a) | static bool int_to_bool(const int32_t &a) | ||||
| { | { | ||||
| return a > 0; | return a > 0; | ||||
| } | } | ||||
| static float int_to_float(const int32_t &a) | static float int_to_float(const int32_t &a) | ||||
| { | { | ||||
| return (float)a; | return (float)a; | ||||
| } | } | ||||
| static float2 int_to_float2(const int32_t &a) | static float2 int_to_float2(const int32_t &a) | ||||
| { | { | ||||
| return float2((float)a); | return float2((float)a); | ||||
| } | } | ||||
| static float3 int_to_float3(const int32_t &a) | static float3 int_to_float3(const int32_t &a) | ||||
| { | { | ||||
| return float3((float)a); | return float3((float)a); | ||||
| } | } | ||||
| static Color4f int_to_color(const int32_t &a) | static ColorGeometry int_to_color(const int32_t &a) | ||||
| { | { | ||||
| return Color4f((float)a, (float)a, (float)a, 1.0f); | return ColorGeometry((float)a, (float)a, (float)a, 1.0f); | ||||
| } | } | ||||
| static float bool_to_float(const bool &a) | static float bool_to_float(const bool &a) | ||||
| { | { | ||||
| return (bool)a; | return (bool)a; | ||||
| } | } | ||||
| static int32_t bool_to_int(const bool &a) | static int32_t bool_to_int(const bool &a) | ||||
| { | { | ||||
| return (int32_t)a; | return (int32_t)a; | ||||
| } | } | ||||
| static float2 bool_to_float2(const bool &a) | static float2 bool_to_float2(const bool &a) | ||||
| { | { | ||||
| return (a) ? float2(1.0f) : float2(0.0f); | return (a) ? float2(1.0f) : float2(0.0f); | ||||
| } | } | ||||
| static float3 bool_to_float3(const bool &a) | static float3 bool_to_float3(const bool &a) | ||||
| { | { | ||||
| return (a) ? float3(1.0f) : float3(0.0f); | return (a) ? float3(1.0f) : float3(0.0f); | ||||
| } | } | ||||
| static Color4f bool_to_color(const bool &a) | static ColorGeometry bool_to_color(const bool &a) | ||||
| { | { | ||||
| return (a) ? Color4f(1.0f, 1.0f, 1.0f, 1.0f) : Color4f(0.0f, 0.0f, 0.0f, 1.0f); | return (a) ? ColorGeometry(1.0f, 1.0f, 1.0f, 1.0f) : ColorGeometry(0.0f, 0.0f, 0.0f, 1.0f); | ||||
| } | } | ||||
| static bool color_to_bool(const Color4f &a) | static bool color_to_bool(const ColorGeometry &a) | ||||
| { | { | ||||
| return rgb_to_grayscale(a) > 0.0f; | return rgb_to_grayscale(a) > 0.0f; | ||||
| } | } | ||||
| static float color_to_float(const Color4f &a) | static float color_to_float(const ColorGeometry &a) | ||||
| { | { | ||||
| return rgb_to_grayscale(a); | return rgb_to_grayscale(a); | ||||
| } | } | ||||
| static int32_t color_to_int(const Color4f &a) | static int32_t color_to_int(const ColorGeometry &a) | ||||
| { | { | ||||
| return (int)rgb_to_grayscale(a); | return (int)rgb_to_grayscale(a); | ||||
| } | } | ||||
| static float2 color_to_float2(const Color4f &a) | static float2 color_to_float2(const ColorGeometry &a) | ||||
| { | { | ||||
| return float2(a.r, a.g); | return float2(a.r, a.g); | ||||
| } | } | ||||
| static float3 color_to_float3(const Color4f &a) | static float3 color_to_float3(const ColorGeometry &a) | ||||
| { | { | ||||
| return float3(a.r, a.g, a.b); | return float3(a.r, a.g, a.b); | ||||
| } | } | ||||
| static DataTypeConversions create_implicit_conversions() | static DataTypeConversions create_implicit_conversions() | ||||
| { | { | ||||
| DataTypeConversions conversions; | DataTypeConversions conversions; | ||||
| add_implicit_conversion<float, float2, float_to_float2>(conversions); | add_implicit_conversion<float, float2, float_to_float2>(conversions); | ||||
| add_implicit_conversion<float, float3, float_to_float3>(conversions); | add_implicit_conversion<float, float3, float_to_float3>(conversions); | ||||
| add_implicit_conversion<float, int32_t, float_to_int>(conversions); | add_implicit_conversion<float, int32_t, float_to_int>(conversions); | ||||
| add_implicit_conversion<float, bool, float_to_bool>(conversions); | add_implicit_conversion<float, bool, float_to_bool>(conversions); | ||||
| add_implicit_conversion<float, Color4f, float_to_color>(conversions); | add_implicit_conversion<float, ColorGeometry, float_to_color>(conversions); | ||||
| add_implicit_conversion<float2, float3, float2_to_float3>(conversions); | add_implicit_conversion<float2, float3, float2_to_float3>(conversions); | ||||
| add_implicit_conversion<float2, float, float2_to_float>(conversions); | add_implicit_conversion<float2, float, float2_to_float>(conversions); | ||||
| add_implicit_conversion<float2, int32_t, float2_to_int>(conversions); | add_implicit_conversion<float2, int32_t, float2_to_int>(conversions); | ||||
| add_implicit_conversion<float2, bool, float2_to_bool>(conversions); | add_implicit_conversion<float2, bool, float2_to_bool>(conversions); | ||||
| add_implicit_conversion<float2, Color4f, float2_to_color>(conversions); | add_implicit_conversion<float2, ColorGeometry, float2_to_color>(conversions); | ||||
| add_implicit_conversion<float3, bool, float3_to_bool>(conversions); | add_implicit_conversion<float3, bool, float3_to_bool>(conversions); | ||||
| add_implicit_conversion<float3, float, float3_to_float>(conversions); | add_implicit_conversion<float3, float, float3_to_float>(conversions); | ||||
| add_implicit_conversion<float3, int32_t, float3_to_int>(conversions); | add_implicit_conversion<float3, int32_t, float3_to_int>(conversions); | ||||
| add_implicit_conversion<float3, float2, float3_to_float2>(conversions); | add_implicit_conversion<float3, float2, float3_to_float2>(conversions); | ||||
| add_implicit_conversion<float3, Color4f, float3_to_color>(conversions); | add_implicit_conversion<float3, ColorGeometry, float3_to_color>(conversions); | ||||
| add_implicit_conversion<int32_t, bool, int_to_bool>(conversions); | add_implicit_conversion<int32_t, bool, int_to_bool>(conversions); | ||||
| add_implicit_conversion<int32_t, float, int_to_float>(conversions); | add_implicit_conversion<int32_t, float, int_to_float>(conversions); | ||||
| add_implicit_conversion<int32_t, float2, int_to_float2>(conversions); | add_implicit_conversion<int32_t, float2, int_to_float2>(conversions); | ||||
| add_implicit_conversion<int32_t, float3, int_to_float3>(conversions); | add_implicit_conversion<int32_t, float3, int_to_float3>(conversions); | ||||
| add_implicit_conversion<int32_t, Color4f, int_to_color>(conversions); | add_implicit_conversion<int32_t, ColorGeometry, int_to_color>(conversions); | ||||
| add_implicit_conversion<bool, float, bool_to_float>(conversions); | add_implicit_conversion<bool, float, bool_to_float>(conversions); | ||||
| add_implicit_conversion<bool, int32_t, bool_to_int>(conversions); | add_implicit_conversion<bool, int32_t, bool_to_int>(conversions); | ||||
| add_implicit_conversion<bool, float2, bool_to_float2>(conversions); | add_implicit_conversion<bool, float2, bool_to_float2>(conversions); | ||||
| add_implicit_conversion<bool, float3, bool_to_float3>(conversions); | add_implicit_conversion<bool, float3, bool_to_float3>(conversions); | ||||
| add_implicit_conversion<bool, Color4f, bool_to_color>(conversions); | add_implicit_conversion<bool, ColorGeometry, bool_to_color>(conversions); | ||||
| add_implicit_conversion<Color4f, bool, color_to_bool>(conversions); | add_implicit_conversion<ColorGeometry, bool, color_to_bool>(conversions); | ||||
| add_implicit_conversion<Color4f, float, color_to_float>(conversions); | add_implicit_conversion<ColorGeometry, float, color_to_float>(conversions); | ||||
| add_implicit_conversion<Color4f, int32_t, color_to_int>(conversions); | add_implicit_conversion<ColorGeometry, int32_t, color_to_int>(conversions); | ||||
| add_implicit_conversion<Color4f, float2, color_to_float2>(conversions); | add_implicit_conversion<ColorGeometry, float2, color_to_float2>(conversions); | ||||
| add_implicit_conversion<Color4f, float3, color_to_float3>(conversions); | add_implicit_conversion<ColorGeometry, float3, color_to_float3>(conversions); | ||||
| return conversions; | return conversions; | ||||
| } | } | ||||
| const DataTypeConversions &get_implicit_type_conversions() | const DataTypeConversions &get_implicit_type_conversions() | ||||
| { | { | ||||
| static const DataTypeConversions conversions = create_implicit_conversions(); | static const DataTypeConversions conversions = create_implicit_conversions(); | ||||
| return conversions; | return conversions; | ||||
| Show All 15 Lines | |||||