I can see you only have two recursive calls, the last being a tail
call.  When introducing a stack, instead of making that first recursive
call, I would push the four point on the stack.  Something like

draw (p1, p2, p3, p4) P =
    S = empty stack
    do
        tailrec:
            compute next control points
            draw midpoint onto P
            if first segment touching
                push first segment on S
            if second segment touching
                (p1, p2, p3, p4) := second segment
                goto tailrec
    while (p1, p2, p3, p4) := pop from S
    return P

I think in the worst case scenario, the control points are scattered
alternatively on opposite corners of the screen making a total distance
about sqrt(X_MAX^2 + Y_MAX^2)*3, so I think a stack depth of 12--14
should do.  If points are 2*32 bits (2D) it should fit within 512 bytes,
though a rigid proof takes more careful inspection of the algorithm,
also considering rounding issues.

I see this is another algorithm than I assumed in my previous post.
_______________________________________________
Open-graphics mailing list
[email protected]
http://lists.duskglow.com/mailman/listinfo/open-graphics
List service provided by Duskglow Consulting, LLC (www.duskglow.com)

Reply via email to