Refactor: rename BKE_fcurve_bezt_shrink to ..._resize and allow growing

The `BKE_fcurve_bezt_shrink()` function had an artificial limitation to
only allow shrinking the `bezt` array. That limitation is now removed,
and therefore the function renamed to `BKE_fcurve_bezt_resize()`.

A note was added to the documentation that newly added array elements
should be initialized by the caller.

Pull Request: https://projects.blender.org/blender/blender/pulls/134864
This commit is contained in:
Sybren A. Stüvel
2025-02-20 15:52:26 +01:00
parent 2185143fc2
commit 94563dedca
2 changed files with 9 additions and 5 deletions

View File

@@ -478,10 +478,15 @@ bool BKE_fcurve_bezt_subdivide_handles(BezTriple *bezt,
/**
* Resize the FCurve 'bezt' array to fit the given length.
*
* This potentially moves the entire array, and thus pointers from before this call should be
* considered invalid / dangling.
*
* \param new_totvert: new number of elements in the FCurve's `bezt` array.
* Constraint: `0 <= new_totvert <= fcu->totvert`
*
* \note When increasing the size of the array, newly added elements are not initialized. That is
* left to the caller.
*/
void BKE_fcurve_bezt_shrink(FCurve *fcu, int new_totvert);
void BKE_fcurve_bezt_resize(FCurve *fcu, int new_totvert);
/**
* Merge the two given BezTriple arrays `a` and `b` into a newly allocated BezTriple array of size

View File

@@ -1607,10 +1607,9 @@ bool BKE_fcurve_bezt_subdivide_handles(BezTriple *bezt,
return true;
}
void BKE_fcurve_bezt_shrink(FCurve *fcu, const int new_totvert)
void BKE_fcurve_bezt_resize(FCurve *fcu, const int new_totvert)
{
BLI_assert(new_totvert >= 0);
BLI_assert(new_totvert <= fcu->totvert);
/* No early return when new_totvert == fcu->totvert. There is no way to know the intention of the
* caller, nor the history of the FCurve so far, so `fcu->bezt` may actually have allocated space
@@ -1939,7 +1938,7 @@ void BKE_fcurve_deduplicate_keys(FCurve *fcu)
}
}
BKE_fcurve_bezt_shrink(fcu, prev_bezt_index + 1);
BKE_fcurve_bezt_resize(fcu, prev_bezt_index + 1);
}
/** \} */