[Bf-blender-cvs] [2afbf00600c] soc-2019-bevel-profiles: Profile widget sampling bug fix, cleanup in file
Hans Goudey
noreply at git.blender.org
Fri Aug 16 01:26:19 CEST 2019
Commit: 2afbf00600c89ef7332111c89216b88e5e7a7c25
Author: Hans Goudey
Date: Thu Aug 15 19:25:10 2019 -0400
Branches: soc-2019-bevel-profiles
https://developer.blender.org/rB2afbf00600c89ef7332111c89216b88e5e7a7c25
Profile widget sampling bug fix, cleanup in file
- Extra samples are now correctly assigned to most curved edges.
- The first and last control points use their neighbor's handle type.
- Final cleanup and commenting of profile_widget.c
===================================================================
M source/blender/blenkernel/intern/profile_widget.c
M source/blender/editors/interface/interface_templates.c
===================================================================
diff --git a/source/blender/blenkernel/intern/profile_widget.c b/source/blender/blenkernel/intern/profile_widget.c
index cfe0dec94a8..1077f9efe82 100644
--- a/source/blender/blenkernel/intern/profile_widget.c
+++ b/source/blender/blenkernel/intern/profile_widget.c
@@ -41,40 +41,10 @@
#include "BKE_curve.h"
#include "BKE_fcurve.h"
-#define DEBUG_PRWDGT 0
-#define DEBUG_PRWDGT_TABLE 0
-#define DEBUG_PRWDGT_EVALUATE 0
-#define DEBUG_PRWDGT_REVERSE 0
-
-void BKE_profilewidget_set_defaults(ProfileWidget *prwdgt)
-{
-#if DEBUG_PRWDGT
- printf("PROFILEWIDGET SET DEFAULTS\n");
-#endif
- prwdgt->flag = PROF_USE_CLIP;
-
- BLI_rctf_init(&prwdgt->view_rect, 0.0f, 1.0f, 0.0f, 1.0f);
- prwdgt->clip_rect = prwdgt->view_rect;
-
- prwdgt->totpoint = 2;
- prwdgt->path = MEM_callocN(2 * sizeof(ProfilePoint), "path points");
-
- prwdgt->path[0].x = 1.0f;
- prwdgt->path[0].y = 0.0f;
- prwdgt->path[1].x = 1.0f;
- prwdgt->path[1].y = 1.0f;
-
- prwdgt->changed_timestamp = 0;
-}
+#define DEBUG_PRWDGT_EVALUATE
void BKE_profilewidget_free_data(ProfileWidget *prwdgt)
{
-#if DEBUG_PRWDGT
- printf("PROFILEWIDGET FREE DATA\n");
- if (!prwdgt->path) {
- printf("The prwdgt had no path... probably a second redundant free call\n");
- }
-#endif
if (prwdgt->path) {
MEM_freeN(prwdgt->path);
prwdgt->path = NULL;
@@ -91,9 +61,6 @@ void BKE_profilewidget_free_data(ProfileWidget *prwdgt)
void BKE_profilewidget_free(ProfileWidget *prwdgt)
{
-#if DEBUG_PRWDGT
- printf("PROFILEWIDGET FREE\n");
-#endif
if (prwdgt) {
BKE_profilewidget_free_data(prwdgt);
MEM_freeN(prwdgt);
@@ -102,9 +69,6 @@ void BKE_profilewidget_free(ProfileWidget *prwdgt)
void BKE_profilewidget_copy_data(ProfileWidget *target, const ProfileWidget *prwdgt)
{
-#if DEBUG_PRWDGT
- printf("PROFILEWIDGET COPY DATA\n");
-#endif
*target = *prwdgt;
if (prwdgt->path) {
@@ -120,10 +84,6 @@ void BKE_profilewidget_copy_data(ProfileWidget *target, const ProfileWidget *prw
ProfileWidget *BKE_profilewidget_copy(const ProfileWidget *prwdgt)
{
-#if DEBUG_PRWDGT
- printf("PROFILEWIDGET COPY\n");
-#endif
-
if (prwdgt) {
ProfileWidget *new_prdgt = MEM_dupallocN(prwdgt);
BKE_profilewidget_copy_data(new_prdgt, prwdgt);
@@ -132,56 +92,49 @@ ProfileWidget *BKE_profilewidget_copy(const ProfileWidget *prwdgt)
return NULL;
}
-/** Removes a specific point from the path of control points
- * \note: Requiress profilewidget_changed call after */
+/** Removes a specific point from the path of control points.
+ * \note: Requiress profilewidget_changed call after. */
bool BKE_profilewidget_remove_point(ProfileWidget *prwdgt, ProfilePoint *point)
{
ProfilePoint *pts;
- int a, b, removed = 0;
-
-#if DEBUG_PRWDGT
- printf("PROFILEPATH REMOVE POINT\n");
-#endif
+ int i_old, i_new, n_removed = 0;
- /* must have 2 points minimum */
+ /* Must have 2 points minimum. */
if (prwdgt->totpoint <= 2) {
return false;
}
pts = MEM_mallocN((size_t)prwdgt->totpoint * sizeof(ProfilePoint), "path points");
- /* Keep the two outer points */
- for (a = 0, b = 0; a < prwdgt->totpoint; a++) {
- if (&prwdgt->path[a] != point) {
- pts[b] = prwdgt->path[a];
- b++;
+ /* Build the new list without the point when it's found. Keep the first and last points. */
+ for (i_old = 1, i_new = 0; i_old < prwdgt->totpoint - 1; i_old++) {
+ if (&prwdgt->path[i_old] != point) {
+ pts[i_new] = prwdgt->path[i_old];
+ i_new++;
}
else {
- removed++;
+ n_removed++;
}
}
MEM_freeN(prwdgt->path);
prwdgt->path = pts;
- prwdgt->totpoint -= removed;
- return (removed != 0);
+ prwdgt->totpoint -= n_removed;
+ return (n_removed != 0);
}
/** Removes every point in the widget with the supplied flag set, except for the first and last.
- * \param flag: ProfilePoint->flag
- * \note: Requiress profilewidget_changed call after */
+ * \param flag: ProfilePoint->flag.
+ * \note: Requiress profilewidget_changed call after. */
void BKE_profilewidget_remove(ProfileWidget *prwdgt, const short flag)
{
-#if DEBUG_PRWDGT
- printf("PROFILEPATH REMOVE\n");
-#endif
int i_old, i_new, n_removed = 0;
- /* Copy every point without the flag into the new path */
+ /* Copy every point without the flag into the new path. */
ProfilePoint *new_pts = MEM_mallocN(((size_t)prwdgt->totpoint) * sizeof(ProfilePoint),
"path points");
- /* Don't delete the starting and ending points */
+ /* Build the new list without any of the points with the flag. Keep the first and last points. */
new_pts[0] = prwdgt->path[0];
for (i_old = 1, i_new = 1; i_old < prwdgt->totpoint - 1; i_old++) {
if (!(prwdgt->path[i_old].flag & flag)) {
@@ -200,23 +153,20 @@ void BKE_profilewidget_remove(ProfileWidget *prwdgt, const short flag)
}
/** Adds a new point at the specified location. The choice for which points to place the new vertex
- * between is more complex for a profile. We can't just find the new neighbors with X value
- * comparisons. Instead this function checks which line segment is closest to the new point.
- * \note: Requiress profilewidget_changed call after */
+ * between is made by checking which control point line segment is closest to the new point and
+ * placing the new vertex in between that segment's points.
+ * \note: Requiress profilewidget_changed call after. */
ProfilePoint *BKE_profilewidget_insert(ProfileWidget *prwdgt, float x, float y)
{
ProfilePoint *new_pt = NULL;
float new_loc[2] = {x, y};
-#if DEBUG_PRWDGT
- printf("PROFILEPATH INSERT\n");
-#endif
- /* Don't add more control points than the maximum size of the higher resolution table */
+ /* Don't add more control points than the maximum size of the higher resolution table. */
if (prwdgt->totpoint == PROF_TABLE_MAX - 1) {
return NULL;
}
- /* Find the index at the line segment that's closest to the new position */
+ /* Find the index at the line segment that's closest to the new position. */
float distance;
float min_distance = FLT_MAX;
int insert_i = 0;
@@ -231,7 +181,7 @@ ProfilePoint *BKE_profilewidget_insert(ProfileWidget *prwdgt, float x, float y)
}
}
- /* Insert the new point at the location we found and copy all of the old points in as well */
+ /* Insert the new point at the location we found and copy all of the old points in as well. */
prwdgt->totpoint++;
ProfilePoint *new_pts = MEM_mallocN(((size_t)prwdgt->totpoint) * sizeof(ProfilePoint),
"path points");
@@ -240,11 +190,11 @@ ProfilePoint *BKE_profilewidget_insert(ProfileWidget *prwdgt, float x, float y)
/* Insert old points */
new_pts[i_new].x = prwdgt->path[i_old].x;
new_pts[i_new].y = prwdgt->path[i_old].y;
- new_pts[i_new].flag = prwdgt->path[i_old].flag & ~PROF_SELECT; /* Deselect old points */
+ new_pts[i_new].flag = prwdgt->path[i_old].flag & ~PROF_SELECT; /* Deselect old points. */
i_old++;
}
else {
- /* Insert new point */
+ /* Insert new point. */
new_pts[i_new].x = x;
new_pts[i_new].y = y;
new_pts[i_new].flag = PROF_SELECT;
@@ -252,20 +202,17 @@ ProfilePoint *BKE_profilewidget_insert(ProfileWidget *prwdgt, float x, float y)
}
}
- /* Free the old points and use the new ones */
+ /* Free the old points and use the new ones. */
MEM_freeN(prwdgt->path);
prwdgt->path = new_pts;
return new_pt;
}
/** Sets the handle type of the selected control points.
- * \param type: Either HD_VECT or HD_AUTO
+ * \param type: Either HD_VECT or HD_AUTO.
* \note: Requiress profilewidget_changed call after. */
void BKE_profilewidget_handle_set(ProfileWidget *prwdgt, int type)
{
-#if DEBUG_PRWDGT
- printf("PROFILEPATH HANDLE SET\n");
-#endif
for (int i = 0; i < prwdgt->totpoint; i++) {
if (prwdgt->path[i].flag & PROF_SELECT) {
prwdgt->path[i].flag &= ~(PROF_HANDLE_VECTOR | PROF_HANDLE_AUTO);
@@ -283,9 +230,6 @@ void BKE_profilewidget_handle_set(ProfileWidget *prwdgt, int type)
* \note: Requiress profilewidget_changed call after. */
void BKE_profilewidget_reverse(ProfileWidget *prwdgt)
{
-#if DEBUG_PRWDGT
- printf("PROFILEPATH INSERT\n");
-#endif
/* Quick fix for when there are only two points and reversing shouldn't do anything */
if (prwdgt->totpoint == 2) {
return;
@@ -299,24 +243,12 @@ void BKE_profilewidget_reverse(ProfileWidget *prwdgt)
new_pts[prwdgt->totpoint - i - 1].flag = prwdgt->path[i].flag;
}
-#if DEBUG_PRWDGT_REVERSE
- printf("Locations before:\n");
- for (int i = 0; i < prwdgt->totpoint; i++) {
- printf("(%.2f, %.2f)", (double)prwdgt->path[i].x, (double)prwdgt->path[i].y);
- }
- printf("\nLocations after:\n");
- for (int i = 0; i < prwdgt->totpoint; i++) {
- printf("(%.2f, %.2f)", (double)new_pts[i].x, (double)new_pts[i].y);
- }
- printf("\n");
-#endif
-
/* Free the old points and use the new ones */
MEM_freeN(prwdgt->path);
prwdgt->path = new_pts;
}
-/** Puts the widget's control points in a step pattern, setting vector interpolation */
+/** Puts the widget's control points in a step pattern. Uses vector handles for each point. */
static void profilewidget_build_steps(ProfileWidget *prwdgt)
{
int n, step_x, step_y;
@@ -337,12 +269,9 @@ static void profilewidget_build_steps(ProfileWidget *prwdgt)
}
/** Resets the profile to the current preset.
- * \note: Requires profilewidget_changed call after */
+ * \note: Requires profilewidget_changed call after. */
void BKE_profilewidget_reset(ProfileWidget *prwdgt)
{
-#if DEBUG_PRWDGT
- printf("PROFILEPATH RESET\n");
-#endif
if (prwdgt->path) {
MEM_freeN(prwdgt->path);
}
@@ -478,21 +407,21 @@ void BKE_profilewidget_reset(ProfileWidget *prwdgt)
}
/** Helper for 'profile_widget_create' samples. Returns whether both handles that make up the edge
- * are vector handles */
+ * are vector handles. */
static bool is_curved_edge(BezTriple * bezt, int i)
{
return (bezt[i].h2 != HD_VECT || bezt[i + 1].h1 != HD_VECT);
}
/** Used to set bezier handle locations in the sample creation process. Reduced copy of
- * #calchandleNurb_intern co
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list