[Bf-blender-cvs] [28b9dfeece3] greasepencil-object: Move int <-> float 2d vector funcs from GP code to Math Lib

Joshua Leung noreply at git.blender.org
Thu Feb 1 08:45:38 CET 2018


Commit: 28b9dfeece3f550cf494f4079ba982cc8164bb0f
Author: Joshua Leung
Date:   Thu Feb 1 15:45:38 2018 +1300
Branches: greasepencil-object
https://developer.blender.org/rB28b9dfeece3f550cf494f4079ba982cc8164bb0f

Move int <-> float 2d vector funcs from GP code to Math Lib

We now have the following two new functions:
* copy_v2fl_v2i(float r[2], const int a[2])  <-- Copies 2D int vector to float vector
* round_v2i_v2fl(int r[2], const float a[2]) <-- Copies 2D float vector to int vector, by rounding the values

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

M	source/blender/blenlib/BLI_math_vector.h
M	source/blender/blenlib/intern/math_vector_inline.c
M	source/blender/editors/gpencil/gpencil_paint.c

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

diff --git a/source/blender/blenlib/BLI_math_vector.h b/source/blender/blenlib/BLI_math_vector.h
index e4e0bf22de0..9deff7694d4 100644
--- a/source/blender/blenlib/BLI_math_vector.h
+++ b/source/blender/blenlib/BLI_math_vector.h
@@ -78,6 +78,9 @@ MINLINE void zero_v3_int(int r[3]);
 MINLINE void copy_v2_v2_int(int r[2], const int a[2]);
 MINLINE void copy_v3_v3_int(int r[3], const int a[3]);
 MINLINE void copy_v4_v4_int(int r[4], const int a[4]);
+/* int <-> float */
+MINLINE void copy_v2fl_v2i(float r[2], const int a[2]);
+MINLINE void round_v2i_v2fl(int r[2], const float a[2]);
 /* double -> float */
 MINLINE void copy_v2fl_v2db(float r[2], const double a[2]);
 MINLINE void copy_v3fl_v3db(float r[3], const double a[3]);
diff --git a/source/blender/blenlib/intern/math_vector_inline.c b/source/blender/blenlib/intern/math_vector_inline.c
index 4f658ef015f..b8d7bc2efeb 100644
--- a/source/blender/blenlib/intern/math_vector_inline.c
+++ b/source/blender/blenlib/intern/math_vector_inline.c
@@ -192,6 +192,19 @@ MINLINE void copy_v4_v4_int(int r[4], const int a[4])
 	r[3] = a[3];
 }
 
+/* int <-> float */
+MINLINE void round_v2i_v2fl(int r[2], const float a[2])
+{
+	r[0] = (int)roundf(a[0]);
+	r[1] = (int)roundf(a[1]);
+}
+
+MINLINE void copy_v2fl_v2i(float r[2], const int a[2])
+{
+	r[0] = (float)a[0];
+	r[1] = (float)a[1];
+}
+
 /* double -> float */
 MINLINE void copy_v2fl_v2db(float r[2], const double a[2])
 {
diff --git a/source/blender/editors/gpencil/gpencil_paint.c b/source/blender/editors/gpencil/gpencil_paint.c
index aa8a2920aed..d60e4c5e785 100644
--- a/source/blender/editors/gpencil/gpencil_paint.c
+++ b/source/blender/editors/gpencil/gpencil_paint.c
@@ -277,20 +277,6 @@ static void gp_get_3d_reference(tGPsdata *p, float vec[3])
 	ED_gp_get_drawing_reference(v3d, p->scene, ob, p->gpl, *p->align_flag, vec);
 }
 
-// XXX: Rename and move to BLI_math_vector.h
-static void copy_v2int_v2float(int r[2], const float a[2])
-{
-	r[0] = (int)roundf(a[0]);
-	r[1] = (int)roundf(a[1]);
-}
-
-// XXX: Rename and move to BLI_math_vector.h
-static void copy_v2float_v2int(float r[2], const int a[2])
-{
-	r[0] = (float)a[0];
-	r[1] = (float)a[1];
-}
-
 /* Stroke Editing ---------------------------- */
 /* check if the current mouse position is suitable for adding a new point */
 static bool gp_stroke_filtermval(tGPsdata *p, const int mval[2], int pmval[2])
@@ -2178,10 +2164,10 @@ static void gpencil_draw_apply(bContext *C, wmOperator *op, tGPsdata *p, const D
 		if (GPENCIL_LAZY_MODE(p->brush, p->shift)) {
 			float now_mouse[2];
 			float last_mouse[2];
-			copy_v2float_v2int(now_mouse, p->mval);
-			copy_v2float_v2int(last_mouse, p->mvalo);
+			copy_v2fl_v2i(now_mouse, p->mval);
+			copy_v2fl_v2i(last_mouse, p->mvalo);
 			interp_v2_v2v2(now_mouse, now_mouse, last_mouse, p->brush->lazy_factor);
-			copy_v2int_v2float(p->mval, now_mouse);
+			round_v2i_v2fl(p->mval, now_mouse);
 		}
 
 		/* try to add point */



More information about the Bf-blender-cvs mailing list