Thursday, September 14, 2023

⚗ CIRCLE Algorithms Testing Enhanced

 Follow-up to ⚗ When CIRCLE feels too slow, try and test some triangle math

A fellow BASIC community member (paul doe) suggested I expand my previous test app with  a couple of fast and well-known algorithms for drawing circles:  Bresenham's circle algorithm and the midpoint circle algorithm.  paul doe also graciously shared FreeBASIC subroutines that were very easy to integrate into my BAM program with very little futzing about.

Strangely enough, my "triangle-math-based" routine (converted from GOSUB routine to subroutine for apples and apples comparison) is on pretty equal footing with both Bresenhaum's and midpoint algorithms.

Let it run long enough, and we find that my routine bests both of the other ones by a hair, with Bresenhaum's algorithm coming in second, and midpoint coming in third.  All three are all better than twice as fast as the CIRCLE statement implemented in javascript.

Now, hard to say how the three subroutines would compare if implemented in native javascript.  That's not an exercise I want to do.

Do note that all three routines have been altered to handle "aspect ratios" for different screen modes, something I insist on keeping in BAM to maintain compatibility with GW-BASIC screen modes.

I intend on replacing/enhancing BAM's CIRCLE implementation to improve the speed of circle drawing.  This comparison test with BASIC code transpiled to javascript when a BAM program is executed, it is enough to convince me that I should just go ahead and convert my BASIC subroutine into the equivalent javascript code for a re-implemented CIRCLE statement.

However, like many things, I'm going to digest it all for a bit, and wait to see if any of the awesome brains out there have notice flubs in my code or have any suggestions.

Version 2 of the CIRCLE tester:




No comments:

Post a Comment

🖥 Saucer Zap

This program is a port and mod of a QBJS program by James D Jarvis (shared with the QB64PE community and discussed in this thread ). That pr...