[Bf-blender-cvs] [f2c52aa0e1a] master: Cleanup: use 'const' arguments in transform calculation

Campbell Barton noreply at git.blender.org
Tue Jun 29 12:26:55 CEST 2021


Commit: f2c52aa0e1a5a6905849daa299ab907e60cab983
Author: Campbell Barton
Date:   Tue Jun 29 20:13:55 2021 +1000
Branches: master
https://developer.blender.org/rBf2c52aa0e1a5a6905849daa299ab907e60cab983

Cleanup: use 'const' arguments in transform calculation

Use const arguments to simplify further optimizations.

Transforming elements shouldn't need to change their containers
data-structures.
ElementResize for grease pencil stroke thickness was
modifying TransInfo.num & TransInfo.values_final.

Now copies are operated on to preserve const correctness although
it's worth investigating if this can be avoided altogether.

===================================================================

M	source/blender/editors/transform/transform.h
M	source/blender/editors/transform/transform_constraints.c
M	source/blender/editors/transform/transform_constraints.h
M	source/blender/editors/transform/transform_mode.c
M	source/blender/editors/transform/transform_mode.h
M	source/blender/editors/transform/transform_snap.c
M	source/blender/editors/transform/transform_snap.h

===================================================================

diff --git a/source/blender/editors/transform/transform.h b/source/blender/editors/transform/transform.h
index 2df0d86d02b..4f97c3b6713 100644
--- a/source/blender/editors/transform/transform.h
+++ b/source/blender/editors/transform/transform.h
@@ -356,22 +356,22 @@ typedef struct TransCon {
 
   /** Apply function pointer for linear vectorial transformation
    * The last three parameters are pointers to the in/out/printable vectors. */
-  void (*applyVec)(struct TransInfo *t,
-                   struct TransDataContainer *tc,
+  void (*applyVec)(const struct TransInfo *t,
+                   const struct TransDataContainer *tc,
                    struct TransData *td,
                    const float in[3],
-                   float out[3]);
+                   float r_out[3]);
   /** Apply function pointer for size transformation. */
-  void (*applySize)(struct TransInfo *t,
-                    struct TransDataContainer *tc,
+  void (*applySize)(const struct TransInfo *t,
+                    const struct TransDataContainer *tc,
                     struct TransData *td,
-                    float smat[3][3]);
+                    float r_smat[3][3]);
   /** Apply function pointer for rotation transformation */
-  void (*applyRot)(struct TransInfo *t,
-                   struct TransDataContainer *tc,
+  void (*applyRot)(const struct TransInfo *t,
+                   const struct TransDataContainer *tc,
                    struct TransData *td,
-                   float vec[3],
-                   float *angle);
+                   float r_axis[3],
+                   float *r_angle);
 } TransCon;
 
 typedef struct MouseInput {
diff --git a/source/blender/editors/transform/transform_constraints.c b/source/blender/editors/transform/transform_constraints.c
index 8c74d5349ba..78fc6575e6e 100644
--- a/source/blender/editors/transform/transform_constraints.c
+++ b/source/blender/editors/transform/transform_constraints.c
@@ -97,7 +97,7 @@ static void view_vector_calc(const TransInfo *t, const float focus[3], float r_v
 /* ************************** CONSTRAINTS ************************* */
 #define CONSTRAIN_EPSILON 0.0001f
 
-static void constraint_plane_calc(TransInfo *t, float r_plane[4])
+static void constraint_plane_calc(const TransInfo *t, float r_plane[4])
 {
   const float *constraint_vector[2];
   int n = 0;
@@ -391,8 +391,11 @@ static void planeProjection(const TransInfo *t, const float in[3], float out[3])
  * projected along the view vector.
  * (in perspective mode, the view vector is relative to the position on screen)
  */
-static void applyAxisConstraintVec(
-    TransInfo *t, TransDataContainer *UNUSED(tc), TransData *td, const float in[3], float out[3])
+static void applyAxisConstraintVec(const TransInfo *t,
+                                   const TransDataContainer *UNUSED(tc),
+                                   TransData *td,
+                                   const float in[3],
+                                   float out[3])
 {
   copy_v3_v3(out, in);
   if (!td && t->con.mode & CON_APPLY) {
@@ -472,8 +475,11 @@ static void applyAxisConstraintVec(
  *
  * Further down, that vector is mapped to each data's space.
  */
-static void applyObjectConstraintVec(
-    TransInfo *t, TransDataContainer *tc, TransData *td, const float in[3], float out[3])
+static void applyObjectConstraintVec(const TransInfo *t,
+                                     const TransDataContainer *tc,
+                                     TransData *td,
+                                     const float in[3],
+                                     float out[3])
 {
   if (!td) {
     applyAxisConstraintVec(t, tc, td, in, out);
@@ -494,36 +500,36 @@ static void applyObjectConstraintVec(
 /**
  * Generic callback for constant spatial constraints applied to resize motion.
  */
-static void applyAxisConstraintSize(TransInfo *t,
-                                    TransDataContainer *UNUSED(tc),
+static void applyAxisConstraintSize(const TransInfo *t,
+                                    const TransDataContainer *UNUSED(tc),
                                     TransData *td,
-                                    float smat[3][3])
+                                    float r_smat[3][3])
 {
   if (!td && t->con.mode & CON_APPLY) {
     float tmat[3][3];
 
     if (!(t->con.mode & CON_AXIS0)) {
-      smat[0][0] = 1.0f;
+      r_smat[0][0] = 1.0f;
     }
     if (!(t->con.mode & CON_AXIS1)) {
-      smat[1][1] = 1.0f;
+      r_smat[1][1] = 1.0f;
     }
     if (!(t->con.mode & CON_AXIS2)) {
-      smat[2][2] = 1.0f;
+      r_smat[2][2] = 1.0f;
     }
 
-    mul_m3_m3m3(tmat, smat, t->spacemtx_inv);
-    mul_m3_m3m3(smat, t->spacemtx, tmat);
+    mul_m3_m3m3(tmat, r_smat, t->spacemtx_inv);
+    mul_m3_m3m3(r_smat, t->spacemtx, tmat);
   }
 }
 
 /**
  * Callback for object based spatial constraints applied to resize motion.
  */
-static void applyObjectConstraintSize(TransInfo *t,
-                                      TransDataContainer *tc,
+static void applyObjectConstraintSize(const TransInfo *t,
+                                      const TransDataContainer *tc,
                                       TransData *td,
-                                      float smat[3][3])
+                                      float r_smat[3][3])
 {
   if (td && t->con.mode & CON_APPLY) {
     float tmat[3][3];
@@ -532,26 +538,26 @@ static void applyObjectConstraintSize(TransInfo *t,
     invert_m3_m3(imat, td->axismtx);
 
     if (!(t->con.mode & CON_AXIS0)) {
-      smat[0][0] = 1.0f;
+      r_smat[0][0] = 1.0f;
     }
     if (!(t->con.mode & CON_AXIS1)) {
-      smat[1][1] = 1.0f;
+      r_smat[1][1] = 1.0f;
     }
     if (!(t->con.mode & CON_AXIS2)) {
-      smat[2][2] = 1.0f;
+      r_smat[2][2] = 1.0f;
     }
 
-    mul_m3_m3m3(tmat, smat, imat);
+    mul_m3_m3m3(tmat, r_smat, imat);
     if (t->flag & T_EDIT) {
-      mul_m3_m3m3(smat, tc->mat3_unit, smat);
+      mul_m3_m3m3(r_smat, tc->mat3_unit, r_smat);
     }
-    mul_m3_m3m3(smat, td->axismtx, tmat);
+    mul_m3_m3m3(r_smat, td->axismtx, tmat);
   }
 }
 
-static void constraints_rotation_impl(TransInfo *t,
+static void constraints_rotation_impl(const TransInfo *t,
                                       const float axismtx[3][3],
-                                      float r_vec[3],
+                                      float r_axis[3],
                                       float *r_angle)
 {
   BLI_assert(t->con.mode & CON_APPLY);
@@ -560,15 +566,15 @@ static void constraints_rotation_impl(TransInfo *t,
   switch (mode) {
     case CON_AXIS0:
     case (CON_AXIS1 | CON_AXIS2):
-      copy_v3_v3(r_vec, axismtx[0]);
+      copy_v3_v3(r_axis, axismtx[0]);
       break;
     case CON_AXIS1:
     case (CON_AXIS0 | CON_AXIS2):
-      copy_v3_v3(r_vec, axismtx[1]);
+      copy_v3_v3(r_axis, axismtx[1]);
       break;
     case CON_AXIS2:
     case (CON_AXIS0 | CON_AXIS1):
-      copy_v3_v3(r_vec, axismtx[2]);
+      copy_v3_v3(r_axis, axismtx[2]);
       break;
   }
   /* don't flip axis if asked to or if num input */
@@ -576,7 +582,7 @@ static void constraints_rotation_impl(TransInfo *t,
       !((mode & CON_NOFLIP) || hasNumInput(&t->num) || (t->flag & T_INPUT_IS_VALUES_FINAL))) {
     float view_vector[3];
     view_vector_calc(t, t->center_global, view_vector);
-    if (dot_v3v3(r_vec, view_vector) > 0.0f) {
+    if (dot_v3v3(r_axis, view_vector) > 0.0f) {
       *r_angle = -(*r_angle);
     }
   }
@@ -595,11 +601,14 @@ static void constraints_rotation_impl(TransInfo *t,
  * This insures that the rotation is always logically following the mouse.
  * (ie: not doing counterclockwise rotations when the mouse moves clockwise).
  */
-static void applyAxisConstraintRot(
-    TransInfo *t, TransDataContainer *UNUSED(tc), TransData *td, float vec[3], float *angle)
+static void applyAxisConstraintRot(const TransInfo *t,
+                                   const TransDataContainer *UNUSED(tc),
+                                   TransData *td,
+                                   float r_axis[3],
+                                   float *r_angle)
 {
   if (!td && t->con.mode & CON_APPLY) {
-    constraints_rotation_impl(t, t->spacemtx, vec, angle);
+    constraints_rotation_impl(t, t->spacemtx, r_axis, r_angle);
   }
 }
 
@@ -616,8 +625,11 @@ static void applyAxisConstraintRot(
  * This insures that the rotation is always logically following the mouse.
  * (ie: not doing counterclockwise rotations when the mouse moves clockwise).
  */
-static void applyObjectConstraintRot(
-    TransInfo *t, TransDataContainer *tc, TransData *td, float vec[3], float *angle)
+static void applyObjectConstraintRot(const TransInfo *t,
+                                     const TransDataContainer *tc,
+                                     TransData *td,
+                                     float r_axis[3],
+                                     float *r_angle)
 {
   if (t->con.mode & CON_APPLY) {
     float tmp_axismtx[3][3];
@@ -638,7 +650,7 @@ static void applyObjectConstraintRot(
       axismtx = td->axismtx;
     }
 
-    constraints_rotation_impl(t, axismtx, vec, angle);
+    constraints_rotation_impl(t, axismtx, r_axis, r_angle);
   }
 }
 
@@ -1164,7 +1176,7 @@ bool isLockConstraint(TransInfo *t)
  * even if they aren't actually used in the callback function.
  * (Which could happen for weird constraints not yet designed. Along a path for example.)
  */
-int getConstraintSpaceDimension(TransInfo *t)
+int getConstraintSpaceDimension(const TransInfo *t)
 {
   int n = 0;
 
diff --git a/source/blender/editors/transform/transform_constraints.h b/source/blender/editors/transform/transform_constraints.h
index ac62c057f9d..cbf6c7bb576 100644
--- a/source/blender/editors/transform/transform_constraints.h
+++ b/source/blender/editors/transform/transform_constraints.h
@@ -47,4 +47,4 @@ void setNearestAxis(TransInfo *t);
 int constraintModeToIndex(const TransInfo *t);
 char constraintModeToChar(const TransInfo *t);
 bool isLockConstraint(TransInfo *t);
-int getConstraintSpaceDimension(TransInfo *t);
+int getConstraintSpaceDimension(const TransInfo *t);
diff --git a/source/blender/editors/transform/transform_mode.c b/source/blender/editors/transform

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list