I knew that all those days looking at assembly language line drawing algorithms would some day pay off. I'm almost certain there is an "improved" Bresenham algorithm that does not require you to paint the line pixel-by-pixel - but unfortunately, I can't find it. Most likely, it is discussed in the "Mode X" articles published around 1990. The "Mode X" was a graphics mode where you could write up to four bytes of (8 bit) graphics memory, by writing one byte to the graphics bus. This greatly improved (non-OpenGL) rasterizers, as long as they could tell when the next error overflow was bound to happen.

And yay, Google Gives!

Michael Abrash's book, "Graphics Programming", is online, and it has the discussion of how to turn Bresenham's Algorithm 90 degrees sideways, so you get to know how long a run (=range) is without iterating it. I'm not convinced that this solution is any better than your original approach, as the algorithm plus setup is best stuffed away in a subroutine, and it certainly is not really self-explaining to the casual onlooker. But at least this made me revisit ideas of the olden times and find an application for a somewhat unrelated topic.


In reply to Re^4: Split range 0 to M into N non-overlapping (roughly equal) ranges. by Corion
in thread Split range 0 to M into N non-overlapping (roughly equal) ranges. by BrowserUk

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.