fix for lasso selection (in non-zbuf mode) when the line intersected its self.
isect_point_poly_v2() - add argument to check overlapping areas.
This commit is contained in:
@@ -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]);
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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 */
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user