Note that there are some explanatory texts on larger screens.

plurals
  1. POHit-testing line segments
    primarykey
    data
    text
    <p>1) I have a list of line segments (defined by their two endpoints and a width.)<br> 2) These line segments are drawn in a panel.<br> 3) When my mouse moves (Panel.MouseMove event), I loop over the list of line segments.<br> 4) Foreach:</p> <pre><code> gPath.Reset(); Pen Pen = new Pen(Color.White, 20); gPath.AddLine(P1, P2); return gPath.IsOutlineVisible(cursorPos, Pen); </code></pre> <p>5) If I get true, then I know my cursor is hovering over the current line segment. </p> <p>This works fine for about... 300 lines or so. When I reach 1,000 my program slows to a halt (profiling shows that it's caused by IsOutlineVisible). So, is there any way I could increase performance of my hit-testing algorithm? I don't know how efficient IsOutlineVisible is, so I don't want to implement any optimizations that the method already uses. Any ideas?</p> <p><strong>EDIT:</strong><br> After digging into my data I noticed some of the lines were extremely large. For example:<br> endpoint1 = (16000, -16000)<br> endpoint2 = (5041448, -32868734)</p> <p>(yes, one of the coordinates is in the negative tens of millions...)</p> <p>I verified that hit-testing against just one such line segment is enough to bring my program to a halt, (IsOutlineVisible takes 2-3 seconds to do the test, and the test is run whenever the cursor moves...).</p> <p>I should have tested this more thoroughly before posting. Thanks to all that responded (a 2d spatial index is a great suggestion if I end-up handling thousands of lines). </p> <p>p.s. If anyone knows why a large line-segment is that big a problem for IsOutlineVisible, that would be great.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload