In this code block:
# p1 is starting or anchor point of the line segment foreach my $p1 (@{$points}) { # p2 is end point of the line segment foreach my $p2 (@{$points}) { # We don't need to caculate if anchor and end are the same # or we have already seen these two pairs [reversed] before unless ( ($p1 == $p2) || $found->{$p2}->{$p1} ) { # Compute the edge my $edge = sqrt( ($p1->[0] - $p2->[0])**2 + ($p1->[1] - $p2->[1])**2 ); # Push the whole thing on a stack push (@edges, [ $edge, $p1->[0], $p1->[1], $p2->[0], $p2->[1] +]); # Keep track of the edges we've already computed (no need to d +o so twice) $found->{$p2}->{$p1} = 1; } } }
Can you perhaps do:
# outer loop goes through all points for my $i ( 0 .. $#{$points}) { # inner loop only through those not visited yet for my $j ( ( $i + 1 ) .. $#{$points}) { # Compute the edge my $edge = sqrt( ( $points->[$i][0] - $points->[$j][0] )**2 + ( $points->[$i][1] - $points->[$j][1] )**2 ); # Push the whole thing on a stack push (@edges, [ $edge, $points->[$i][0], $points->[$i][1], $points->[$j][0], $points->[$j][1] ] ); } } }
I don't know enough about the problem space to be sure this is helpful or hurtful...

In reply to Re: Millions of line segment intersection calcs: Looking for speed tips by rvosa
in thread Millions of line segment intersection calcs: Looking for speed tips by drewhead

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.