Cleanup: use BKE_fcurve_ prefix for keyframing bezier functions
- BKE_bezt_subdivide_handles -> BKE_fcurve_bezt_subdivide_handles - binarysearch_bezt_index -> BKE_fcurve_bezt_binarysearch_index These functions are specific to F-Curves and don't make sense for other uses of BezTriple (curve-object data for e.g.) Also: - Move detailed doxygen comment above code, following code-style. - Mark bezt_add_to_cfra_elem unused.
This commit is contained in:
parent
8335c26119
commit
65965a892f
Notes:
blender-bot
2023-02-14 08:38:11 +01:00
Referenced by issue #89367, Running select_linked_pick with a negative index crashes Blender with an access violation
|
@ -57,8 +57,6 @@ typedef struct CfraElem {
|
|||
int sel;
|
||||
} CfraElem;
|
||||
|
||||
void bezt_add_to_cfra_elem(ListBase *lb, struct BezTriple *bezt);
|
||||
|
||||
/* ************** F-Curve Modifiers *************** */
|
||||
|
||||
/* F-Curve Modifier Type-Info (fmi):
|
||||
|
@ -229,7 +227,10 @@ struct FCurve *BKE_fcurve_find_by_rna_context_ui(struct bContext *C,
|
|||
/* Binary search algorithm for finding where to 'insert' BezTriple with given frame number.
|
||||
* Returns the index to insert at (data already at that index will be offset if replace is 0)
|
||||
*/
|
||||
int binarysearch_bezt_index(struct BezTriple array[], float frame, int arraylen, bool *r_replace);
|
||||
int BKE_fcurve_bezt_binarysearch_index(struct BezTriple array[],
|
||||
float frame,
|
||||
int arraylen,
|
||||
bool *r_replace);
|
||||
|
||||
/* get the time extents for F-Curve */
|
||||
bool BKE_fcurve_calc_range(
|
||||
|
@ -270,17 +271,11 @@ typedef enum eFCU_Cycle_Type {
|
|||
|
||||
eFCU_Cycle_Type BKE_fcurve_get_cycle_type(struct FCurve *fcu);
|
||||
|
||||
/** Adjust Bezier handles of all three given BezTriples, so that `bezt` can be inserted between
|
||||
* `prev` and `next` without changing the resulting curve shape.
|
||||
*
|
||||
* \param r_pdelta: return Y difference between `bezt` and the original curve value at its X
|
||||
* position.
|
||||
* \return Whether the split was succesful.
|
||||
*/
|
||||
bool BKE_bezt_subdivide_handles(struct BezTriple *bezt,
|
||||
struct BezTriple *prev,
|
||||
struct BezTriple *next,
|
||||
float *r_pdelta);
|
||||
/* Recompute handles to neatly subdivide the prev-next range at bezt. */
|
||||
bool BKE_fcurve_bezt_subdivide_handles(struct BezTriple *bezt,
|
||||
struct BezTriple *prev,
|
||||
struct BezTriple *next,
|
||||
float *r_pdelta);
|
||||
|
||||
/* -------- Curve Sanity -------- */
|
||||
|
||||
|
|
|
@ -502,7 +502,7 @@ FCurve *BKE_fcurve_find_by_rna_context_ui(bContext *C,
|
|||
* with optional argument for precision required.
|
||||
* Returns the index to insert at (data already at that index will be offset if replace is 0)
|
||||
*/
|
||||
static int binarysearch_bezt_index_ex(
|
||||
static int BKE_fcurve_bezt_binarysearch_index_ex(
|
||||
BezTriple array[], float frame, int arraylen, float threshold, bool *r_replace)
|
||||
{
|
||||
int start = 0, end = arraylen;
|
||||
|
@ -589,10 +589,14 @@ static int binarysearch_bezt_index_ex(
|
|||
/* Binary search algorithm for finding where to insert BezTriple. (for use by insert_bezt_fcurve)
|
||||
* Returns the index to insert at (data already at that index will be offset if replace is 0)
|
||||
*/
|
||||
int binarysearch_bezt_index(BezTriple array[], float frame, int arraylen, bool *r_replace)
|
||||
int BKE_fcurve_bezt_binarysearch_index(BezTriple array[],
|
||||
float frame,
|
||||
int arraylen,
|
||||
bool *r_replace)
|
||||
{
|
||||
/* this is just a wrapper which uses the default threshold */
|
||||
return binarysearch_bezt_index_ex(array, frame, arraylen, BEZT_BINARYSEARCH_THRESH, r_replace);
|
||||
return BKE_fcurve_bezt_binarysearch_index_ex(
|
||||
array, frame, arraylen, BEZT_BINARYSEARCH_THRESH, r_replace);
|
||||
}
|
||||
|
||||
/* ...................................... */
|
||||
|
@ -968,7 +972,7 @@ bool BKE_fcurve_is_keyframable(FCurve *fcu)
|
|||
* \{ */
|
||||
|
||||
/* add a BezTriple to a column */
|
||||
void bezt_add_to_cfra_elem(ListBase *lb, BezTriple *bezt)
|
||||
static void UNUSED_FUNCTION(bezt_add_to_cfra_elem)(ListBase *lb, BezTriple *bezt)
|
||||
{
|
||||
CfraElem *ce, *cen;
|
||||
|
||||
|
@ -1533,11 +1537,18 @@ static void berekeny(float f1, float f2, float f3, float f4, float *o, int b)
|
|||
}
|
||||
}
|
||||
|
||||
/* Recompute handles to neatly subdivide the prev-next range at bezt. */
|
||||
bool BKE_bezt_subdivide_handles(struct BezTriple *bezt,
|
||||
struct BezTriple *prev,
|
||||
struct BezTriple *next,
|
||||
float *r_pdelta)
|
||||
/**
|
||||
* Adjust Bezier handles of all three given BezTriples, so that `bezt` can be inserted between
|
||||
* `prev` and `next` without changing the resulting curve shape.
|
||||
*
|
||||
* \param r_pdelta: return Y difference between `bezt` and the original curve value at its X
|
||||
* position.
|
||||
* \return Whether the split was successful.
|
||||
*/
|
||||
bool BKE_fcurve_bezt_subdivide_handles(struct BezTriple *bezt,
|
||||
struct BezTriple *prev,
|
||||
struct BezTriple *next,
|
||||
float *r_pdelta)
|
||||
{
|
||||
/* The four points that make up this section of the Bezier curve. */
|
||||
const float *prev_coords = prev->vec[1];
|
||||
|
@ -1667,7 +1678,7 @@ static float fcurve_eval_keyframes_interpolate(FCurve *fcu, BezTriple *bezts, fl
|
|||
* Weird errors, like selecting the wrong keyframe range (see T39207), occur.
|
||||
* This lower bound was established in b888a32eee8147b028464336ad2404d8155c64dd.
|
||||
*/
|
||||
a = binarysearch_bezt_index_ex(bezts, evaltime, fcu->totvert, 0.0001, &exact);
|
||||
a = BKE_fcurve_bezt_binarysearch_index_ex(bezts, evaltime, fcu->totvert, 0.0001, &exact);
|
||||
bezt = bezts + a;
|
||||
|
||||
if (exact) {
|
||||
|
|
|
@ -50,8 +50,9 @@ TEST(evaluate_fcurve, OnKeys)
|
|||
EXPECT_NEAR(evaluate_fcurve(fcu, 3.0f), 19.0f, EPSILON); /* hits 'on or after last' function */
|
||||
|
||||
/* Also test within a specific time epsilon of the keys, as this was an issue in T39207.
|
||||
* This epsilon is just slightly smaller than the epsilon given to binarysearch_bezt_index_ex()
|
||||
* in fcurve_eval_between_keyframes(), so it should hit the "exact" code path. */
|
||||
* This epsilon is just slightly smaller than the epsilon given to
|
||||
* BKE_fcurve_bezt_binarysearch_index_ex() in fcurve_eval_between_keyframes(), so it should hit
|
||||
* the "exact" code path. */
|
||||
float time_epsilon = 0.00008f;
|
||||
EXPECT_NEAR(evaluate_fcurve(fcu, 2.0f - time_epsilon), 13.0f, EPSILON);
|
||||
EXPECT_NEAR(evaluate_fcurve(fcu, 2.0f + time_epsilon), 13.0f, EPSILON);
|
||||
|
@ -210,7 +211,7 @@ TEST(evaluate_fcurve, ExtrapolationBezierKeys)
|
|||
BKE_fcurve_free(fcu);
|
||||
}
|
||||
|
||||
TEST(fcurve_subdivide, BKE_bezt_subdivide_handles)
|
||||
TEST(fcurve_subdivide, BKE_fcurve_bezt_subdivide_handles)
|
||||
{
|
||||
FCurve *fcu = BKE_fcurve_create();
|
||||
|
||||
|
@ -245,7 +246,7 @@ TEST(fcurve_subdivide, BKE_bezt_subdivide_handles)
|
|||
|
||||
/* This should update the existing handles as well as the new BezTriple. */
|
||||
float y_delta;
|
||||
BKE_bezt_subdivide_handles(&beztr, &fcu->bezt[0], &fcu->bezt[1], &y_delta);
|
||||
BKE_fcurve_bezt_subdivide_handles(&beztr, &fcu->bezt[0], &fcu->bezt[1], &y_delta);
|
||||
|
||||
EXPECT_FLOAT_EQ(y_delta, 0.0f);
|
||||
|
||||
|
|
|
@ -407,7 +407,7 @@ int insert_bezt_fcurve(FCurve *fcu, const BezTriple *bezt, eInsertKeyFlags flag)
|
|||
/* are there already keyframes? */
|
||||
if (fcu->bezt) {
|
||||
bool replace;
|
||||
i = binarysearch_bezt_index(fcu->bezt, bezt->vec[1][0], fcu->totvert, &replace);
|
||||
i = BKE_fcurve_bezt_binarysearch_index(fcu->bezt, bezt->vec[1][0], fcu->totvert, &replace);
|
||||
|
||||
/* replace an existing keyframe? */
|
||||
if (replace) {
|
||||
|
@ -511,7 +511,7 @@ static void subdivide_nonauto_handles(const FCurve *fcu,
|
|||
|
||||
/* Subdivide the curve. */
|
||||
float delta;
|
||||
if (!BKE_bezt_subdivide_handles(bezt, prev, next, &delta)) {
|
||||
if (!BKE_fcurve_bezt_subdivide_handles(bezt, prev, next, &delta)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -1605,7 +1605,7 @@ static bool delete_keyframe_fcurve(AnimData *adt, FCurve *fcu, float cfra)
|
|||
int i;
|
||||
|
||||
/* try to find index of beztriple to get rid of */
|
||||
i = binarysearch_bezt_index(fcu->bezt, cfra, fcu->totvert, &found);
|
||||
i = BKE_fcurve_bezt_binarysearch_index(fcu->bezt, cfra, fcu->totvert, &found);
|
||||
if (found) {
|
||||
/* delete the key at the index (will sanity check + do recalc afterwards) */
|
||||
delete_fcurve_key(fcu, i, 1);
|
||||
|
@ -2648,7 +2648,7 @@ static int delete_key_button_exec(bContext *C, wmOperator *op)
|
|||
int i;
|
||||
|
||||
/* try to find index of beztriple to get rid of */
|
||||
i = binarysearch_bezt_index(fcu->bezt, cfra, fcu->totvert, &found);
|
||||
i = BKE_fcurve_bezt_binarysearch_index(fcu->bezt, cfra, fcu->totvert, &found);
|
||||
if (found) {
|
||||
/* delete the key at the index (will sanity check + do recalc afterwards) */
|
||||
delete_fcurve_key(fcu, i, 1);
|
||||
|
@ -2822,9 +2822,9 @@ bool fcurve_frame_has_keyframe(FCurve *fcu, float frame, short filter)
|
|||
/* we either include all regardless of muting, or only non-muted */
|
||||
if ((filter & ANIMFILTER_KEYS_MUTED) || (fcu->flag & FCURVE_MUTED) == 0) {
|
||||
bool replace;
|
||||
int i = binarysearch_bezt_index(fcu->bezt, frame, fcu->totvert, &replace);
|
||||
int i = BKE_fcurve_bezt_binarysearch_index(fcu->bezt, frame, fcu->totvert, &replace);
|
||||
|
||||
/* binarysearch_bezt_index will set replace to be 0 or 1
|
||||
/* BKE_fcurve_bezt_binarysearch_index will set replace to be 0 or 1
|
||||
* - obviously, 1 represents a match
|
||||
*/
|
||||
if (replace) {
|
||||
|
|
|
@ -1802,7 +1802,7 @@ static void pose_propagate_fcurve(
|
|||
* - if only doing selected keyframes, start from the first one
|
||||
*/
|
||||
if (mode != POSE_PROPAGATE_SELECTED_KEYS) {
|
||||
match = binarysearch_bezt_index(fcu->bezt, startFrame, fcu->totvert, &keyExists);
|
||||
match = BKE_fcurve_bezt_binarysearch_index(fcu->bezt, startFrame, fcu->totvert, &keyExists);
|
||||
|
||||
if (fcu->bezt[match].vec[1][0] < startFrame) {
|
||||
i = match + 1;
|
||||
|
|
|
@ -546,7 +546,8 @@ static void gather_frames_to_render_for_adt(const OGLRender *oglrender, const An
|
|||
}
|
||||
|
||||
bool found = false; /* Not interesting, we just want a starting point for the for-loop.*/
|
||||
int key_index = binarysearch_bezt_index(fcu->bezt, frame_start, fcu->totvert, &found);
|
||||
int key_index = BKE_fcurve_bezt_binarysearch_index(
|
||||
fcu->bezt, frame_start, fcu->totvert, &found);
|
||||
for (; key_index < fcu->totvert; key_index++) {
|
||||
BezTriple *bezt = &fcu->bezt[key_index];
|
||||
/* The frame range to render uses integer frame numbers, and the frame
|
||||
|
|
|
@ -498,7 +498,7 @@ PyObject *pyrna_struct_keyframe_delete(BPy_StructRNA *self, PyObject *args, PyOb
|
|||
int i;
|
||||
|
||||
/* try to find index of beztriple to get rid of */
|
||||
i = binarysearch_bezt_index(fcu->bezt, cfra, fcu->totvert, &found);
|
||||
i = BKE_fcurve_bezt_binarysearch_index(fcu->bezt, cfra, fcu->totvert, &found);
|
||||
if (found) {
|
||||
/* delete the key at the index (will sanity check + do recalc afterwards) */
|
||||
delete_fcurve_key(fcu, i, 1);
|
||||
|
|
Loading…
Reference in New Issue