Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHans Goudey <h.goudey@me.com>2021-10-04 03:52:59 +0300
committerHans Goudey <h.goudey@me.com>2021-10-04 03:52:59 +0300
commitdfdc9c62199ebb77007a59aa8e57aba1cb6988de (patch)
tree4572b44600de2c87700d64d69d98e201cdfaa8a2 /source/blender/blenkernel/intern/curveprofile.cc
parentb6195f66643be6604a4dc1072ead53d1567f6795 (diff)
Cleanup: Make more functions static
This simplifies the surface of the API for a CurveProfile.
Diffstat (limited to 'source/blender/blenkernel/intern/curveprofile.cc')
-rw-r--r--source/blender/blenkernel/intern/curveprofile.cc259
1 files changed, 129 insertions, 130 deletions
diff --git a/source/blender/blenkernel/intern/curveprofile.cc b/source/blender/blenkernel/intern/curveprofile.cc
index 9a7a8f7329f..78ec05838c2 100644
--- a/source/blender/blenkernel/intern/curveprofile.cc
+++ b/source/blender/blenkernel/intern/curveprofile.cc
@@ -44,6 +44,21 @@
/** \name Data Handling
* \{ */
+/**
+ * Returns a pointer to a newly allocated curve profile, using the given preset.
+ */
+struct CurveProfile *BKE_curveprofile_add(eCurveProfilePresets preset)
+{
+ CurveProfile *profile = (CurveProfile *)MEM_callocN(sizeof(CurveProfile), __func__);
+
+ BKE_curveprofile_set_defaults(profile);
+ profile->preset = preset;
+ BKE_curveprofile_reset(profile);
+ BKE_curveprofile_update(profile, 0);
+
+ return profile;
+}
+
void BKE_curveprofile_free_data(CurveProfile *profile)
{
MEM_SAFE_FREE(profile->path);
@@ -676,7 +691,7 @@ static void calculate_path_handles(CurveProfilePoint *path, int path_len)
}
/**
- * Helper function for 'BKE_curveprofile_create_samples.' Calculates the angle between the
+ * Helper function for #create_samples. Calculates the angle between the
* handles on the inside of the edge starting at index i. A larger angle means the edge is
* more curved.
* \param i_edge: The start index of the edge to calculate the angle for.
@@ -702,7 +717,7 @@ struct CurvatureSortPoint {
};
/**
- * Helper function for 'BKE_curveprofile_create_samples' for sorting edges based on curvature.
+ * Helper function for #create_samples for sorting edges based on curvature.
*/
static int sort_points_curvature(const void *in_a, const void *in_b)
{
@@ -729,10 +744,10 @@ static int sort_points_curvature(const void *in_a, const void *in_b)
* n_segments. Fill the array with the sampled locations and if the point corresponds to a
* control point, its handle type.
*/
-void BKE_curveprofile_create_samples(CurveProfile *profile,
- int n_segments,
- bool sample_straight_edges,
- CurveProfilePoint *r_samples)
+static void create_samples(CurveProfile *profile,
+ int n_segments,
+ bool sample_straight_edges,
+ CurveProfilePoint *r_samples)
{
CurveProfilePoint *path = profile->path;
int totpoints = profile->path_len;
@@ -856,51 +871,6 @@ void BKE_curveprofile_create_samples(CurveProfile *profile,
}
/**
- * Creates a higher resolution table by sampling the curved points.
- * This table is used for display and evenly spaced evaluation.
- */
-static void curveprofile_make_table(CurveProfile *profile)
-{
- int n_samples = BKE_curveprofile_table_size(profile);
- CurveProfilePoint *new_table = (CurveProfilePoint *)MEM_callocN(
- sizeof(CurveProfilePoint) * (n_samples + 1), __func__);
-
- BKE_curveprofile_create_samples(profile, n_samples - 1, false, new_table);
- /* Manually add last point at the end of the profile */
- new_table[n_samples - 1].x = 0.0f;
- new_table[n_samples - 1].y = 1.0f;
-
- MEM_SAFE_FREE(profile->table);
- profile->table = new_table;
-}
-
-/**
- * Creates the table of points used for displaying a preview of the sampled segment locations on
- * the widget itself.
- */
-static void curveprofile_make_segments_table(CurveProfile *profile)
-{
- int n_samples = profile->segments_len;
- if (n_samples <= 0) {
- return;
- }
- CurveProfilePoint *new_table = (CurveProfilePoint *)MEM_callocN(
- sizeof(CurveProfilePoint) * (n_samples + 1), __func__);
-
- if (profile->flag & PROF_SAMPLE_EVEN_LENGTHS) {
- /* Even length sampling incompatible with only straight edge sampling for now. */
- BKE_curveprofile_create_samples_even_spacing(profile, n_samples, new_table);
- }
- else {
- BKE_curveprofile_create_samples(
- profile, n_samples, profile->flag & PROF_SAMPLE_STRAIGHT_EDGES, new_table);
- }
-
- MEM_SAFE_FREE(profile->segments);
- profile->segments = new_table;
-}
-
-/**
* Sets the default settings and clip range for the profile widget.
* Does not generate either table.
*/
@@ -925,82 +895,6 @@ void BKE_curveprofile_set_defaults(CurveProfile *profile)
}
/**
- * Returns a pointer to a newly allocated curve profile, using the given preset.
- */
-struct CurveProfile *BKE_curveprofile_add(eCurveProfilePresets preset)
-{
- CurveProfile *profile = (CurveProfile *)MEM_callocN(sizeof(CurveProfile), __func__);
-
- BKE_curveprofile_set_defaults(profile);
- profile->preset = preset;
- BKE_curveprofile_reset(profile);
- curveprofile_make_table(profile);
-
- return profile;
-}
-
-/**
- * Should be called after the widget is changed. Does profile and remove double checks and more
- * importantly, recreates the display / evaluation and segments tables.
- * \param update_flags: Bitfield with fields defined in header file. Controls removing doubles and
- * clipping.
- */
-void BKE_curveprofile_update(CurveProfile *profile, const int update_flags)
-{
- CurveProfilePoint *points = profile->path;
- rctf *clipr = &profile->clip_rect;
-
- profile->changed_timestamp++;
-
- /* Clamp with the clipping rect in case something got past. */
- if (profile->flag & PROF_USE_CLIP) {
- /* Move points inside the clip rectangle. */
- if (update_flags & PROF_UPDATE_CLIP) {
- for (int i = 0; i < profile->path_len; i++) {
- points[i].x = clamp_f(points[i].x, clipr->xmin, clipr->xmax);
- points[i].y = clamp_f(points[i].y, clipr->ymin, clipr->ymax);
-
- /* Extra sanity assert to make sure the points have the right profile pointer. */
- BLI_assert(points[i].profile == profile);
- }
- }
- /* Ensure zoom-level respects clipping. */
- if (BLI_rctf_size_x(&profile->view_rect) > BLI_rctf_size_x(&profile->clip_rect)) {
- profile->view_rect.xmin = profile->clip_rect.xmin;
- profile->view_rect.xmax = profile->clip_rect.xmax;
- }
- if (BLI_rctf_size_y(&profile->view_rect) > BLI_rctf_size_y(&profile->clip_rect)) {
- profile->view_rect.ymin = profile->clip_rect.ymin;
- profile->view_rect.ymax = profile->clip_rect.ymax;
- }
- }
-
- /* Remove doubles with a threshold set at 1% of default range. */
- float thresh = pow2f(0.01f * BLI_rctf_size_x(clipr));
- if (update_flags & PROF_UPDATE_REMOVE_DOUBLES && profile->path_len > 2) {
- for (int i = 0; i < profile->path_len - 1; i++) {
- if (len_squared_v2v2(&points[i].x, &points[i + 1].x) < thresh) {
- if (i == 0) {
- BKE_curveprofile_remove_point(profile, &points[1]);
- }
- else {
- BKE_curveprofile_remove_point(profile, &points[i]);
- }
- break; /* Assumes 1 deletion per update call is ok. */
- }
- }
- }
-
- /* Create the high resolution table for drawing and some evaluation functions. */
- curveprofile_make_table(profile);
-
- /* Store a table of samples for the segment locations for a preview and the table's user. */
- if (profile->segments_len > 0) {
- curveprofile_make_segments_table(profile);
- }
-}
-
-/**
* Refreshes the higher resolution table sampled from the input points. A call to this or
* #BKE_curveprofile_update is needed before evaluation functions that use the table.
* Also sets the number of segments used for the display preview of the locations
@@ -1052,9 +946,9 @@ static float curveprofile_total_length(const CurveProfile *profile)
* \note Working, but would conflict with "Sample Straight Edges" option, so this is unused for
* now.
*/
-void BKE_curveprofile_create_samples_even_spacing(CurveProfile *profile,
- int n_segments,
- CurveProfilePoint *r_samples)
+static void create_samples_even_spacing(CurveProfile *profile,
+ int n_segments,
+ CurveProfilePoint *r_samples)
{
const float total_length = curveprofile_total_length(profile);
const float segment_length = total_length / n_segments;
@@ -1103,6 +997,111 @@ void BKE_curveprofile_create_samples_even_spacing(CurveProfile *profile,
}
/**
+ * Creates a higher resolution table by sampling the curved points.
+ * This table is used for display and evenly spaced evaluation.
+ */
+static void curveprofile_make_table(CurveProfile *profile)
+{
+ int n_samples = BKE_curveprofile_table_size(profile);
+ CurveProfilePoint *new_table = (CurveProfilePoint *)MEM_callocN(
+ sizeof(CurveProfilePoint) * (n_samples + 1), __func__);
+
+ create_samples(profile, n_samples - 1, false, new_table);
+ /* Manually add last point at the end of the profile */
+ new_table[n_samples - 1].x = 0.0f;
+ new_table[n_samples - 1].y = 1.0f;
+
+ MEM_SAFE_FREE(profile->table);
+ profile->table = new_table;
+}
+
+/**
+ * Creates the table of points used for displaying a preview of the sampled segment locations on
+ * the widget itself.
+ */
+static void curveprofile_make_segments_table(CurveProfile *profile)
+{
+ int n_samples = profile->segments_len;
+ if (n_samples <= 0) {
+ return;
+ }
+ CurveProfilePoint *new_table = (CurveProfilePoint *)MEM_callocN(
+ sizeof(CurveProfilePoint) * (n_samples + 1), __func__);
+
+ if (profile->flag & PROF_SAMPLE_EVEN_LENGTHS) {
+ /* Even length sampling incompatible with only straight edge sampling for now. */
+ create_samples_even_spacing(profile, n_samples, new_table);
+ }
+ else {
+ create_samples(profile, n_samples, profile->flag & PROF_SAMPLE_STRAIGHT_EDGES, new_table);
+ }
+
+ MEM_SAFE_FREE(profile->segments);
+ profile->segments = new_table;
+}
+
+/**
+ * Should be called after the widget is changed. Does profile and remove double checks and more
+ * importantly, recreates the display / evaluation and segments tables.
+ * \param update_flags: Bitfield with fields defined in header file. Controls removing doubles and
+ * clipping.
+ */
+void BKE_curveprofile_update(CurveProfile *profile, const int update_flags)
+{
+ CurveProfilePoint *points = profile->path;
+ rctf *clipr = &profile->clip_rect;
+
+ profile->changed_timestamp++;
+
+ /* Clamp with the clipping rect in case something got past. */
+ if (profile->flag & PROF_USE_CLIP) {
+ /* Move points inside the clip rectangle. */
+ if (update_flags & PROF_UPDATE_CLIP) {
+ for (int i = 0; i < profile->path_len; i++) {
+ points[i].x = clamp_f(points[i].x, clipr->xmin, clipr->xmax);
+ points[i].y = clamp_f(points[i].y, clipr->ymin, clipr->ymax);
+
+ /* Extra sanity assert to make sure the points have the right profile pointer. */
+ BLI_assert(points[i].profile == profile);
+ }
+ }
+ /* Ensure zoom-level respects clipping. */
+ if (BLI_rctf_size_x(&profile->view_rect) > BLI_rctf_size_x(&profile->clip_rect)) {
+ profile->view_rect.xmin = profile->clip_rect.xmin;
+ profile->view_rect.xmax = profile->clip_rect.xmax;
+ }
+ if (BLI_rctf_size_y(&profile->view_rect) > BLI_rctf_size_y(&profile->clip_rect)) {
+ profile->view_rect.ymin = profile->clip_rect.ymin;
+ profile->view_rect.ymax = profile->clip_rect.ymax;
+ }
+ }
+
+ /* Remove doubles with a threshold set at 1% of default range. */
+ float thresh = pow2f(0.01f * BLI_rctf_size_x(clipr));
+ if (update_flags & PROF_UPDATE_REMOVE_DOUBLES && profile->path_len > 2) {
+ for (int i = 0; i < profile->path_len - 1; i++) {
+ if (len_squared_v2v2(&points[i].x, &points[i + 1].x) < thresh) {
+ if (i == 0) {
+ BKE_curveprofile_remove_point(profile, &points[1]);
+ }
+ else {
+ BKE_curveprofile_remove_point(profile, &points[i]);
+ }
+ break; /* Assumes 1 deletion per update call is ok. */
+ }
+ }
+ }
+
+ /* Create the high resolution table for drawing and some evaluation functions. */
+ curveprofile_make_table(profile);
+
+ /* Store a table of samples for the segment locations for a preview and the table's user. */
+ if (profile->segments_len > 0) {
+ curveprofile_make_segments_table(profile);
+ }
+}
+
+/**
* Does a single evaluation along the profile's path.
* Travels down (length_portion * path) length and returns the position at that point.
*