[Oberon] PO2013 - Simple Arc

Joerg joerg.straube at iaeth.ch
Fri Jun 26 12:03:04 CEST 2020


It depends on how you define „better“.
One of the things you could do to improve the runtime just a little bit, is nesting the IFs.

In worst case your code has to evaluate 5 conditions. Optimally, 2 condition checks will do.

br
Jörg

> Am 26.06.2020 um 12:24 schrieb Tomas Kral <thomas.kral at email.cz>:
> 
> Hi,
> 
> Just revising `Arc' procedure in simple graph, I have coded this. In
> fact it just draws quarter circle, based on +/- hint, not sure if good idea.
> 
> I do not need exact RAD segments, that would probably require Math trigo, but wish to somehow get it better if
> possible.
> 
>  PROCEDURE Arc*(col, x0, y0, r, mode: INTEGER);
>    VAR x, y, sx, sy, u: INTEGER;
>  BEGIN u := 1 - r; x := r; y := 0; sx := 1; sy := 1;
>  IF x0 < 0 THEN sx := -1 END ; x0 := ABS(x0);
>    IF y0 < 0 THEN sy := -1 END ; y0 := ABS(y0);
>    WHILE y <= x DO
>      IF (sx > 0) & (sy > 0) THEN
>        Dot(col, x0+x, y0+y, mode);
>        Dot(col, x0+y, y0+x, mode)
>      ELSIF (sx < 0) & (sy > 0) THEN
>        Dot(col, x0-y, y0+x, mode);
>        Dot(col, x0-x, y0+y, mode)
>      ELSIF (sx < 0) & (sy < 0) THEN
>        Dot(col, x0-x, y0-y, mode);
>        Dot(col, x0-y, y0-x, mode)
>      ELSE (*(sx > 0) & (sy < 0)*)
>        Dot(col, x0+y, y0-x, mode);
>        Dot(col, x0+x, y0-y, mode)
>      END ;
>      IF u < 0 THEN INC(u, 2*y+3) ELSE INC(u, 2*(y-x)+5); DEC(x) END ;
>      INC(y)
>    END
>  END Arc;
> 
> -- 
> Tomas Kral <thomas.kral at email.cz>
> --
> Oberon at lists.inf.ethz.ch mailing list for ETH Oberon and related systems
> https://lists.inf.ethz.ch/mailman/listinfo/oberon



More information about the Oberon mailing list