[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [42200] branches/bmesh/blender/source/ blender: when comparing lengths no need to sqrt
Campbell Barton
ideasman42 at gmail.com
Mon Nov 28 02:21:00 CET 2011
Revision: 42200
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=42200
Author: campbellbarton
Date: 2011-11-28 01:20:53 +0000 (Mon, 28 Nov 2011)
Log Message:
-----------
when comparing lengths no need to sqrt
Modified Paths:
--------------
branches/bmesh/blender/source/blender/bmesh/operators/connectops.c
branches/bmesh/blender/source/blender/bmesh/operators/createops.c
branches/bmesh/blender/source/blender/editors/mesh/knifetool.c
Modified: branches/bmesh/blender/source/blender/bmesh/operators/connectops.c
===================================================================
--- branches/bmesh/blender/source/blender/bmesh/operators/connectops.c 2011-11-28 00:27:26 UTC (rev 42199)
+++ branches/bmesh/blender/source/blender/bmesh/operators/connectops.c 2011-11-28 01:20:53 UTC (rev 42200)
@@ -296,9 +296,10 @@
/* If v1 is a better match for v4 than v3, AND v2 is a better match
for v3 than v4, the loops are in opposite directions, so reverse
- the order of reads from vv1 */
- if (len_v3v3(v1->co, v3->co) > len_v3v3(v1->co, v4->co) &&
- len_v3v3(v2->co, v4->co) > len_v3v3(v2->co, v3->co)) {
+ the order of reads from vv1. We can avoid sqrt for comparison */
+ if (len_squared_v3v3(v1->co, v3->co) > len_squared_v3v3(v1->co, v4->co) &&
+ len_squared_v3v3(v2->co, v4->co) > len_squared_v3v3(v2->co, v3->co))
+ {
dir1 = -1;
starti = CLAMP_INDEX(-1, lenv1);
}
@@ -333,7 +334,8 @@
previ = CLAMP_INDEX(starti - 1, lenv1);
nexti = CLAMP_INDEX(starti + 1, lenv1);
- if (len_v3v3(vv1[nexti]->co, vv2[1]->co) > len_v3v3(vv1[previ]->co, vv2[1]->co)) {
+ /* avoid sqrt for comparison */
+ if (len_squared_v3v3(vv1[nexti]->co, vv2[1]->co) > len_squared_v3v3(vv1[previ]->co, vv2[1]->co)) {
/* reverse direction for reading vv1 (1 is forward, -1 is backward) */
dir1 = -1;
}
Modified: branches/bmesh/blender/source/blender/bmesh/operators/createops.c
===================================================================
--- branches/bmesh/blender/source/blender/bmesh/operators/createops.c 2011-11-28 00:27:26 UTC (rev 42199)
+++ branches/bmesh/blender/source/blender/bmesh/operators/createops.c 2011-11-28 01:20:53 UTC (rev 42200)
@@ -1139,8 +1139,10 @@
else v4 = edges2[i]->v1;
}
- if (len_v3v3(v1->co, v3->co) + len_v3v3(v2->co, v4->co) >
- len_v3v3(v1->co, v4->co) + len_v3v3(v2->co, v3->co)) {
+ /* avoid sqrt for comparison */
+ if (len_squared_v3v3(v1->co, v3->co) + len_squared_v3v3(v2->co, v4->co) >
+ len_squared_v3v3(v1->co, v4->co) + len_squared_v3v3(v2->co, v3->co))
+ {
BMVert *v;
v = v3;
v3 = v4;
Modified: branches/bmesh/blender/source/blender/editors/mesh/knifetool.c
===================================================================
--- branches/bmesh/blender/source/blender/editors/mesh/knifetool.c 2011-11-28 00:27:26 UTC (rev 42199)
+++ branches/bmesh/blender/source/blender/editors/mesh/knifetool.c 2011-11-28 01:20:53 UTC (rev 42200)
@@ -746,11 +746,14 @@
glEnable(GL_DEPTH_TEST);
}
-static int kfe_vert_in_edge(KnifeEdge *e, KnifeVert *v) {
+/* do we need to keep these functions? - campbell */
+
+static int UNUSED_FUNCTION(kfe_vert_in_edge)(KnifeEdge *e, KnifeVert *v)
+{
return e->v1 == v || e->v2 == v;
}
-static int point_on_line(float p[3], float v1[3], float v2[3])
+static int UNUSED_FUNCTION(point_on_line)(float p[3], float v1[3], float v2[3])
{
float d = dist_to_line_segment_v3(p, v1, v2);
if (d < 0.01) {
@@ -775,16 +778,17 @@
BLI_array_declare(edges);
BVHTreeOverlap *results, *result;
BMLoop **ls;
- float cos[9], uv[3], lambda, depsilon;
+ float cos[9], uv[3], lambda;
unsigned int tot=0;
int i, j;
+
+ /* for comparing distances, error of intersection depends on triangle scale */
+ const float depsilon_squared= 50 * FLT_EPSILON * maxf(maxf(len_squared_v3v3(v1, v2), len_squared_v3v3(v1, v3)), len_squared_v3v3(v2, v3));
+ /* const float depsilon= sqrtf(depsilon_squared); */ /* UNUSED */
copy_v3_v3(cos, v1);
copy_v3_v3(cos+3, v2);
copy_v3_v3(cos+6, v3);
-
- /* for comparing distances, error of intersection depends on triangle scale */
- depsilon = 50*FLT_EPSILON*MAX3(len_v3v3(v1, v2), len_v3v3(v1, v3), len_v3v3(v2, v3));
BLI_bvhtree_insert(tree2, 0, cos, 3);
BLI_bvhtree_balance(tree2);
@@ -813,13 +817,16 @@
interp_v3_v3v3(p, kfe->v1->cageco, kfe->v2->cageco, lambda);
- if (kcd->curvert && len_v3v3(kcd->curvert->cageco, p) < depsilon)
+ if (kcd->curvert && len_squared_v3v3(kcd->curvert->cageco, p) < depsilon_squared)
continue;
- if (kcd->prevvert && len_v3v3(kcd->prevvert->cageco, p) < depsilon)
+ if (kcd->prevvert && len_squared_v3v3(kcd->prevvert->cageco, p) < depsilon_squared)
continue;
- if (len_v3v3(kcd->prevcage, p) < depsilon || len_v3v3(kcd->vertcage, p) < depsilon)
+ if ( len_squared_v3v3(kcd->prevcage, p) < depsilon_squared ||
+ len_squared_v3v3(kcd->vertcage, p) < depsilon_squared)
+ {
continue;
-
+ }
+
/*check if this point is visible in the viewport*/
knife_project_v3(kcd, p, sp);
view3d_unproject(mats, view, sp[0], sp[1], 0.0f);
@@ -841,8 +848,11 @@
if (!hitf && !BLI_smallhash_haskey(ehash, (intptr_t)kfe)) {
BMEdgeHit hit;
- if (len_v3v3(p, kcd->vertco) < depsilon || len_v3v3(p, kcd->prevco) < depsilon)
+ if ( len_squared_v3v3(p, kcd->vertco) < depsilon_squared ||
+ len_squared_v3v3(p, kcd->prevco) < depsilon_squared)
+ {
continue;
+ }
hit.kfe = kfe;
hit.v = NULL;
More information about the Bf-blender-cvs
mailing list