/**
* Author: Victor Lecomte, chilli
* Date: 2019-04-27
* License: CC0
* Source: https://vlecomte.github.io/cp-geo.pdf
* Description:\\
\begin{minipage}{75mm}
If a unique intersection point between the line segments going from s1 to e1 and from s2 to e2 exists then it is returned.
If no intersection point exists an empty vector is returned.
If infinitely many exist a vector with 2 elements is returned, containing the endpoints of the common line segment.
The wrong position will be returned if P is Point<ll> and the intersection point does not have integer coordinates.
Products of three coordinates are used in intermediate steps so watch out for overflow if using int or long long.
\end{minipage}
\begin{minipage}{15mm}
\includegraphics[width=\textwidth]{src/geometry/SegmentIntersection}
\end{minipage}
* Usage:
* vector<P> inter = segInter(s1,e1,s2,e2);
* if (sz(inter)==1)
* cout << "segments intersect at " << inter[0] << endl;
* Status: stress-tested, tested on kattis:intersection
*/#pragma once
#include"src/geometry/Point.h"
#include"src/geometry/OnSegment.h"template<classP>vector<P>segInter(Pa,Pb,Pc,Pd){autooa=c.cross(d,a),ob=c.cross(d,b),oc=a.cross(b,c),od=a.cross(b,d);// Checks if intersection is single non-endpoint point.if(sgn(oa)*sgn(ob)<0&&sgn(oc)*sgn(od)<0)return{(a*ob-b*oa)/(ob-oa)};set<P>s;if(onSegment(c,d,a))s.insert(a);if(onSegment(c,d,b))s.insert(b);if(onSegment(a,b,c))s.insert(c);if(onSegment(a,b,d))s.insert(d);return{all(s)};}
Traceback(mostrecentcalllast):File"/opt/hostedtoolcache/Python/3.14.0/x64/lib/python3.14/site-packages/onlinejudge_verify/documentation/build.py",line71,in_render_source_code_statbundled_code=language.bundle(stat.path,basedir=basedir,options={'include_paths':[basedir]}).decode()~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^File"/opt/hostedtoolcache/Python/3.14.0/x64/lib/python3.14/site-packages/onlinejudge_verify/languages/cplusplus.py",line187,inbundlebundler.update(path)~~~~~~~~~~~~~~^^^^^^File"/opt/hostedtoolcache/Python/3.14.0/x64/lib/python3.14/site-packages/onlinejudge_verify/languages/cplusplus_bundle.py",line312,inupdateraiseBundleErrorAt(path,i+1,"#pragma once found in a non-first line")onlinejudge_verify.languages.cplusplus_bundle.BundleErrorAt:src/geometry/SegmentIntersection.h:line23:#pragmaoncefoundinanon-firstline