What does that mean?

Code fragment is only reached if illuminated interval at particular latitude doesn't cross map border. Won't happen at 12 GMT. It also means replacing that loop won't affect time I posted because of 12 GMT chosen for a test.

Looks like I robbed humanity of 45s (24 hours / 1920) of their precious daytime, off by 1 error in patch above. Fixed below.

I also came to significantly faster solution, but have to decide what to do with rounding errors and glitches which are possible very close to equinoxes with maths as implemented in this module. Unseen possible stray pixel with current solution, but unacceptable if polygon lines jump from pole to pole for daytime illumination area. May lead to a few heart attacks among astronomers or geographers etc. But absolutely don't wont to re-do all trigonometry from scratch, need more time for a hack which would seem reliable enough.

--- WorldMap.pm.old Fri Jun 17 10:33:43 2016 +++ WorldMap.pm Wed Dec 14 12:18:17 2022 @@ -500,7 +500,7 @@ my ($wtab, $noon, $width, $height) = @_; my $illumMap = Imager->new(ysize => $height, xsize => $width); $illumMap = $illumMap->convert(preset => 'addalpha'); - my $day = Imager::Color->new(255, 255, 255, 10); + my $day_p = pack 'C4', 255, 255, 255, 10; my ($i, $j, $oh, $nl, $nh); for ($i = 0; $i < $height; $i++) { @@ -510,16 +510,13 @@ $oh = ($nh - $nl) + 1; if (($nl + $oh) > $width) { - for ($j = $nl; $j < $width; $j++) { - $illumMap->setpixel(x => $j, y => $i, color => $d +ay); - } - for ($j = 0; $j < ((($nl + $oh) - $width) + 1); $j++) + { - $illumMap->setpixel(x => $j, y => $i, color => $d +ay); - } + $illumMap->setscanline(x => $nl, y => $i, + pixels => $day_p x ($width - $nl)); + $illumMap->setscanline(x => 0, y => $i, + pixels => $day_p x ($nl + $oh - $width + 1)); } else { - for ($j = $nl; $j < (($nl + $oh) + 1); $j++) { - $illumMap->setpixel(x => $j, y => $i, color => $d +ay); - } + $illumMap->setscanline(x => $nl, y => $i, + pixels => $day_p x ($oh + 1)); } } }

In reply to Re^5: Double the speed of Imager->setpixel by Anonymous Monk
in thread Double the speed of Imager->setpixel by Anonymous Monk

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.