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-05-03 09:57:33 +0400
committerCampbell Barton <ideasman42@gmail.com>2013-05-03 09:57:33 +0400
commit2a78a1436934590d4762e79c50e85be466d3914f (patch)
tree420d0181bd375069300e608ad42b9f439afbe9cc
parenta5d6820b6d96b2f379e3f5e118b80cfc486b425d (diff)
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.
-rw-r--r--source/blender/blenlib/intern/math_geom.c7
-rw-r--r--source/blender/editors/mesh/editmesh_knife.c31
2 files changed, 15 insertions, 23 deletions
diff --git a/source/blender/blenlib/intern/math_geom.c b/source/blender/blenlib/intern/math_geom.c
index 56921797659..c8de9108fc3 100644
--- a/source/blender/blenlib/intern/math_geom.c
+++ b/source/blender/blenlib/intern/math_geom.c
@@ -1654,9 +1654,16 @@ float closest_to_line_v2(float cp[2], const float p[2], const float l1[2], const
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])
diff --git a/source/blender/editors/mesh/editmesh_knife.c b/source/blender/editors/mesh/editmesh_knife.c
index afd151f3c77..5957e71c57c 100644
--- a/source/blender/editors/mesh/editmesh_knife.c
+++ b/source/blender/editors/mesh/editmesh_knife.c
@@ -2212,43 +2212,28 @@ static void knifenet_fill_faces(KnifeTool_OpData *kcd)
#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 @@ static void knife_make_cuts(KnifeTool_OpData *kcd)
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);
}
}