43 if (std::any_of(sizes_ptr, sizes_ptr + sizes_num, [](
const int size) {
return size < 1; })) {
49 curves.tag_topology_changed();
53static std::optional<IndexMask> rna_indices_to_mask(
const IndexRange universe,
54 const int *indices_ptr,
55 const int indices_num,
62 const Span<int> indices(indices_ptr, indices_num);
63 if (std::any_of(indices.begin(),
65 [&](
const int index) { return !universe.contains(index); }))
70 if (!std::is_sorted(indices.begin(), indices.end())) {
74 if (std::adjacent_find(indices.begin(), indices.end(), std::greater_equal<>()) != indices.end())
84 const int *indices_ptr,
85 const int indices_num)
88 const std::optional<IndexMask> curves_to_delete = rna_indices_to_mask(
89 curves.curves_range(), indices_ptr, indices_num, *reports, memory);
90 if (!curves_to_delete) {
93 curves.remove_curves(*curves_to_delete, {});
101 const int *indices_ptr,
102 const int indices_num)
104 const Span<int> new_sizes(sizes_ptr, sizes_num);
105 if (std::any_of(new_sizes.begin(), new_sizes.end(), [](
const int size) { return size < 1; })) {
110 const std::optional<IndexMask> curves_to_resize = rna_indices_to_mask(
111 curves.curves_range(), indices_ptr, indices_num, *reports, memory);
112 if (!curves_to_resize) {
115 if (curves_to_resize->size() != sizes_num) {
125 const int *reorder_indices_ptr,
126 const int reorder_indices_num)
128 const Span<int> new_to_old_indices_map(reorder_indices_ptr, reorder_indices_num);
129 if (
curves.curves_num() != reorder_indices_num) {
131 reports,
RPT_ERROR,
"Length of reorder indices must be the same as the number of curves");
134 if (std::any_of(new_to_old_indices_map.begin(),
135 new_to_old_indices_map.end(),
136 [&](
const int index) { return !curves.curves_range().contains(index); }))
141 if (
Set(new_to_old_indices_map).
size() != reorder_indices_num) {
152 const int *indices_ptr,
153 const int indices_num)
156 const std::optional<IndexMask> selection = rna_indices_to_mask(
157 curves.curves_range(), indices_ptr, indices_num, *reports, memory);
167static void rna_Curves_add_curves(
Curves *curves_id,
173 if (!rna_CurvesGeometry_add_curves(
curves, reports, sizes, sizes_num)) {
178 if (curves_id->id.us > 0) {
184static void rna_Curves_remove_curves(
Curves *curves_id,
186 const int *indices_ptr,
187 const int indices_num)
190 if (!rna_CurvesGeometry_remove_curves(
curves, reports, indices_ptr, indices_num)) {
195 if (curves_id->id.us > 0) {
201static void rna_Curves_resize_curves(
Curves *curves_id,
203 const int *sizes_ptr,
205 const int *indices_ptr,
206 const int indices_num)
209 if (!rna_CurvesGeometry_resize_curves(
210 curves, reports, sizes_ptr, sizes_num, indices_ptr, indices_num))
216 if (curves_id->id.us > 0) {
222static void rna_Curves_reorder_curves(
Curves *curves_id,
224 const int *reorder_indices_ptr,
225 const int reorder_indices_num)
228 if (!rna_CurvesGeometry_reorder_curves(
229 curves, reports, reorder_indices_ptr, reorder_indices_num))
235 if (curves_id->id.us > 0) {
241static void rna_Curves_set_types(
Curves *curves_id,
244 const int *indices_ptr,
245 const int indices_num)
248 if (!rna_CurvesGeometry_set_types(
curves, reports, type, indices_ptr, indices_num)) {
252 if (curves_id->id.us > 0) {
258static const char *rna_Curves_unit_test_compare(
Curves *curves1,
Curves *curves2,
float threshold)
263 curves1->geometry.wrap(), curves2->geometry.wrap(), threshold);
292 "The number of points in each curve",
299 "Remove all curves. If indices are provided, remove only the "
300 "curves with the given indices.");
309 "The indices of the curves to remove",
317 "Resize all existing curves. If indices are provided, resize only the curves with the given "
318 "indices. If the new size for a curve is smaller, the curve is trimmed. If "
319 "the new size for a curve is larger, the new end values are default initialized.");
328 "The number of points in each curve",
339 "The indices of the curves to resize",
344 func =
RNA_def_function(srna,
"reorder_curves",
"rna_Curves_reorder_curves");
354 "The new index for each of the curves",
361 "Set the curve type. If indices are provided, set only the "
362 "types with the given curve indices.");
372 "The indices of the curves to resize",
377 func =
RNA_def_function(srna,
"unit_test_compare",
"rna_Curves_unit_test_compare");
385 "Comparison tolerance threshold",
390 func,
"result",
"nothing", 64,
"Return value",
"String description of result of comparison");
Low-level operations for curves.
static IndexMask from_indices(Span< T > indices, LinearAllocator<> &memory)
Set(Allocator allocator={}) noexcept
std::optional< GeoMismatch > compare_curves(const CurvesGeometry &curves1, const CurvesGeometry &curves2, float threshold)
Checks if the two curves geometries are different, returning the type of mismatch if any....
const char * mismatch_to_string(const GeoMismatch &mismatch)
int size(const AssetLibraryReference *library_reference)
void resize_curves(bke::CurvesGeometry &curves, const IndexMask &curves_to_resize, const Span< int > new_sizes)
void add_curves(bke::CurvesGeometry &curves, const Span< int > new_sizes)
void reorder_curves(bke::CurvesGeometry &curves, const Span< int > old_by_new_indices_map)
void WM_main_add_notifier(uint type, void *reference)
PropertyRNA * RNA_def_string(StructOrFunctionRNA *cont_, const char *identifier, const char *default_value, const int maxlen, const char *ui_name, const char *ui_description)
void RNA_def_function_ui_description(FunctionRNA *func, const char *description)
const EnumPropertyItem rna_enum_curves_type_items[]
PropertyRNA * RNA_def_enum(StructOrFunctionRNA *cont_, const char *identifier, const EnumPropertyItem *items, const int default_value, const char *ui_name, const char *ui_description)
PropertyRNA * RNA_def_pointer(StructOrFunctionRNA *cont_, const char *identifier, const char *type, const char *ui_name, const char *ui_description)
PropertyRNA * RNA_def_float_factor(StructOrFunctionRNA *cont_, const char *identifier, const float default_value, const float hardmin, const float hardmax, const char *ui_name, const char *ui_description, const float softmin, const float softmax)
void RNA_def_parameter_flags(PropertyRNA *prop, PropertyFlag flag_property, ParameterFlag flag_parameter)
void DEG_id_tag_update(ID *id, unsigned int flags)
void BKE_report(ReportList *reports, eReportType type, const char *message)
void RNA_def_function_return(FunctionRNA *func, PropertyRNA *ret)
FunctionRNA * RNA_def_function(StructRNA *srna, const char *identifier_c_str, const char *call)
void RNA_api_curves(StructRNA *srna)
void RNA_def_function_flag(FunctionRNA *func, FunctionFlag flag)
PropertyRNA * RNA_def_int_array(StructOrFunctionRNA *cont_, const char *identifier, const int len, const int *default_value, const int hardmin, const int hardmax, const char *ui_name, const char *ui_description, const int softmin, const int softmax)