Lines and Traps:
I've just finished some code which generates a transformed rectangle out of ordinary lines, and generates Trapezoids out of it later.
It was ... well harder than expected and I needed an awful lot of trigonometry, some basics about tranformations (especially rotation) and a lot of debugging and trying.
Thanks to Heinz for some trigonometry lessons and for removing the need for two trigonometry functions (its now basically a few multiplications/divisions and a single square root).
I did the whole thing in Java first, because I am used to it and don't to read manuals just to get a line drawn to draw my calculations, and combined it with my Trapviewer app I wrote a few days ago.
The big difference is that now I calculate my own traps, instead of stealing cairo's ;)
The first window is simply a debug-window which shows the line maginifed, the second is trapviwer.
Why are Lines so hard?:
Well, XRender itself does not support lines, so they have to be composed out of trapezoids.
Furthermore lines are ... well some kind of rotated primitive, the rotation is more or less specified by the end points.
The sad thing is, you need 3 primitives for a single line, and lines are used a lot by application programmers as well as the java shape stroking (Graphics2D.draw()) code.
Best solution would be a Trapezoid-Generator, which could generate as much traps as really needed, but thats far beyond my qualification.
Some day it would be great if we could port Cairo's trap generator to Java, or use it through an JNI-Interface but for now its a private API(its LGPL after all).
Well tonight I'll rewrite the code in C and doing some fine-tuning for performance.
Macros, Macros, Macros ;)