Recent changes to 40: Contour clockwise test is not robusthttps://sourceforge.net/p/ftgl/bugs/40/Recent changes to 40: Contour clockwise test is not robustenSat, 18 May 2013 06:05:35 -0000Contour clockwise test is not robusthttps://sourceforge.net/p/ftgl/bugs/40/<div class="markdown_content"><p>On glyphs with duplicated points in the contour, the test for clockwise/anti-clockwise in FTContour::FTContour may fail, as the code tries to calculate the angle between degenerate points.</p>
<p>This can be repaired by using a signed area test for determining the winding, with the added benefit that all the expensive atan2 calls are avoided.</p>
<p>Code snippet below:</p>
<p>// Deterine the orientation of the contour by calculating the signed area of its control points.<br />
// This is robust to repeated control points, and requires to trig functions.<br />
double signedArea2 = 0.0; // This is really *twice* the signed area (though we're only checking sign)<br />
for(unsigned int i = 0; i < n; i++) {<br />
FTPoint pt0 = contour[i];<br />
FTPoint pt1 = contour[(i+1)%n];<br />
double a = (pt0.X()*pt1.Y() - pt0.Y()*pt1.X());<br />
signedArea2 += a;<br />
}<br />
clockwise = (signedArea2 <= 0.0);</p></div>Frank HickmanSat, 18 May 2013 06:05:35 -0000https://sourceforge.netb635e434c3c93c36f7eb3cc6d1ce348ef778161e