diff options
author | Campbell Barton <ideasman42@gmail.com> | 2013-10-04 14:48:24 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2013-10-04 14:48:24 +0400 |
commit | ec4a7fcad12ba8106531ab02c5bc1cce213cfb86 (patch) | |
tree | 37ba99482cda33cd713ef43300af5d463bb097c4 | |
parent | 9a6a9c4f0c7bbef1e320fde69c497de22ecbe952 (diff) |
fix for lasso selection (in non-zbuf mode) when the line intersected its self.
isect_point_poly_v2() - add argument to check overlapping areas.
-rw-r--r-- | source/blender/blenlib/BLI_math_geom.h | 4 | ||||
-rw-r--r-- | source/blender/blenlib/intern/lasso.c | 2 | ||||
-rw-r--r-- | source/blender/blenlib/intern/math_geom.c | 26 | ||||
-rw-r--r-- | source/blender/bmesh/tools/bmesh_bisect_plane.c | 2 | ||||
-rw-r--r-- | source/blender/editors/mesh/editmesh_knife.c | 2 |
5 files changed, 27 insertions, 9 deletions
diff --git a/source/blender/blenlib/BLI_math_geom.h b/source/blender/blenlib/BLI_math_geom.h index d3f6c7ef14b..c7ef410a606 100644 --- a/source/blender/blenlib/BLI_math_geom.h +++ b/source/blender/blenlib/BLI_math_geom.h @@ -155,8 +155,8 @@ bool isect_ray_tri_epsilon_v3(const float p1[3], const float d[3], const float v0[3], const float v1[3], const float v2[3], float *r_lambda, float r_uv[2], const float epsilon); /* point in polygon */ -bool isect_point_poly_v2(const float pt[2], const float verts[][2], const unsigned int nr); -bool isect_point_poly_v2_int(const int pt[2], const int verts[][2], const unsigned int nr); +bool isect_point_poly_v2(const float pt[2], const float verts[][2], const unsigned int nr, const bool use_overlap); +bool isect_point_poly_v2_int(const int pt[2], const int verts[][2], const unsigned int nr, const bool use_overlap); int isect_point_quad_v2(const float p[2], const float a[2], const float b[2], const float c[2], const float d[2]); diff --git a/source/blender/blenlib/intern/lasso.c b/source/blender/blenlib/intern/lasso.c index 8e22d6f1182..e89f7fd795b 100644 --- a/source/blender/blenlib/intern/lasso.c +++ b/source/blender/blenlib/intern/lasso.c @@ -63,7 +63,7 @@ bool BLI_lasso_is_point_inside(const int mcords[][2], const unsigned int moves, } else { int pt[2] = {sx, sy}; - return isect_point_poly_v2_int(pt, mcords, moves); + return isect_point_poly_v2_int(pt, mcords, moves, true); } } diff --git a/source/blender/blenlib/intern/math_geom.c b/source/blender/blenlib/intern/math_geom.c index 65cfac86021..e45714f33da 100644 --- a/source/blender/blenlib/intern/math_geom.c +++ b/source/blender/blenlib/intern/math_geom.c @@ -712,7 +712,8 @@ int isect_line_sphere_v2(const float l1[2], const float l2[2], } /* point in polygon (keep float and int versions in sync) */ -bool isect_point_poly_v2(const float pt[2], const float verts[][2], const unsigned int nr) +bool isect_point_poly_v2(const float pt[2], const float verts[][2], const unsigned int nr, + const bool use_overlap) { /* we do the angle rule, define that all added angles should be about zero or (2 * PI) */ float angletot = 0.0; @@ -749,9 +750,18 @@ bool isect_point_poly_v2(const float pt[2], const float verts[][2], const unsign p1 = p2; } - return (fabsf(angletot) > 4.0f); + angletot = fabsf(angletot); + if (use_overlap) { + const int nested = floorf((angletot / (float)(M_PI * 2.0)) + 0.00001f); + angletot -= nested * (float)(M_PI * 2.0); + return (angletot > 4.0f) != (nested % 2); + } + else { + return (angletot > 4.0f); + } } -bool isect_point_poly_v2_int(const int pt[2], const int verts[][2], const unsigned int nr) +bool isect_point_poly_v2_int(const int pt[2], const int verts[][2], const unsigned int nr, + const bool use_overlap) { /* we do the angle rule, define that all added angles should be about zero or (2 * PI) */ float angletot = 0.0; @@ -788,7 +798,15 @@ bool isect_point_poly_v2_int(const int pt[2], const int verts[][2], const unsign p1 = p2; } - return (fabsf(angletot) > 4.0f); + angletot = fabsf(angletot); + if (use_overlap) { + const int nested = floorf((angletot / (float)(M_PI * 2.0)) + 0.00001f); + angletot -= nested * (float)(M_PI * 2.0); + return (angletot > 4.0f) != (nested % 2); + } + else { + return (angletot > 4.0f); + } } /* point in tri */ diff --git a/source/blender/bmesh/tools/bmesh_bisect_plane.c b/source/blender/bmesh/tools/bmesh_bisect_plane.c index e45ee75b8cd..4633d0db788 100644 --- a/source/blender/bmesh/tools/bmesh_bisect_plane.c +++ b/source/blender/bmesh/tools/bmesh_bisect_plane.c @@ -237,7 +237,7 @@ static void bm_face_bisect_verts(BMesh *bm, BMFace *f, const float plane[4], con face_verts_proj_2d[BM_VERT_LOOPINDEX(v_a)], face_verts_proj_2d[BM_VERT_LOOPINDEX(v_b)]); - if (isect_point_poly_v2(co_mid, (const float (*)[2])face_verts_proj_2d, f_len_orig)) { + if (isect_point_poly_v2(co_mid, (const float (*)[2])face_verts_proj_2d, f_len_orig, false)) { BMLoop *l_a, *l_b; bool found = false; unsigned int j; diff --git a/source/blender/editors/mesh/editmesh_knife.c b/source/blender/editors/mesh/editmesh_knife.c index 43cb15e065e..5e88ecabd35 100644 --- a/source/blender/editors/mesh/editmesh_knife.c +++ b/source/blender/editors/mesh/editmesh_knife.c @@ -3525,7 +3525,7 @@ static bool edbm_mesh_knife_face_isect(ARegion *ar, LinkNode *polys, BMFace *f, while (p) { const float (*mval_fl)[2] = p->link; const int mval_tot = MEM_allocN_len(mval_fl) / sizeof(*mval_fl); - isect += (int)isect_point_poly_v2(cent_ss, mval_fl, mval_tot - 1); + isect += (int)isect_point_poly_v2(cent_ss, mval_fl, mval_tot - 1, false); p = p->next; } |