Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Another small filled circe sub (not as fast as fcirc)
#62
This is a fun thread!

@bplus thank you for the test program. I made some changes to your code and the fill routines to ensure they are evenly matched.

On my system, Vince's circle-fill routines almost always beat everything when the IDE C++ optimizations are enabled.

To be fair, the final numbers are extremely close.

[Image: Screenshot-2024-08-31-071215.png]

Code: (Select All)
_DEFINE A-Z ASLONG
OPTION _EXPLICIT

CONST CCOLOR~& = _RGBA32(0, 100, 0, 100)

_TITLE "Circle Fill speed tests"

SCREEN _NEWIMAGE(1830, 680, 32)

' Dry run
SLEEP 1
_PRINTSTRING (0, 0), "Dry run..."
Run_Test 10000

' Showdown
SLEEP 5
CLS
_PRINTSTRING (0, 0), "Showdown..."
Run_Test 200000

END

SUB Run_Test (iterations AS LONG)
    STATIC AS DOUBLE start, finish
    STATIC i AS LONG

    _DISPLAY

    start = TIMER(0.001!)
    FOR i = 1 TO iterations
        FC_Dav 305, 305, 300, CCOLOR
    NEXT
    finish = TIMER(0.001!) - start
    _AUTODISPLAY
    _PRINTSTRING (100, 615), "Time for" + STR$(iterations) + " Contender Fills (Dav):" + STR$(finish)

    _DISPLAY
    start = TIMER
    FOR i = 1 TO iterations
        FC_Vince 915, 305, 300, CCOLOR
    NEXT
    finish = TIMER(0.001!) - start
    _AUTODISPLAY
    _PRINTSTRING (700, 615), "Time for" + STR$(iterations) + " Contender Fills (Vince):" + STR$(finish)

    _DISPLAY
    start = TIMER
    FOR i = 1 TO iterations
        FC_Gold 1525, 305, 300, CCOLOR
    NEXT
    finish = TIMER(0.001!) - start
    _AUTODISPLAY
    _PRINTSTRING (1300, 615), "Time for" + STR$(iterations) + " Gold Standard Circle Fills:" + STR$(finish)
END SUB

SUB FC_Gold (cx AS LONG, cy AS LONG, r AS LONG, c AS _UNSIGNED LONG)
    $CHECKING:OFF

    DIM radius AS LONG: radius = ABS(r)
    DIM radiusError AS LONG: radiusError = -radius
    DIM x AS LONG: x = radius
    DIM y AS LONG

    IF radius = 0 THEN
        PSET (cx, cy), c
        EXIT SUB
    END IF

    LINE (cx - x, cy)-(cx + x, cy), c, BF

    DO WHILE x > y
        radiusError = radiusError + _SHL(y, 1) + 1

        IF radiusError >= 0 THEN
            IF x <> y + 1 THEN
                LINE (cx - y, cy - x)-(cx + y, cy - x), c, BF
                LINE (cx - y, cy + x)-(cx + y, cy + x), c, BF
            END IF

            x = x - 1

            radiusError = radiusError - _SHL(x, 1)
        END IF

        y = y + 1

        LINE (cx - x, cy - y)-(cx + x, cy - y), c, BF
        LINE (cx - x, cy + y)-(cx + x, cy + y), c, BF
    LOOP

    $CHECKING:ON
END SUB

SUB FC_Dav (cx AS LONG, cy AS LONG, r AS LONG, c AS _UNSIGNED LONG)
    $CHECKING:OFF

    DIM r2 AS LONG: r2 = r * r
    DIM AS LONG x, y

    LINE (cx - r, cy)-(cx + r, cy), c, BF

    DO WHILE y < r
        y = y + 1

        x = SQR(r2 - y * y)

        LINE (cx - x, cy + y)-(cx + x, cy + y), c, BF
        LINE (cx - x, cy - y)-(cx + x, cy - y), c, BF
    LOOP

    $CHECKING:ON
END SUB

SUB FC_Vince (cx AS LONG, cy AS LONG, r AS LONG, c AS _UNSIGNED LONG)
    $CHECKING:OFF

    DIM e AS LONG: e = -r
    DIM x AS LONG: x = r
    DIM y AS LONG

    DO WHILE y < x
        IF e <= 0 THEN
            y = y + 1

            LINE (cx - x, cy + y)-(cx + x, cy + y), c, BF
            LINE (cx - x, cy - y)-(cx + x, cy - y), c, BF

            e = e + _SHL(y, 1)
        ELSE
            LINE (cx - y, cy - x)-(cx + y, cy - x), c, BF
            LINE (cx - y, cy + x)-(cx + y, cy + x), c, BF

            x = x - 1

            e = e - _SHL(x, 1)
        END IF
    LOOP

    LINE (cx - r, cy)-(cx + r, cy), c, BF

    $CHECKING:ON
END SUB
Reply


Messages In This Thread
RE: Another small filled circe sub (not as fast as fcirc) - by a740g - 08-31-2024, 01:45 AM



Users browsing this thread: 32 Guest(s)