Skip to content

Commit cb2db5b

Browse files
committed
Removed some extra functions. Some minor modifications.
1 parent dc2255c commit cb2db5b

File tree

1 file changed

+3
-66
lines changed

1 file changed

+3
-66
lines changed

Diff for: tsp.c

+3-66
Original file line numberDiff line numberDiff line change
@@ -451,6 +451,7 @@ bool vertex3(int *v3)
451451
return true;
452452
}
453453

454+
// ----------------------------------------------------------- //
454455
#define MIN_DIFF 5
455456
#define EPS 0.01
456457
bool same_coor(city c1, city c2)
@@ -460,71 +461,6 @@ bool same_coor(city c1, city c2)
460461
return false;
461462
}
462463

463-
// TODO visit: https://rosettacode.org/wiki/Find_the_intersection_of_two_lines#C
464-
float line_slope(city a,city b){
465-
466-
if(a.x-b.x == 0.0)
467-
return NAN;
468-
else
469-
return (a.y-b.y)/(a.x-b.x);
470-
}
471-
city intersection_point(city a1,city a2,city b1,city b2){
472-
city c;
473-
474-
float slopeA = line_slope(a1,a2);
475-
float slopeB = line_slope(b1,b2);
476-
477-
if(slopeA==slopeB)
478-
{
479-
c.x = NAN;
480-
c.y = NAN;
481-
}
482-
else if(isnan(slopeA) && !isnan(slopeB))
483-
{
484-
c.x = a1.x;
485-
c.y = (a1.x-b1.x)*slopeB + b1.y;
486-
}
487-
else if(isnan(slopeB) && !isnan(slopeA))
488-
{
489-
c.x = b1.x;
490-
c.y = (b1.x-a1.x)*slopeA + a1.y;
491-
}
492-
else
493-
{
494-
c.x = (slopeA*a1.x - slopeB*b1.x + b1.y - a1.y)/(slopeA - slopeB);
495-
c.y = slopeB*(c.x - b1.x) + b1.y;
496-
}
497-
498-
return c;
499-
}
500-
501-
int point_in_poly(int nvert, float *vertx, float *verty, float testx, float testy)
502-
{
503-
int i, j, c = 0;
504-
for (i = 0, j = nvert-1; i < nvert; j = i++) {
505-
if ( ((verty[i]>testy) != (verty[j]>testy)) &&
506-
(testx < (vertx[j]-vertx[i]) * (testy-verty[i]) / (verty[j]-verty[i]) + vertx[i]) )
507-
c = !c;
508-
}
509-
return c;
510-
}
511-
bool point_in_quadrilateral(city a1, city a2, city b1, city b2)
512-
{
513-
int c;
514-
float vertx[4]={a1.x, a2.x, b1.x, b2.x};
515-
float verty[4]={a1.y, a2.y, b1.y, b2.y};
516-
517-
city ip = intersection_point(a1, a2, b1, b2);
518-
if(isnan(ip.x))
519-
return false;
520-
c = point_in_poly(4, vertx, verty, ip.x, ip.y);
521-
if(c==0)
522-
return false;
523-
return true;
524-
}
525-
526-
// Returns 1 if the lines intersect, otherwise 0. In addition, if the lines
527-
// intersect the intersection point may be stored in the floats i_x and i_y.
528464
bool get_line_intersection(float p0_x, float p0_y, float p1_x, float p1_y,
529465
float p2_x, float p2_y, float p3_x, float p3_y)
530466
{
@@ -542,6 +478,7 @@ bool get_line_intersection(float p0_x, float p0_y, float p1_x, float p1_y,
542478
float i_x = p0_x + (t * s1_x);
543479
float i_y = p0_y + (t * s1_y);
544480

481+
// Ignore intersection of vertices
545482
if(fabs(i_x-p0_x)<EPS && fabs(i_y-p0_y)<EPS)
546483
return false;
547484
if(fabs(i_x-p1_x)<EPS && fabs(i_y-p1_y)<EPS)
@@ -550,7 +487,7 @@ bool get_line_intersection(float p0_x, float p0_y, float p1_x, float p1_y,
550487
return false;
551488
if(fabs(i_x-p3_x)<EPS && fabs(i_y-p3_y)<EPS)
552489
return false;
553-
490+
554491
return true;
555492
}
556493

0 commit comments

Comments
 (0)