MCPcopy Create free account
hub / github.com/OSGeo/gdal / getIntersection

Function getIntersection

alg/gdalwarpkernel.cpp:8516–8540  ·  view source on GitHub ↗

Returns intersection of [p1,p2] with [p3,p4], if * it is a single point, and the 2 segments are not colinear. */

Source from the content-addressed store, hash-verified

8514 * it is a single point, and the 2 segments are not colinear.
8515 */
8516static bool getIntersection(const XYPair &p1, const XYPair &p2,
8517 const XYPair &p3, const XYPair &p4, XYPair &xy)
8518{
8519 const double x1 = p1.first;
8520 const double y1 = p1.second;
8521 const double x2 = p2.first;
8522 const double y2 = p2.second;
8523 const double x3 = p3.first;
8524 const double y3 = p3.second;
8525 const double x4 = p4.first;
8526 const double y4 = p4.second;
8527 const double t_num = (x1 - x3) * (y3 - y4) - (y1 - y3) * (x3 - x4);
8528 const double denom = (x1 - x2) * (y3 - y4) - (y1 - y2) * (x3 - x4);
8529 if (t_num * denom < 0 || std::abs(t_num) > std::abs(denom) || denom == 0)
8530 return false;
8531
8532 const double u_num = (x1 - x3) * (y1 - y2) - (y1 - y3) * (x1 - x2);
8533 if (u_num * denom < 0 || std::abs(u_num) > std::abs(denom))
8534 return false;
8535
8536 const double t = t_num / denom;
8537 xy.first = x1 + t * (x2 - x1);
8538 xy.second = y1 + t * (y2 - y1);
8539 return true;
8540}
8541
8542/************************************************************************/
8543/* getConvexPolyIntersection() */

Callers 2

GWKSumPreservingThreadFunction · 0.85

Calls 1

absFunction · 0.85

Tested by

no test coverage detected