Given a bline (composed with several segments of bilne) and a tile to render (TL, BR or w,h or 1234 as the diagram of yesterday)
Given a straight line (untransformed bline) by the union of points 'a' and 'b'. When the bline goes from 0 to 1 then the straight
segment goes from 'a' to 'b'.
Given a point P in the untransformed space, it can be "on the left" or "on the right" of the straight segment according to ab vector.
To simplify lets call the four corners of the tile to render to be 1,2,3,4. When those four corners are untransformed using the bline they
lies on four places on the context space. Lets call them 1', 2', 3', 4'. Most of the times the 1'2'3'4 polygon is not an square.
WE ASSUME THE TE BLINE DOESN'T CROSS ITSELF. OTHERWISE THE ALGORITHM WILL FAIL AND BAD RENDER WILL BE DELIVERED.
ALSO THE BLINE IS NOT LOOPED
PROCEDURE
1) Calculate if the end and start of the bline are inside the tile or not. It gives three cases
a) both inside
b) both ouside
c) one inside and other outside (which one is irrelevant)
2) Calculate the intersections of the bline with the tile to render
2.1) if no intersections and case a) then subdivide by a half.
2.2) if no intersections and case b). GOTO 3).
2.2.1) The untransformed 1'2'3'4' are all in the "same side" of the straight segment ab.
2.2.2) The untransformed 1'2'3'4' are "some of them on the left" and "some of them on the right". Then the tile cannot be rendered properly. Subdivide by a half.
2.3) if there is an odd number of intersections and case c) (not possible case a) or b) because they need an even number of interesections) then subdivide by a half
2.4) if there is an even number of intersections then there can be two cases:
2.4.1) number of intersections = 2
2.4.1.1) both intersections in the same side of the tile. Then subdivide and place each interesection in a different sub-tile.
2.4.1.2) on intersection in one side and the other in the adjacent. GOTO 3)
2.4.1.3) on intersection and other in the oposite. GOTO 3)
2.4.2) number of intersections = 2*n (n=2,3,4...). The amount of cases are not maneagable. Subdivide by half.
3) The tile is correct and can be rendered. Use the current normal algorithm to calculate the untransformed context area to render.