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:
authorCampbell Barton <ideasman42@gmail.com>2013-09-06 00:54:32 +0400
committerCampbell Barton <ideasman42@gmail.com>2013-09-06 00:54:32 +0400
commit3b72f1824cf06216c70101ee0d29004cc6dc632d (patch)
tree56981fdefd7a0de0d37e4feab3acaea7c1b744ef
parentf6b37f34ec2593b12b67046cf032acc202e2fa54 (diff)
rename positive_mod to mod_i, make it work with nagative numbers (matching pythons modulo), and use in a few more places.
allow mesh-checker-deselect to have a negative offset.
-rw-r--r--source/blender/blenkernel/intern/anim.c3
-rw-r--r--source/blender/blenlib/BLI_math_base.h2
-rw-r--r--source/blender/blenlib/intern/math_base_inline.c7
-rw-r--r--source/blender/bmesh/intern/bmesh_edgeloop.c2
-rw-r--r--source/blender/bmesh/operators/bmo_bridge.c2
-rw-r--r--source/blender/editors/mesh/editmesh_select.c4
-rw-r--r--source/blender/editors/mesh/editmesh_tools.c2
7 files changed, 12 insertions, 10 deletions
diff --git a/source/blender/blenkernel/intern/anim.c b/source/blender/blenkernel/intern/anim.c
index 3d8b70b693b..49c9a8e9083 100644
--- a/source/blender/blenkernel/intern/anim.c
+++ b/source/blender/blenkernel/intern/anim.c
@@ -594,8 +594,7 @@ void calc_curvepath(Object *ob, ListBase *nurbs)
static int interval_test(const int min, const int max, int p1, const int cycl)
{
if (cycl) {
- if (p1 < min) p1 = ((p1 - min) % (max - min + 1)) + max + 1;
- else if (p1 > max) p1 = ((p1 - min) % (max - min + 1)) + min;
+ p1 = mod_i(p1 - min, (max - min + 1)) + min;
}
else {
if (p1 < min) p1 = min;
diff --git a/source/blender/blenlib/BLI_math_base.h b/source/blender/blenlib/BLI_math_base.h
index 86aabf76350..1cb28d25b6c 100644
--- a/source/blender/blenlib/BLI_math_base.h
+++ b/source/blender/blenlib/BLI_math_base.h
@@ -222,7 +222,7 @@ MINLINE int power_of_2_max_i(int n);
MINLINE int power_of_2_min_i(int n);
MINLINE int divide_round_i(int a, int b);
-MINLINE int positive_mod(int i, int n);
+MINLINE int mod_i(int i, int n);
MINLINE float shell_angle_to_dist(const float angle);
diff --git a/source/blender/blenlib/intern/math_base_inline.c b/source/blender/blenlib/intern/math_base_inline.c
index f68970b832d..e6509db1c5e 100644
--- a/source/blender/blenlib/intern/math_base_inline.c
+++ b/source/blender/blenlib/intern/math_base_inline.c
@@ -153,9 +153,12 @@ MINLINE int divide_round_i(int a, int b)
return (2 * a + b) / (2 * b);
}
-MINLINE int positive_mod(int i, int n)
+/**
+ * modulo that handles negative numbers, works the same as Python's.
+ */
+MINLINE int mod_i(int i, int n)
{
- return ((i = i % n) < 0) ? i + n : i;
+ return (i % n + n) % n;
}
MINLINE unsigned int highest_order_bit_i(unsigned int n)
diff --git a/source/blender/bmesh/intern/bmesh_edgeloop.c b/source/blender/bmesh/intern/bmesh_edgeloop.c
index 6b306e82bb0..fe3f6551b70 100644
--- a/source/blender/bmesh/intern/bmesh_edgeloop.c
+++ b/source/blender/bmesh/intern/bmesh_edgeloop.c
@@ -230,7 +230,7 @@ static bool bm_loop_path_build_step(BLI_mempool *vs_pool, ListBase *lb, const in
/* on the same side - do nothing */
}
else {
- /* we have met out match! (vertices from differnt sides meet) */
+ /* we have met out match! (vertices from different sides meet) */
if (dir == 1) {
v_match[0] = vs->v;
v_match[1] = v_next;
diff --git a/source/blender/bmesh/operators/bmo_bridge.c b/source/blender/bmesh/operators/bmo_bridge.c
index 22a1a87b71c..f4bb73f87ea 100644
--- a/source/blender/bmesh/operators/bmo_bridge.c
+++ b/source/blender/bmesh/operators/bmo_bridge.c
@@ -273,7 +273,7 @@ static void bridge_loop_pair(BMesh *bm,
if (twist_offset != 0) {
const int len_b = BM_edgeloop_length_get(el_store_b);
ListBase *lb_b = BM_edgeloop_verts_get(el_store_b);
- LinkData *el_b = BLI_rfindlink(lb_b, positive_mod(twist_offset, len_b));
+ LinkData *el_b = BLI_rfindlink(lb_b, mod_i(twist_offset, len_b));
BLI_rotatelist_first(lb_b, el_b);
}
}
diff --git a/source/blender/editors/mesh/editmesh_select.c b/source/blender/editors/mesh/editmesh_select.c
index f4a55af742c..806ae96cb61 100644
--- a/source/blender/editors/mesh/editmesh_select.c
+++ b/source/blender/editors/mesh/editmesh_select.c
@@ -2510,7 +2510,7 @@ static int edbm_select_nth_exec(bContext *C, wmOperator *op)
int offset = RNA_int_get(op->ptr, "offset");
/* so input of offset zero ends up being (nth - 1) */
- offset = (offset + (nth - 1)) % nth;
+ offset = mod_i(offset, nth);
if (edbm_deselect_nth(em, nth, offset) == false) {
BKE_report(op->reports, RPT_ERROR, "Mesh has no active vert/edge/face");
@@ -2538,7 +2538,7 @@ void MESH_OT_select_nth(wmOperatorType *ot)
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
RNA_def_int(ot->srna, "nth", 2, 2, INT_MAX, "Nth Selection", "", 2, 100);
- RNA_def_int(ot->srna, "offset", 0, 0, INT_MAX, "Offset", "", 0, 100);
+ RNA_def_int(ot->srna, "offset", 0, INT_MIN, INT_MAX, "Offset", "", -100, 100);
}
void em_setup_viewcontext(bContext *C, ViewContext *vc)
diff --git a/source/blender/editors/mesh/editmesh_tools.c b/source/blender/editors/mesh/editmesh_tools.c
index 6d47f1e1a98..e8033ab0d91 100644
--- a/source/blender/editors/mesh/editmesh_tools.c
+++ b/source/blender/editors/mesh/editmesh_tools.c
@@ -2959,7 +2959,7 @@ static int edbm_fill_grid_exec(bContext *C, wmOperator *op)
RNA_property_int_set(op->ptr, prop_span, span);
offset = RNA_property_int_get(op->ptr, prop_offset);
- offset = positive_mod(offset, clamp);
+ offset = mod_i(offset, clamp);
/* in simple cases, move selection for tags, but also support more advanced cases */
edbm_fill_grid_prepare(em->bm, span, offset);