From b6195f66643be6604a4dc1072ead53d1567f6795 Mon Sep 17 00:00:00 2001 From: Hans Goudey Date: Sun, 3 Oct 2021 18:54:52 -0500 Subject: Cleanup: Replace macro with function --- source/blender/blenkernel/BKE_curveprofile.h | 2 ++ source/blender/blenkernel/intern/curveprofile.cc | 21 +++++++++++++++++---- source/blender/editors/interface/interface_draw.c | 6 +++--- .../blender/editors/interface/interface_handlers.c | 2 +- source/blender/makesdna/DNA_curveprofile_types.h | 7 ------- 5 files changed, 23 insertions(+), 15 deletions(-) diff --git a/source/blender/blenkernel/BKE_curveprofile.h b/source/blender/blenkernel/BKE_curveprofile.h index 88bac220eb3..62074a30612 100644 --- a/source/blender/blenkernel/BKE_curveprofile.h +++ b/source/blender/blenkernel/BKE_curveprofile.h @@ -75,6 +75,8 @@ void BKE_curveprofile_create_samples(struct CurveProfile *profile, bool sample_straight_edges, struct CurveProfilePoint *r_samples); +int BKE_curveprofile_table_size(const struct CurveProfile *profile); + void BKE_curveprofile_init(struct CurveProfile *profile, short segments_len); /* Called for a complete update of the widget after modifications */ diff --git a/source/blender/blenkernel/intern/curveprofile.cc b/source/blender/blenkernel/intern/curveprofile.cc index 282aa04e0fa..9a7a8f7329f 100644 --- a/source/blender/blenkernel/intern/curveprofile.cc +++ b/source/blender/blenkernel/intern/curveprofile.cc @@ -21,6 +21,8 @@ * \ingroup bke */ +#include + #include "MEM_guardedalloc.h" #include "DNA_curve_types.h" @@ -35,6 +37,9 @@ #include "BLO_read_write.h" +/** Number of points in high resolution table is dynamic up to a maximum. */ +#define PROF_TABLE_MAX 512 + /* -------------------------------------------------------------------- */ /** \name Data Handling * \{ */ @@ -569,6 +574,14 @@ void BKE_curveprofile_reset(CurveProfile *profile) /** \name Sampling and Evaluation * \{ */ +int BKE_curveprofile_table_size(const CurveProfile *profile) +{ + /** Number of table points per control point. */ + const int resolution = 16; + + return std::clamp((profile->path_len - 1) * resolution + 1, 0, PROF_TABLE_MAX); +} + /** * Helper for 'curve_profile_create' samples. * Returns whether both handles that make up the edge are vector handles. @@ -848,7 +861,7 @@ void BKE_curveprofile_create_samples(CurveProfile *profile, */ static void curveprofile_make_table(CurveProfile *profile) { - int n_samples = PROF_TABLE_LEN(profile->path_len); + int n_samples = BKE_curveprofile_table_size(profile); CurveProfilePoint *new_table = (CurveProfilePoint *)MEM_callocN( sizeof(CurveProfilePoint) * (n_samples + 1), __func__); @@ -1012,7 +1025,7 @@ void BKE_curveprofile_init(CurveProfile *profile, short segments_len) */ static float curveprofile_distance_to_next_table_point(const CurveProfile *profile, int i) { - BLI_assert(i < PROF_TABLE_LEN(profile->path_len)); + BLI_assert(i < BKE_curveprofile_table_size(profile)); return len_v2v2(&profile->table[i].x, &profile->table[i + 1].x); } @@ -1025,7 +1038,7 @@ static float curveprofile_distance_to_next_table_point(const CurveProfile *profi static float curveprofile_total_length(const CurveProfile *profile) { float total_length = 0; - for (int i = 0; i < PROF_TABLE_LEN(profile->path_len) - 1; i++) { + for (int i = 0; i < BKE_curveprofile_table_size(profile) - 1; i++) { total_length += len_v2v2(&profile->table[i].x, &profile->table[i + 1].x); } return total_length; @@ -1109,7 +1122,7 @@ void BKE_curveprofile_evaluate_length_portion(const CurveProfile *profile, float length_travelled = 0.0f; while (length_travelled < requested_length) { /* Check if we reached the last point before the final one. */ - if (i == PROF_TABLE_LEN(profile->path_len) - 2) { + if (i == BKE_curveprofile_table_size(profile) - 2) { break; } float new_length = curveprofile_distance_to_next_table_point(profile, i); diff --git a/source/blender/editors/interface/interface_draw.c b/source/blender/editors/interface/interface_draw.c index ebebf69bc11..e9404b0273d 100644 --- a/source/blender/editors/interface/interface_draw.c +++ b/source/blender/editors/interface/interface_draw.c @@ -1860,13 +1860,13 @@ void ui_draw_but_CURVEPROFILE(ARegion *region, /* Also add the last points on the right and bottom edges to close off the fill polygon. */ const bool add_left_tri = profile->view_rect.xmin < 0.0f; const bool add_bottom_tri = profile->view_rect.ymin < 0.0f; - uint tot_points = (uint)PROF_TABLE_LEN(profile->path_len) + 1 + add_left_tri + add_bottom_tri; + uint tot_points = (uint)BKE_curveprofile_table_size(profile) + 1 + add_left_tri + add_bottom_tri; const uint tot_triangles = tot_points - 2; /* Create array of the positions of the table's points. */ float(*table_coords)[2] = MEM_mallocN(sizeof(*table_coords) * tot_points, "table x coords"); - for (uint i = 0; i < (uint)PROF_TABLE_LEN(profile->path_len); - i++) { /* Only add the points from the table here. */ + for (uint i = 0; i < (uint)BKE_curveprofile_table_size(profile); i++) { + /* Only add the points from the table here. */ table_coords[i][0] = pts[i].x; table_coords[i][1] = pts[i].y; } diff --git a/source/blender/editors/interface/interface_handlers.c b/source/blender/editors/interface/interface_handlers.c index f0e3464a955..6ee563003ef 100644 --- a/source/blender/editors/interface/interface_handlers.c +++ b/source/blender/editors/interface/interface_handlers.c @@ -7587,7 +7587,7 @@ static int ui_do_but_CURVEPROFILE( dist_min_sq = square_f(U.dpi_fac * 8.0f); /* 8 pixel radius from each table point. */ /* Loop through the path's high resolution table and find what's near the click. */ - for (int i = 1; i <= PROF_TABLE_LEN(profile->path_len); i++) { + for (int i = 1; i <= BKE_curveprofile_table_size(profile); i++) { copy_v2_v2(f_xy_prev, f_xy); BLI_rctf_transform_pt_v(&but->rect, &profile->view_rect, f_xy, &table[i].x); diff --git a/source/blender/makesdna/DNA_curveprofile_types.h b/source/blender/makesdna/DNA_curveprofile_types.h index 7c76251adc3..447e94d2659 100644 --- a/source/blender/makesdna/DNA_curveprofile_types.h +++ b/source/blender/makesdna/DNA_curveprofile_types.h @@ -29,13 +29,6 @@ extern "C" { #endif -/** Number of points in high resolution table is dynamic up to a maximum. */ -#define PROF_TABLE_MAX 512 -/** Number of table points per control point. */ -#define PROF_RESOL 16 -/** Dynamic size of widget's high resolution table. Input should be profile->totpoint. */ -#define PROF_TABLE_LEN(n_pts) min_ii(PROF_TABLE_MAX, (((n_pts - 1)) * PROF_RESOL) + 1) - /** * Each control point that makes up the profile. * \note The flags use the same enum as Bezier curves, but they aren't guaranteed -- cgit v1.2.3