From abd2ee4a8d80d74d59604be7e11b507389f0778f Mon Sep 17 00:00:00 2001 From: Hans Goudey Date: Thu, 10 Dec 2020 09:31:42 -0600 Subject: Attribute Compare: Use the most complex data type instead of the least --- source/blender/nodes/geometry/node_geometry_util.cc | 14 +++++++------- source/blender/nodes/geometry/node_geometry_util.hh | 2 +- .../nodes/geometry/nodes/node_geo_attribute_compare.cc | 12 ++++++------ 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/source/blender/nodes/geometry/node_geometry_util.cc b/source/blender/nodes/geometry/node_geometry_util.cc index f9ded0e1995..6dccfa300d1 100644 --- a/source/blender/nodes/geometry/node_geometry_util.cc +++ b/source/blender/nodes/geometry/node_geometry_util.cc @@ -62,20 +62,20 @@ static int attribute_data_type_complexity(const CustomDataType data_type) } } -CustomDataType attribute_domain_lowest_complexity(Span data_types) +CustomDataType attribute_domain_highest_complexity(Span data_types) { - int lowest_complexity = INT_MAX; - CustomDataType least_complex_type = CD_PROP_BOOL; + int highest_complexity = INT_MIN; + CustomDataType most_complex_type = CD_PROP_COLOR; for (const CustomDataType data_type : data_types) { const int complexity = attribute_data_type_complexity(data_type); - if (complexity < lowest_complexity) { - lowest_complexity = complexity; - least_complex_type = data_type; + if (complexity > highest_complexity) { + highest_complexity = complexity; + most_complex_type = data_type; } } - return least_complex_type; + return most_complex_type; } } // namespace blender::nodes diff --git a/source/blender/nodes/geometry/node_geometry_util.hh b/source/blender/nodes/geometry/node_geometry_util.hh index b8728016230..44c9406c61c 100644 --- a/source/blender/nodes/geometry/node_geometry_util.hh +++ b/source/blender/nodes/geometry/node_geometry_util.hh @@ -43,6 +43,6 @@ void update_attribute_input_socket_availabilities(bNode &node, const StringRef name, const GeometryNodeAttributeInputMode mode); -CustomDataType attribute_domain_lowest_complexity(Span); +CustomDataType attribute_domain_highest_complexity(Span); } // namespace blender::nodes \ No newline at end of file diff --git a/source/blender/nodes/geometry/nodes/node_geo_attribute_compare.cc b/source/blender/nodes/geometry/nodes/node_geo_attribute_compare.cc index 7ec27bc85d6..972f536e2ee 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_attribute_compare.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_attribute_compare.cc @@ -221,12 +221,12 @@ static CustomDataType get_data_type(GeometryComponent &component, CustomDataType data_type_b = params.get_input_attribute_data_type( "B", component, CD_PROP_FLOAT); - /* Convert the input attributes to the same data type for the equality tests. Use the lower - * complexity attribute type because any other information would be arbitrary anyway.*/ - return attribute_domain_lowest_complexity(Span{data_type_a, data_type_b}); + /* Convert the input attributes to the same data type for the equality tests. Use the higher + * complexity attribute type, otherwise information necessary to the comparison may be lost. */ + return attribute_domain_highest_complexity({data_type_a, data_type_b}); } - /* Use float compare for every operation besides equality. (This might have to change). */ + /* Use float compare for every operation besides equality. */ return CD_PROP_FLOAT; } @@ -265,8 +265,8 @@ static void attribute_compare_calc(GeometryComponent &component, const GeoNodeEx BooleanWriteAttribute attribute_result_bool = std::move(attribute_result); MutableSpan result_span = attribute_result_bool.get_span(); - /* Use specific types for correct equality operations, but for other - * operations we can use* implicit conversions and float comparison. */ + /* Use specific types for correct equality operations, but for other operations we use implicit + * conversions and float comparison. In other words, the comparison is not element-wise. */ if (operation_is_equality(*node_storage)) { const float threshold = params.get_input("Threshold"); if (operation == NODE_FLOAT_COMPARE_EQUAL) { -- cgit v1.2.3