How to determine if a ray intersects a wedge in 2d space

How much (length) of a straight line is enclosed within the boundaries of a 2-D domain of interest? The answer is: $$ \oint H\left[\cos(\phi)(x-p)+\sin(\phi)(y-q)\right]\left[-\sin(\phi).dx+\cos(\phi).dy\,\right] $$ Here $\oint$ is the contour integral around the domain of interest; $H[\cdots]$ is the Heaviside step function; $\phi$ is the angle of the normal of the straight line with the $x$-axis; $(p,q)$ is just a point on the line.
A picture says more than a thousand words:

More details are found in the section" Sharpened Lines and Contours" at page 10-11 near the end of this PDF document: