Monday, June 27, 2005

Lines with Endcaps in Windows CE (3 of 3)

(We now return to our regularly scheduled programming. I believe we were still in February discovering lines with endcaps...)

Previously: Hatched brushes worked great...every 8th pixel

After flailing about for a while I discovered polygons. That isn't to say I'd never heard of Archimedes and triangles before, I just hadn't thought about his work in terms of my problem.

And the problem was easy, too. In any line that had a fixed width, the shape of the line was merely a Polygon() with its end vertices shaped to look like semi-circles.

Pixel-level polygon
Above: a 5-pixel high polygon on your monitor under an electron microscope

To break it down even farther (at a pixel-level) a "rounded glue line" was just a Polyline() where the lines in the middle extended a pixel or two past the lines at the top and bottom, like a snaking connect-the-dots viewed from across the room.

Pixel-level polyline
Above: Refocusing our massive scanning electron microscope on a 5-pixel high polyline instead

Having two equally promising prospects meant putting both to the test. I set up a simple test of my idea, the meat of which is listed below:

#define POLYGON_POINTS 8
#define POLYLINE_POINTS 10

DrawGlueLine(...) {
CPoint polyPts[POLYLINE_POINTS];
...

if (m_polygon)
{
nCount = POLYGON_POINTS;

polyPts[0].x = rect.left+1; polyPts[0].y = rect.top;
polyPts[1].x = rect.right-1; polyPts[1].y = rect.top;
polyPts[2].x = rect.right; polyPts[2].y = rect.top+1;
polyPts[3].x = rect.right; polyPts[3].y = rect.top+3;
polyPts[4].x = rect.right-1; polyPts[4].y = rect.top+4;
polyPts[5].x = rect.left+1; polyPts[5].y = rect.top+4;
polyPts[6].x = rect.left; polyPts[6].y = rect.top+3;
polyPts[7].x = rect.left; polyPts[7].y = rect.top+1;

pDC->Polygon(polyPts, nCount);
}
else
{
nCount = POLYLINE_POINTS;
polyPts[0].x = rect.left+1; polyPts[0].y = rect.top;
polyPts[1].x = rect.right-1; polyPts[1].y = rect.top;
polyPts[2].x = rect.right; polyPts[2].y = rect.top+1;
polyPts[3].x = rect.left; polyPts[3].y = rect.top+1;
polyPts[4].x = rect.left; polyPts[4].y = rect.top+2;
polyPts[5].x = rect.right; polyPts[5].y = rect.top+2;
polyPts[6].x = rect.right; polyPts[6].y = rect.top+3;
polyPts[7].x = rect.left; polyPts[7].y = rect.top+3;
polyPts[8].x = rect.left+1; polyPts[8].y = rect.top+4;
// Polyline draws up to the last x-pixel - 1, so
// draw 1 pixel farther
polyPts[9].x = rect.right; polyPts[9].y = rect.top+4;

pDC->Polyline(polyPts, nCount);
}

...
}
Under the emulator, both polylines and polygons drew equally well (and equally fast). But when I ran the demo on the physical device the polylines blew the polygons away. I suspect it was for two reasons: the polygon fill was slow, and the polyline optimized itself to draw five lines instead of the nine I plotted. (Four of the nine lines are just "steps" to the next level. They have an effective length of zero.)

Also, the lines were extremely fast. On the actual device I drew 480 polylines every redraw no slower than drawing as many normal lines. Flexible these lines were not. But flexibility wasn't one of the original requirements. I needed lines that would look like a line of glue and draw extremely fast. On both those counts this solution fit the bill.

Moral of the story: I knew that I would have to go outside my toolbox to solve the problem, but I didn't know that my screwdriver would make an excellent wrench, so to speak. It turned out that it wasn't noticeably slower to draw nine (or five) lines that appeared to look like a line with circle endcaps than to draw one plain line.

I also benefited from simplifying the problem. I didn't need to draw a line at an arbirtrary width with circles of an arbirtrary radius on each end. I just needed to draw a specific-sized line. And for my specific problem I found a specific solution.

ZIPPolyTest.zip (eVC 4.0 project compiled for 4.2 standard SDK)

6 Comments:

At 12/23/2005 1:00 AM, Blogger alextewnewsite said...

Hi D. Philippe ,

Alex Tew here!

You most probably heard of my website, the world famous million dollar pixel page.

Due to it nearly filling up, I personally reccommend the next (and best) working pixel website:

The new and improved pixel adventure:

The ten million dollar website.

See what MSN.COM already says about it!

They call it the greatest value in advertising

If you did not yet get your pixel advertising, come and get it now on the one and only Ten million Dollar Web Site!!

Regards,


Alex Tew.

 
At 12/23/2005 12:17 PM, Blogger alextewnewsite said...

Hi D. Philippe ,

Alex Tew here!

You most probably heard of my website, the world famous million dollar pixel page.

Due to it nearly filling up, I personally reccommend the next (and best) working pixel website:

The new and improved pixel adventure:

The ten million dollar website.

See what MSN.COM already says about it!

They call it the greatest value in advertising

If you did not yet get your pixel advertising, come and get it now on the one and only Ten million Dollar Web Site!!

Regards,


Alex Tew.

 
At 12/25/2005 12:13 AM, Blogger alextewnewsite said...

Hi D. Philippe ,

Alex Tew here!

You most probably heard of my website, the world famous million dollar pixel page.

Due to it nearly filling up, I personally reccommend the next (and best) working pixel website:

The new and improved pixel adventure:

The ten million dollar website.

See what MSN.COM already says about it!

They call it the greatest value in advertising

If you did not yet get your pixel advertising, come and get it now on the one and only Ten million Dollar Web Site!!

Regards,


Alex Tew.

 
At 4/08/2006 5:50 AM, Blogger Greg said...

make money from books in the public domain what about it..make money from books in the public domain Here it is now its up to you...

 
At 4/10/2006 7:41 PM, Anonymous parts of a compound microscope said...

Well done on a nice blog D. Philippe. I was searching for information on history of the microscope and came across your post Lines with Endcaps in Windows CE (3 of 3) - not quite what I was looking for related to history of the microscope but very interesting all the same!

If you have a moment, why not hop over and take a look at my report on microscopes.

 
At 3/01/2007 10:27 AM, Anonymous Anonymous said...

Here all free
free music
free free
free ringtone
free chat
free web layout
free hardware
free online dating
free stuff

 

Post a Comment

<< Home