Changeset View
Changeset View
Standalone View
Standalone View
source/blender/blenkernel/intern/attribute_math_test.cc
- This file was added.
| #include "BKE_attribute_math.hh" | |||||
| #include "BKE_type_conversions.hh" | |||||
| #include "BLI_vector_set.hh" | |||||
| #include "testing/testing.h" | |||||
| #include "CLG_log.h" | |||||
| namespace blender::bke::tests { | |||||
| TEST(default_mixer, attributes_type_accumulate_finalize) | |||||
| { | |||||
| const int size = 10; | |||||
| const int mixing_number = 10; | |||||
| Array<eCustomDataType> attribute_types( | |||||
| {CD_PROP_BOOL, CD_PROP_FLOAT, CD_PROP_FLOAT2, CD_PROP_FLOAT3, CD_PROP_INT32, CD_PROP_COLOR}); | |||||
| for (const eCustomDataType data_type : attribute_types) { | |||||
| attribute_math::convert_to_static_type(data_type, [&](auto dummy) { | |||||
| using T = decltype(dummy); | |||||
| Array<T> set_of_values(size); | |||||
| attribute_math::DefaultMixer<T> mixer(set_of_values.as_mutable_span()); | |||||
| VArray<int> indices = VArray<int>::ForFunc(size, [&](const int index) { return index; }); | |||||
| /* Set of random (index range) values such type. */ | |||||
| auto values = get_implicit_type_conversions().try_convert(indices, CPPType::get<T>()); | |||||
| /* Repeat mixing or each elements of Default Mixer by mixing_number times. */ | |||||
| for (const int index : values.index_range()) { | |||||
| for (const int step : IndexRange(mixing_number)) { | |||||
| T value; | |||||
| values.get(index, &value); | |||||
| mixer.mix_in(index, value, 1.0f); | |||||
| } | |||||
| } | |||||
| /* First value always is equal. */ | |||||
| for (const int index : IndexRange(1, values.size() - 1)) { | |||||
| T value; | |||||
| values.get(index, &value); | |||||
| EXPECT_NE(set_of_values[index], value) | |||||
| << "Values after " << mixing_number << " count mixing not valid at " << index | |||||
| << " index." | |||||
| << " For type " << attribute_math::default_name<T>(); | |||||
| } | |||||
| /* Mixer for cumulative types (itn, bol) requires the use of finalize to optimize | |||||
| * performance. */ | |||||
| mixer.finalize(); | |||||
| /* | |||||
| * Finalize divde each elements of DefaultMixer by count (summ of 1.0f factors x | |||||
| * mixing_number) And after the DefaultMixer will contain index value. | |||||
| */ | |||||
| for (const int index : values.index_range()) { | |||||
| T value; | |||||
| values.get(index, &value); | |||||
| EXPECT_EQ(set_of_values[index], value) | |||||
| << "Values after mixing and finalize not valid at " << index << " index." | |||||
| << " For type " << attribute_math::default_name<T>(); | |||||
| } | |||||
| }); | |||||
| } | |||||
| } | |||||
| } // namespace blender::bke::tests | |||||
| No newline at end of file | |||||