--------------------------------------------------------------------- segSegInt: Finds the point of intersection p between two closed segments ab and cd. Returns p and a char with the following meaning: 'e': The segments collinearly overlap, sharing a point. 'v': An endpoint (vertex) of one segment is on the other segment, but 'e' doesn't hold. '1': The segments intersect properly (i.e., they sha
| 390 | // of each, returns 'e' rather than 'v' as one might expect. |
| 391 | //--------------------------------------------------------------------- |
| 392 | static char segSegInt( Point2f a, Point2f b, Point2f c, Point2f d, Point2f& p, Point2f& q ) |
| 393 | { |
| 394 | double s, t; // The two parameters of the parametric eqns. |
| 395 | double num, denom; // Numerator and denoninator of equations. |
| 396 | char code = '?'; // Return char characterizing intersection. |
| 397 | |
| 398 | denom = a.x * (double)( d.y - c.y ) + |
| 399 | b.x * (double)( c.y - d.y ) + |
| 400 | d.x * (double)( b.y - a.y ) + |
| 401 | c.x * (double)( a.y - b.y ); |
| 402 | |
| 403 | // If denom is zero, then segments are parallel: handle separately. |
| 404 | if (denom == 0.0) |
| 405 | return parallelInt(a, b, c, d, p, q); |
| 406 | |
| 407 | num = a.x * (double)( d.y - c.y ) + |
| 408 | c.x * (double)( a.y - d.y ) + |
| 409 | d.x * (double)( c.y - a.y ); |
| 410 | if ( (num == 0.0) || (num == denom) ) code = 'v'; |
| 411 | s = num / denom; |
| 412 | |
| 413 | num = -( a.x * (double)( c.y - b.y ) + |
| 414 | b.x * (double)( a.y - c.y ) + |
| 415 | c.x * (double)( b.y - a.y ) ); |
| 416 | if ( (num == 0.0) || (num == denom) ) code = 'v'; |
| 417 | t = num / denom; |
| 418 | |
| 419 | if ( (0.0 < s) && (s < 1.0) && |
| 420 | (0.0 < t) && (t < 1.0) ) |
| 421 | code = '1'; |
| 422 | else if ( (0.0 > s) || (s > 1.0) || |
| 423 | (0.0 > t) || (t > 1.0) ) |
| 424 | code = '0'; |
| 425 | |
| 426 | p.x = (float)(a.x + s*(b.x - a.x)); |
| 427 | p.y = (float)(a.y + s*(b.y - a.y)); |
| 428 | |
| 429 | return code; |
| 430 | } |
| 431 | |
| 432 | static tInFlag inOut( Point2f p, tInFlag inflag, int aHB, int bHA, Point2f*& result ) |
| 433 | { |
no test coverage detected