Lucas,<div><br></div><div>Thank you for the detailed response. �The data was actually from our application and the only reason I was investigating was because the application was performing poorly. �However, as it turns out the application was faulty and generating polygons that were inappropriate.</div>

<div><br></div><div>I had noticed the divide and conquer further up the stack, but as with most code unfamiliar to you, misunderstandings are easy to make so I wanted to make sure.</div><div><br></div><div>Regards,</div>
<div>
Josh Pieper<br><br><div class="gmail_quote">On Wed, Jan 19, 2011 at 12:37 PM, Simonson, Lucanus J <span dir="ltr">&lt;<a href="mailto:lucanus.j.simonson@intel.com">lucanus.j.simonson@intel.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">

<div class="im">Josh Pieper wrote:<br>
&gt;First: we are using boost 1.45.0 with gcc -O3 on Ubuntu 10.04. �(Although similar problems appear with &gt;VS2008 on Windows 7).<br>
&gt;<br>
&gt;We have been observing performance with boost::polygon that is significantly worse than we were<br>
&gt;expecting when working with any angle polygons. �Namely quadratic instead of the expected O(n log n).<br>
&gt;While profiling, I noticed that most of the time is spent in the overload of<br>
&gt;line_intersection::validate_scan at detail/scan_arbitrary.hpp:154 which is commented as: &quot;//quadratic<br>
&gt;algorithm to do same work as optimal scan for cross checking&quot;.<br>
&gt;<br>
&gt;I have inlined our test program below, and some performance results measured by instruction count<br>
&gt;under &quot;valgrind --tool=callgrind&quot;. �Is this poor performance because our data is degenerate, or<br>
&gt;because a vestigal quadratic double check is still being applied?<br>
<br>
</div>So a couple things need explaining. �The validate scan is worst case quatratic. �The expected runtime of this function is O(n^1.5) if we assume that sqrt(n) edges intersect the sweepline at any given time. �It was originally written to validate the bentley ottman sweepline algorithm I was working on but then I found it to be quite fast and put it into production usage without changing the name since it is an implementation detail. �Moreover, you will notice that it is being called from a function with divide an conquer in the name. �On top of the suboptimal validate_scan algorithm I am doing a divide and conquer. �This approximates the optimal O(n log n) performance in the cases where the data is ammenible to divide and conquer (which is commonly the case.) �Finally, your data appears to be randomly generated edges that you inflate by some small ammount in the edge_plus object, which is a worst case for line intersection. �In randomly generated data the expected number of lin<br>


�e intersections is O(n^2). �Any line intersection will have O(n^2) (or worse) runtime wrt input points on randomly generated data. �Whenever I state the algorithmic complexity of the algorithm I always specific that n is input points plus line intersection points. �I also document that I use divide and conquer. �There are pathological cases where divide and conquer doesn&#39;t help and even where the average number of line segments intersecting the sweepline is O(n) (think many parallel strips at 45 degrees). �These cases are fairly artificial. �In PCB or package layout where such data would commonly be seen divide and conquer usually is of benefit because 45 degree strips across the entire package or board isn&#39;t going to implement a circuit.<br>


<br>
Benchmarking polygon clipping can be tricky. �It is just as easy to benchmark a best case input and conclude fantastic performance as to benchmark a worst case and conclude terrible performance. �It is a little harder to get the real story. �I suggest using application data and collecting requirements for performance for your application. �The performance isn&#39;t poor unless it doesn&#39;t meet requirements on your application data or you have an alternative that is way faster.<br>


<br>
Regards,<br>
Luke<br>
<br>
<br>
_______________________________________________<br>
Boost-users mailing list<br>
<a href="mailto:Boost-users@lists.boost.org">Boost-users@lists.boost.org</a><br>
<a href="http://lists.boost.org/mailman/listinfo.cgi/boost-users" target="_blank">http://lists.boost.org/mailman/listinfo.cgi/boost-users</a><br>
</blockquote></div><br></div>