[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [56486] trunk/blender/source/blender: knife sort_by_frac_along was re-calculating the reference factor for every test , change to only calculate once and use line_point_factor_v3().

Campbell Barton ideasman42 at gmail.com
Fri May 3 07:57:34 CEST 2013


Revision: 56486
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=56486
Author:   campbellbarton
Date:     2013-05-03 05:57:33 +0000 (Fri, 03 May 2013)
Log Message:
-----------
knife sort_by_frac_along was re-calculating the reference factor for every test, change to only calculate once and use line_point_factor_v3().
also add zero division check for line_point_factor_v3() since the 2d version already checked for this.

Modified Paths:
--------------
    trunk/blender/source/blender/blenlib/intern/math_geom.c
    trunk/blender/source/blender/editors/mesh/editmesh_knife.c

Modified: trunk/blender/source/blender/blenlib/intern/math_geom.c
===================================================================
--- trunk/blender/source/blender/blenlib/intern/math_geom.c	2013-05-03 05:24:05 UTC (rev 56485)
+++ trunk/blender/source/blender/blenlib/intern/math_geom.c	2013-05-03 05:57:33 UTC (rev 56486)
@@ -1654,9 +1654,16 @@
 float line_point_factor_v3(const float p[3], const float l1[3], const float l2[3])
 {
 	float h[3], u[3];
+	float dot;
 	sub_v3_v3v3(u, l2, l1);
 	sub_v3_v3v3(h, p, l1);
+#if 0
 	return (dot_v3v3(u, h) / dot_v3v3(u, u));
+#else
+	/* better check for zero */
+	dot = dot_v3v3(u, u);
+	return (dot != 0.0f) ? (dot_v3v3(u, h) / dot) : 0.0f;
+#endif
 }
 
 float line_point_factor_v2(const float p[2], const float l1[2], const float l2[2])

Modified: trunk/blender/source/blender/editors/mesh/editmesh_knife.c
===================================================================
--- trunk/blender/source/blender/editors/mesh/editmesh_knife.c	2013-05-03 05:24:05 UTC (rev 56485)
+++ trunk/blender/source/blender/editors/mesh/editmesh_knife.c	2013-05-03 05:57:33 UTC (rev 56486)
@@ -2212,43 +2212,28 @@
 
 #else  /* use direct (non-scanfill) method for cuts */
 
-/* assuming v is on line ab, what fraction of the way is v from a to b? */
-static float frac_along(const float a[3], const float b[3], const float v[3])
-{
-	float lab;
-
-	lab = len_v3v3(a, b);
-	if (lab == 0.0f) {
-		return 0.0f;
-	}
-	else {
-		return len_v3v3(a, v) / lab;
-	}
-}
-
 /* sort list of kverts by fraction along edge e */
 static void sort_by_frac_along(ListBase *lst, BMEdge *e)
 {
-	KnifeVert *vcur, *vprev;
-	float *v1co, *v2co;
+	const float *v1co = e->v1->co;
+	const float *v2co = e->v2->co;
 	Ref *cur = NULL, *prev = NULL, *next = NULL;
 
 	if (lst->first == lst->last)
 		return;
 
-	v1co = e->v1->co;
-	v2co = e->v2->co;
-
 	for (cur = ((Ref *)lst->first)->next; cur; cur = next) {
+		KnifeVert *vcur = cur->ref;
+		const float vcur_fac = line_point_factor_v3(vcur->co, v1co, v2co);
+
 		next = cur->next;
 		prev = cur->prev;
 
 		BLI_remlink(lst, cur);
 
-		vcur = cur->ref;
 		while (prev) {
-			vprev = prev->ref;
-			if (frac_along(v1co, v2co, vprev->co) <= frac_along(v1co, v2co, vcur->co))
+			KnifeVert *vprev = prev->ref;
+			if (line_point_factor_v3(vprev->co, v1co, v2co) <= vcur_fac)
 				break;
 			prev = prev->prev;
 		}
@@ -2860,7 +2845,7 @@
 		sort_by_frac_along(lst, e);
 		for (ref = lst->first; ref; ref = ref->next) {
 			kfv = ref->ref;
-			pct = frac_along(e->v1->co, e->v2->co, kfv->co);
+			pct = line_point_factor_v3(kfv->co, e->v1->co, e->v2->co);
 			kfv->v = BM_edge_split(bm, e, e->v1, &enew, pct);
 		}
 	}




More information about the Bf-blender-cvs mailing list