54 std::atomic<bool> success =
false;
56 const IndexRange points = src_points_by_curve[curve_i];
58 const bool is_cyclic = src_cyclic[curve_i];
59 const float epsilon = thresholds[curve_i];
63 const bool use_first_as_corner = !
is_cyclic && !corners[points.
first()];
64 const bool use_last_as_corner = !
is_cyclic && !corners[points.
last()];
66 if (use_first_as_corner) {
69 if (points.
size() > 2) {
71 if (corners[points[
i]]) {
76 if (use_last_as_corner) {
81 reinterpret_cast<uint *
>(src_corners.
data());
83 const uint8_t
flag = CURVE_FIT_CALC_HIGH_QUALIY | ((
is_cyclic) ? CURVE_FIT_CALC_CYCLIC : 0);
85 float *cubic_array =
nullptr;
86 uint32_t *orig_index_map =
nullptr;
87 uint32_t cubic_array_size = 0;
88 uint32_t *corner_index_array =
nullptr;
89 uint32_t corner_index_array_size = 0;
92 error = curve_fit_cubic_to_points_fl(curve_positions.
cast<
float>().data(),
93 curve_positions.
size(),
103 &corner_index_array_size);
106 error = curve_fit_cubic_to_points_refit_fl(curve_positions.
cast<
float>().data(),
107 curve_positions.
size(),
119 &corner_index_array_size);
124 dst_curve_sizes[curve_i] = points.
size();
129 success.store(
true, std::memory_order_relaxed);
131 const int dst_points_num = cubic_array_size;
134 dst_curve_sizes[curve_i] = dst_points_num;
139 corner_indices_per_curve[
pos] =
MutableSpan<int>(
reinterpret_cast<int *
>(corner_index_array),
140 corner_index_array_size);
141 original_indices_per_curve[
pos] =
MutableSpan<int>(
reinterpret_cast<int *
>(orig_index_map),
166 if (src_handles_left) {
174 src_points_by_curve, dst_points_by_curve, unselected_curves, src_positions, dst_positions);
175 if (src_handles_right) {
182 if (!src_handle_types_left.
is_empty()) {
186 src_handle_types_left,
187 dst_handle_types_left);
189 if (!src_handle_types_right.
is_empty()) {
193 src_handle_types_right,
194 dst_handle_types_right);
199 const IndexRange src_points = src_points_by_curve[curve_i];
200 const IndexRange dst_points = dst_points_by_curve[curve_i];
207 const IndexRange src_points = src_points_by_curve[curve_i];
208 const IndexRange dst_points = dst_points_by_curve[curve_i];
229 for (const int i : range) {
230 const int index = i * 3;
231 positions[i] = cubic_array[index + 1];
232 left_handles[i] = cubic_array[index];
233 right_handles[i] = cubic_array[index + 2];
237 const Span<int> corner_indices = corner_indices_per_curve[
pos];
243 const Span<int> original_indices = original_indices_per_curve[
pos];
245 for (const int i : range) {
246 old_by_new[i] = src_points[original_indices[i]];
251 dst_curves.update_curve_types();
253 bke::gather_attributes(
254 src_curves.attributes(),
255 bke::AttrDomain::Point,
256 bke::AttrDomain::Point,
257 bke::attribute_filter_with_skip_ref(
259 {
"position",
"handle_left",
"handle_right",
"handle_type_left",
"handle_type_right"}),
261 dst_curves.attributes_for_write());
265 free(cubic_array.data());
268 free(corner_indices.data());
271 free(original_indices.data());