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
path: root/source
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2013-09-19 11:40:41 +0400
committerCampbell Barton <ideasman42@gmail.com>2013-09-19 11:40:41 +0400
commitac0a2ef274c3542a2f72b1e1fd70897b910a04d7 (patch)
tree12309ad81fabe79647741636f7b0eda0d1b97f0e /source
parent16c31832f9e9e455d3a194549e0f2837b49c8b1e (diff)
minor edits to poly_find_ear() bmesh function, no functional changes.
Diffstat (limited to 'source')
-rw-r--r--source/blender/bmesh/intern/bmesh_polygon.c41
1 files changed, 24 insertions, 17 deletions
diff --git a/source/blender/bmesh/intern/bmesh_polygon.c b/source/blender/bmesh/intern/bmesh_polygon.c
index a82d3d07712..1a1d92a9d96 100644
--- a/source/blender/bmesh/intern/bmesh_polygon.c
+++ b/source/blender/bmesh/intern/bmesh_polygon.c
@@ -829,7 +829,9 @@ static bool bm_face_goodline(float const (*projectverts)[2], BMFace *f, int v1i,
continue;
}
- if (isect_point_tri_v2(pv1, v1, v2, v3) || isect_point_tri_v2(pv1, v3, v2, v1)) {
+ if (isect_point_tri_v2(pv1, v1, v2, v3) ||
+ isect_point_tri_v2(pv1, v3, v2, v1))
+ {
#if 0
if (isect_point_tri_v2(pv1, v1, v2, v3))
printf("%d in (%d, %d, %d)\n", v3i, i, v1i, v2i);
@@ -878,7 +880,7 @@ static BMLoop *poly_find_ear(BMFace *f, float (*projectverts)[2], const bool use
/* pick 0/1 based on best length */
/* XXX Can't only rely on such test, also must check we do not get (too much) degenerated triangles!!! */
i = (((len_squared_v3v3(larr[0]->v->co, larr[2]->v->co) >
- len_squared_v3v3(larr[1]->v->co, larr[3]->v->co) * bias)) != use_beauty);
+ len_squared_v3v3(larr[1]->v->co, larr[3]->v->co) * bias)) != use_beauty);
i4 = (i + 3) % 4;
/* Check produced tris aren't too flat/narrow...
* Probably not the best test, but is quite efficient and should at least avoid null-area faces! */
@@ -891,6 +893,7 @@ static BMLoop *poly_find_ear(BMFace *f, float (*projectverts)[2], const bool use
#endif
if (cos1 < cos2)
cos1 = cos2;
+
if (cos1 > cos_threshold) {
if (cos1 > fabsf(cos_v3v3v3(larr[i]->v->co, larr[i4]->v->co, larr[i + 2]->v->co)) &&
cos1 > fabsf(cos_v3v3v3(larr[i]->v->co, larr[i + 1]->v->co, larr[i + 2]->v->co)))
@@ -901,8 +904,10 @@ static BMLoop *poly_find_ear(BMFace *f, float (*projectverts)[2], const bool use
/* Last check we do not get overlapping triangles
* (as much as possible, there are some cases with no good solution!) */
i4 = (i + 3) % 4;
- if (!bm_face_goodline((float const (*)[2])projectverts, f, BM_elem_index_get(larr[i4]->v),
- BM_elem_index_get(larr[i]->v), BM_elem_index_get(larr[i + 1]->v)))
+ if (!bm_face_goodline((float const (*)[2])projectverts, f,
+ BM_elem_index_get(larr[i4]->v),
+ BM_elem_index_get(larr[i]->v),
+ BM_elem_index_get(larr[i + 1]->v)))
{
i = !i;
}
@@ -912,13 +917,13 @@ static BMLoop *poly_find_ear(BMFace *f, float (*projectverts)[2], const bool use
}
else {
/* float angle, bestangle = 180.0f; */
- float cos, bestcos = 1.0f;
- int i, j, len;
+ const int len = f->len;
+ float cos, cos_best = 1.0f;
+ int i, j;
/* Compute cos of all corners! */
i = 0;
l_iter = l_first = BM_FACE_FIRST_LOOP(f);
- len = l_iter->f->len;
do {
const BMVert *v1 = l_iter->prev->v;
const BMVert *v2 = l_iter->v;
@@ -937,7 +942,9 @@ static BMLoop *poly_find_ear(BMFace *f, float (*projectverts)[2], const bool use
const BMVert *v3 = l_iter->next->v;
if (bm_face_goodline((float const (*)[2])projectverts, f,
- BM_elem_index_get(v1), BM_elem_index_get(v2), BM_elem_index_get(v3)))
+ BM_elem_index_get(v1),
+ BM_elem_index_get(v2),
+ BM_elem_index_get(v3)))
{
/* Compute highest cos (i.e. narrowest angle) of this tri. */
cos = max_fff(abscoss[i],
@@ -945,30 +952,30 @@ static BMLoop *poly_find_ear(BMFace *f, float (*projectverts)[2], const bool use
fabsf(cos_v3v3v3(v3->co, v1->co, v2->co)));
/* Compare to prev best (i.e. lowest) cos. */
- if (cos < bestcos) {
+ if (cos < cos_best) {
/* We must check this tri would not leave a (too much) degenerated remaining face! */
/* For now just assume if the average of cos of all
* "remaining face"'s corners is below a given threshold, it's OK. */
- float avgcos = fabsf(cos_v3v3v3(v1->co, v3->co, l_iter->next->next->v->co));
+ float cos_mean = fabsf(cos_v3v3v3(v1->co, v3->co, l_iter->next->next->v->co));
const int i_limit = (i - 1 + len) % len;
- avgcos += fabsf(cos_v3v3v3(l_iter->prev->prev->v->co, v1->co, v3->co));
+ cos_mean += fabsf(cos_v3v3v3(l_iter->prev->prev->v->co, v1->co, v3->co));
j = (i + 2) % len;
do {
- avgcos += abscoss[j];
+ cos_mean += abscoss[j];
} while ((j = (j + 1) % len) != i_limit);
- avgcos /= len - 1;
+ cos_mean /= len - 1;
/* We need a best ear in any case... */
- if (avgcos < cos_threshold || (!bestear && avgcos < 1.0f)) {
+ if (cos_mean < cos_threshold || (!bestear && cos_mean < 1.0f)) {
/* OKI, keep this ear (corner...) as a potential best one! */
bestear = l_iter;
- bestcos = cos;
+ cos_best = cos;
}
#if 0
else
- printf("Had a nice tri (higest cos of %f, current bestcos is %f), "
+ printf("Had a nice tri (higest cos of %f, current cos_best is %f), "
"but average cos of all \"remaining face\"'s corners is too high (%f)!\n",
- cos, bestcos, avgcos);
+ cos, cos_best, cos_mean);
#endif
}
}