60 std::atomic<bool> success =
false;
63 const IndexRange points = src_points_by_curve[curve_i];
64 if (points.
size() < 2) {
65 dst_curve_sizes[curve_i] = points.
size();
70 const bool is_cyclic = src_cyclic[curve_i];
71 const float epsilon = thresholds[curve_i];
75 const bool use_first_as_corner = !is_cyclic && !corners[points.
first()];
76 const bool use_last_as_corner = !is_cyclic && !corners[points.
last()];
78 if (use_first_as_corner) {
81 if (points.
size() > 2) {
83 if (corners[points[i]]) {
88 if (use_last_as_corner) {
93 reinterpret_cast<uint *
>(src_corners.
data());
95 const uint8_t flag = CURVE_FIT_CALC_HIGH_QUALITY |
96 ((is_cyclic) ? CURVE_FIT_CALC_CYCLIC : 0);
98 float *cubic_array =
nullptr;
101 uint32_t *corner_index_array =
nullptr;
102 uint32_t corner_index_array_size = 0;
105 error = curve_fit_cubic_to_points_fl(curve_positions.
cast<
float>().data(),
106 curve_positions.
size(),
116 &corner_index_array_size);
119 error = curve_fit_cubic_to_points_refit_fl(curve_positions.
cast<
float>().data(),
120 curve_positions.
size(),
132 &corner_index_array_size);
137 dst_curve_sizes[curve_i] = points.
size();
142 success.store(
true, std::memory_order_relaxed);
144 const int dst_points_num = cubic_array_size;
147 dst_curve_sizes[curve_i] = dst_points_num;
153 reinterpret_cast<int *
>(corner_index_array), corner_index_array_size);
154 original_indices_per_curve[pos] =
MutableSpan<int>(
reinterpret_cast<int *
>(orig_index_map),
180 if (src_handles_left) {
188 src_points_by_curve, dst_points_by_curve, unselected_curves, src_positions, dst_positions);
189 if (src_handles_right) {
196 if (!src_handle_types_left.
is_empty()) {
200 src_handle_types_left,
201 dst_handle_types_left);
203 if (!src_handle_types_right.
is_empty()) {
207 src_handle_types_right,
208 dst_handle_types_right);
214 const IndexRange src_points = src_points_by_curve[curve_i];
215 const IndexRange dst_points = dst_points_by_curve[curve_i];
224 const IndexRange src_points = src_points_by_curve[curve_i];
225 const IndexRange dst_points = dst_points_by_curve[curve_i];
241 const Span<float3> cubic_array = cubic_array_per_curve[pos];
246 for (const int i : range) {
247 const int index = i * 3;
248 positions[i] = cubic_array[index + 1];
249 left_handles[i] = cubic_array[index];
250 right_handles[i] = cubic_array[index + 2];
254 const Span<int> corner_indices = corner_indices_per_curve[pos];
260 const Span<int> original_indices = original_indices_per_curve[pos];
262 for (const int i : range) {
263 old_by_new[i] = src_points[original_indices[i]];
269 dst_curves.update_curve_types();
272 src_curves.attributes(),
277 {
"position",
"handle_left",
"handle_right",
"handle_type_left",
"handle_type_right"}),
279 dst_curves.attributes_for_write());
282 for (MutableSpan<float3> cubic_array : cubic_array_per_curve) {
283 free(cubic_array.data());
286 free(corner_indices.data());
289 free(original_indices.data());