| 446 | // Precondition: ab and cd intersect normally |
| 447 | template <typename T> |
| 448 | V2d<T> intersectionPosition( |
| 449 | const V2d<T>& a, |
| 450 | const V2d<T>& b, |
| 451 | const V2d<T>& c, |
| 452 | const V2d<T>& d) |
| 453 | { |
| 454 | using namespace predicates::adaptive; |
| 455 | |
| 456 | // note: for better accuracy we interpolate x and y separately |
| 457 | // on a segment with the shortest x/y-projection correspondingly |
| 458 | const T a_cd = orient2d(c.x, c.y, d.x, d.y, a.x, a.y); |
| 459 | const T b_cd = orient2d(c.x, c.y, d.x, d.y, b.x, b.y); |
| 460 | const T t_ab = a_cd / (a_cd - b_cd); |
| 461 | |
| 462 | const T c_ab = orient2d(a.x, a.y, b.x, b.y, c.x, c.y); |
| 463 | const T d_ab = orient2d(a.x, a.y, b.x, b.y, d.x, d.y); |
| 464 | const T t_cd = c_ab / (c_ab - d_ab); |
| 465 | |
| 466 | return V2d<T>( |
| 467 | std::fabs(a.x - b.x) < std::fabs(c.x - d.x) ? lerp(a.x, b.x, t_ab) |
| 468 | : lerp(c.x, d.x, t_cd), |
| 469 | std::fabs(a.y - b.y) < std::fabs(c.y - d.y) ? lerp(a.y, b.y, t_ab) |
| 470 | : lerp(c.y, d.y, t_cd)); |
| 471 | } |
| 472 | |
| 473 | } // namespace detail |
| 474 |
no test coverage detected