Cleanup: rename line to segments, avoids confusion

Differentiate between lines and segments.
This commit is contained in:
Campbell Barton 2015-11-13 07:25:36 +11:00
parent 930771d0cf
commit a7ac59414b
Notes: blender-bot 2023-02-14 10:54:29 +01:00
Referenced by issue #46757, Blender Close when try to render an Animation
10 changed files with 53 additions and 44 deletions

View File

@ -253,7 +253,7 @@ static void feather_bucket_check_intersect(
if (check_a >= cur_a - 1 || cur_b == check_a)
continue;
if (isect_seg_seg_v2(v1, v2, v3, v4)) {
if (isect_seg_seg_v2_simple(v1, v2, v3, v4)) {
int k;
float p[2];
float min_a[2], max_a[2];

View File

@ -154,25 +154,31 @@ void limit_dist_v3(float v1[3], float v2[3], const float dist);
#define ISECT_LINE_LINE_EXACT 1
#define ISECT_LINE_LINE_CROSS 2
int isect_line_line_v2_point(const float v0[2], const float v1[2], const float v2[2], const float v3[2], float r_vi[2]);
int isect_line_line_v2(const float a1[2], const float a2[2], const float b1[2], const float b2[2]);
int isect_line_line_v2_int(const int a1[2], const int a2[2], const int b1[2], const int b2[2]);
int isect_seg_seg_v2(const float a1[2], const float a2[2], const float b1[2], const float b2[2]);
int isect_seg_seg_v2_int(const int a1[2], const int a2[2], const int b1[2], const int b2[2]);
int isect_seg_seg_v2_point(const float v0[2], const float v1[2], const float v2[2], const float v3[2], float vi[2]);
bool isect_seg_seg_v2_simple(const float v1[2], const float v2[2], const float v3[2], const float v4[2]);
int isect_line_sphere_v3(const float l1[3], const float l2[3], const float sp[3], const float r, float r_p1[3], float r_p2[3]);
int isect_line_sphere_v2(const float l1[2], const float l2[2], const float sp[2], const float r, float r_p1[2], float r_p2[2]);
int isect_seg_seg_v2_point(const float v0[2], const float v1[2], const float v2[2], const float v3[2], float vi[2]);
bool isect_seg_seg_v2(const float v1[2], const float v2[2], const float v3[2], const float v4[2]);
int isect_line_line_v2_point(
const float v0[2], const float v1[2],
const float v2[2], const float v3[2],
float r_vi[2]);
int isect_line_line_epsilon_v3(
const float v1[3], const float v2[3],
const float v3[3], const float v4[3], float i1[3], float i2[3],
const float v3[3], const float v4[3],
float i1[3], float i2[3],
const float epsilon);
int isect_line_line_v3(
const float v1[3], const float v2[3],
const float v3[3], const float v4[3],
float i1[3], float i2[3]);
bool isect_line_line_strict_v3(const float v1[3], const float v2[3],
const float v3[3], const float v4[3],
float vi[3], float *r_lambda);
float r_i1[3], float r_i2[3]);
bool isect_line_line_strict_v3(
const float v1[3], const float v2[3],
const float v3[3], const float v4[3],
float vi[3], float *r_lambda);
bool isect_ray_plane_v3(
const float p1[3], const float d[3],

View File

@ -87,9 +87,9 @@ bool BLI_lasso_is_edge_inside(const int mcords[][2], const unsigned int moves,
/* no points in lasso, so we have to intersect with lasso edge */
if (isect_line_line_v2_int(mcords[0], mcords[moves - 1], v1, v2) > 0) return true;
if (isect_seg_seg_v2_int(mcords[0], mcords[moves - 1], v1, v2) > 0) return true;
for (a = 0; a < moves - 1; a++) {
if (isect_line_line_v2_int(mcords[a], mcords[a + 1], v1, v2) > 0) return true;
if (isect_seg_seg_v2_int(mcords[a], mcords[a + 1], v1, v2) > 0) return true;
}
return false;

View File

@ -649,7 +649,7 @@ void closest_on_tri_to_point_v3(float r[3], const float p[3],
/******************************* Intersection ********************************/
/* intersect Line-Line, shorts */
int isect_line_line_v2_int(const int v1[2], const int v2[2], const int v3[2], const int v4[2])
int isect_seg_seg_v2_int(const int v1[2], const int v2[2], const int v3[2], const int v4[2])
{
float div, lambda, mu;
@ -692,7 +692,7 @@ int isect_line_line_v2_point(const float v0[2], const float v1[2], const float v
}
/* intersect Line-Line, floats */
int isect_line_line_v2(const float v1[2], const float v2[2], const float v3[2], const float v4[2])
int isect_seg_seg_v2(const float v1[2], const float v2[2], const float v3[2], const float v4[2])
{
float div, lambda, mu;
@ -714,7 +714,10 @@ int isect_line_line_v2(const float v1[2], const float v2[2], const float v3[2],
* -1: collinear
* 1: intersection
*/
int isect_seg_seg_v2_point(const float v0[2], const float v1[2], const float v2[2], const float v3[2], float r_vi[2])
int isect_seg_seg_v2_point(
const float v0[2], const float v1[2],
const float v2[2], const float v3[2],
float r_vi[2])
{
float s10[2], s32[2], s30[2], d;
const float eps = 1e-6f;
@ -813,7 +816,7 @@ int isect_seg_seg_v2_point(const float v0[2], const float v1[2], const float v2[
}
}
bool isect_seg_seg_v2(const float v1[2], const float v2[2], const float v3[2], const float v4[2])
bool isect_seg_seg_v2_simple(const float v1[2], const float v2[2], const float v3[2], const float v4[2])
{
#define CCW(A, B, C) \
((C[1] - A[1]) * (B[0] - A[0]) > \
@ -824,17 +827,15 @@ bool isect_seg_seg_v2(const float v1[2], const float v2[2], const float v3[2], c
#undef CCW
}
/**
* \param l1, l2: Coordinates (point of line).
* \param sp, r: Coordinate and radius (sphere).
* \return r_p1, r_p2: Intersection coordinates.
*/
int isect_line_sphere_v3(const float l1[3], const float l2[3],
const float sp[3], const float r,
float r_p1[3], float r_p2[3])
{
/* l1: coordinates (point of line)
* l2: coordinates (point of line)
* sp, r: coordinates and radius (sphere)
* r_p1, r_p2: return intersection coordinates
*/
/* adapted for use in blender by Campbell Barton - 2011
*
* atelier iebele abel - 2001
@ -2011,7 +2012,8 @@ bool isect_axial_line_tri_v3(const int axis, const float p1[3], const float p2[3
*/
int isect_line_line_epsilon_v3(
const float v1[3], const float v2[3],
const float v3[3], const float v4[3], float i1[3], float i2[3],
const float v3[3], const float v4[3],
float r_i1[3], float r_i2[3],
const float epsilon)
{
float a[3], b[3], c[3], ab[3], cb[3];
@ -2035,8 +2037,8 @@ int isect_line_line_epsilon_v3(
cross_v3_v3v3(cb, c, b);
mul_v3_fl(a, dot_v3v3(cb, ab) / div);
add_v3_v3v3(i1, v1, a);
copy_v3_v3(i2, i1);
add_v3_v3v3(r_i1, v1, a);
copy_v3_v3(r_i2, r_i1);
return 1; /* one intersection only */
}
@ -2062,10 +2064,10 @@ int isect_line_line_epsilon_v3(
cross_v3_v3v3(cb, c, b);
mul_v3_fl(a, dot_v3v3(cb, ab) / dot_v3v3(ab, ab));
add_v3_v3v3(i1, v1, a);
add_v3_v3v3(r_i1, v1, a);
/* for the second line, just substract the offset from the first intersection point */
sub_v3_v3v3(i2, i1, t);
sub_v3_v3v3(r_i2, r_i1, t);
return 2; /* two nearest points */
}
@ -2073,10 +2075,11 @@ int isect_line_line_epsilon_v3(
int isect_line_line_v3(
const float v1[3], const float v2[3],
const float v3[3], const float v4[3], float i1[3], float i2[3])
const float v3[3], const float v4[3],
float r_i1[3], float r_i2[3])
{
const float epsilon = 0.000001f;
return isect_line_line_epsilon_v3(v1, v2, v3, v4, i1, i2, epsilon);
return isect_line_line_epsilon_v3(v1, v2, v3, v4, r_i1, r_i2, epsilon);
}
/** Intersection point strictly between the two lines
@ -4591,13 +4594,13 @@ bool is_quad_convex_v3(const float v1[3], const float v2[3], const float v3[3],
mul_v2_m3v3(vec[3], mat, v4);
/* linetests, the 2 diagonals have to instersect to be convex */
return (isect_line_line_v2(vec[0], vec[2], vec[1], vec[3]) > 0);
return (isect_seg_seg_v2(vec[0], vec[2], vec[1], vec[3]) > 0);
}
bool is_quad_convex_v2(const float v1[2], const float v2[2], const float v3[2], const float v4[2])
{
/* linetests, the 2 diagonals have to instersect to be convex */
return (isect_line_line_v2(v1, v3, v2, v4) > 0);
return (isect_seg_seg_v2(v1, v3, v2, v4) > 0);
}
bool is_poly_convex_v2(const float verts[][2], unsigned int nr)

View File

@ -173,7 +173,7 @@ bool BLI_rcti_inside_rcti(rcti *rct_a, const rcti *rct_b)
}
/* based closely on 'isect_line_line_v2_int', but in modified so corner cases are treated as intersections */
/* based closely on 'isect_seg_seg_v2_int', but in modified so corner cases are treated as intersections */
static int isect_segments_i(const int v1[2], const int v2[2], const int v3[2], const int v4[2])
{
const double div = (double)((v2[0] - v1[0]) * (v4[1] - v3[1]) - (v2[1] - v1[1]) * (v4[0] - v3[0]));

View File

@ -1672,7 +1672,7 @@ static void knife_find_line_hits(KnifeTool_OpData *kcd)
knife_project_v2(kcd, kfe->v2->cageco, se2);
isect_kind = (kfe_verts_in_cut) ? -1 : isect_seg_seg_v2_point(s1, s2, se1, se2, sint);
if (isect_kind == -1) {
/* isect_seg_seg_v2 doesn't do tolerance test around ends of s1-s2 */
/* isect_seg_seg_v2_simple doesn't do tolerance test around ends of s1-s2 */
closest_to_line_segment_v2(sint, s1, se1, se2);
if (len_squared_v2v2(sint, s1) <= line_tol_sq)
isect_kind = 1;
@ -2480,7 +2480,7 @@ static bool find_hole_chains(KnifeTool_OpData *kcd, ListBase *hole, BMFace *f, L
for (k = 0; k < nh && ok; k++) {
if (k == i || (k + 1) % nh == i)
continue;
if (isect_line_line_v2(hco[i], fco[j], hco[k], hco[(k + 1) % nh]))
if (isect_seg_seg_v2(hco[i], fco[j], hco[k], hco[(k + 1) % nh]))
ok = false;
}
if (!ok)
@ -2488,7 +2488,7 @@ static bool find_hole_chains(KnifeTool_OpData *kcd, ListBase *hole, BMFace *f, L
for (k = 0; k < nf && ok; k++) {
if (k == j || (k + 1) % nf == j)
continue;
if (isect_line_line_v2(hco[i], fco[j], fco[k], fco[(k + 1) % nf]))
if (isect_seg_seg_v2(hco[i], fco[j], fco[k], fco[(k + 1) % nf]))
ok = false;
}
if (ok) {

View File

@ -2989,10 +2989,10 @@ static bool project_bucket_face_isect(ProjPaintState *ps, int bucket_x, int buck
isect_point_tri_v2(p3, v1, v2, v3) ||
isect_point_tri_v2(p4, v1, v2, v3) ||
/* we can avoid testing v3,v1 because another intersection MUST exist if this intersects */
(isect_line_line_v2(p1, p2, v1, v2) || isect_line_line_v2(p1, p2, v2, v3)) ||
(isect_line_line_v2(p2, p3, v1, v2) || isect_line_line_v2(p2, p3, v2, v3)) ||
(isect_line_line_v2(p3, p4, v1, v2) || isect_line_line_v2(p3, p4, v2, v3)) ||
(isect_line_line_v2(p4, p1, v1, v2) || isect_line_line_v2(p4, p1, v2, v3)))
(isect_seg_seg_v2(p1, p2, v1, v2) || isect_seg_seg_v2(p1, p2, v2, v3)) ||
(isect_seg_seg_v2(p2, p3, v1, v2) || isect_seg_seg_v2(p2, p3, v2, v3)) ||
(isect_seg_seg_v2(p3, p4, v1, v2) || isect_seg_seg_v2(p3, p4, v2, v3)) ||
(isect_seg_seg_v2(p4, p1, v1, v2) || isect_seg_seg_v2(p4, p1, v2, v3)))
{
return 1;
}

View File

@ -91,7 +91,7 @@ static int cut_links_intersect(uiLinkLine *line, float mcoords[][2], int tot)
if (ui_link_bezier_points(&rectlink, coord_array, LINK_RESOL)) {
for (i=0; i<tot-1; i++)
for (b=0; b<LINK_RESOL-1; b++)
if (isect_line_line_v2(mcoords[i], mcoords[i+1], coord_array[b], coord_array[b+1]) > 0)
if (isect_seg_seg_v2(mcoords[i], mcoords[i + 1], coord_array[b], coord_array[b + 1]) > 0)
return 1;
}
return 0;

View File

@ -107,7 +107,7 @@ static bool add_reroute_intersect_check(bNodeLink *link, float mcoords[][2], int
for (i = 0; i < tot - 1; i++)
for (b = 0; b < NODE_LINK_RESOL; b++)
if (isect_line_line_v2(mcoords[i], mcoords[i + 1], coord_array[b], coord_array[b + 1]) > 0) {
if (isect_seg_seg_v2(mcoords[i], mcoords[i + 1], coord_array[b], coord_array[b + 1]) > 0) {
result[0] = (mcoords[i][0] + mcoords[i + 1][0]) / 2.0f;
result[1] = (mcoords[i][1] + mcoords[i + 1][1]) / 2.0f;
return 1;

View File

@ -858,7 +858,7 @@ static bool cut_links_intersect(bNodeLink *link, float mcoords[][2], int tot)
for (i = 0; i < tot - 1; i++)
for (b = 0; b < NODE_LINK_RESOL; b++)
if (isect_line_line_v2(mcoords[i], mcoords[i + 1], coord_array[b], coord_array[b + 1]) > 0)
if (isect_seg_seg_v2(mcoords[i], mcoords[i + 1], coord_array[b], coord_array[b + 1]) > 0)
return 1;
}
return 0;