Author Topic: EllipseFill  (Read 7921 times)

0 Members and 1 Guest are viewing this topic.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: EllipseFill
« Reply #15 on: November 03, 2018, 08:50:27 pm »
Hi Steve,

The New Circle method is failing the alpha test with 1 overlapping line in upper and lower halves and it is being edged out by the old circle method in the long loop time test.

Amazingly the Ellipse Fill method is edging out the old gold standard circle fill method and still passing the alpha test.

Here is my test code, comment and uncomment as needed in method block and time report line:
Code: QB64: [Select]
  1. DEFINT A-Z
  2. SCREEN _NEWIMAGE(1220, 620, 32)
  3. _SCREENMOVE 100, 20
  4. FOR i = 0 TO 1000
  5.     t = t + i
  6. 'who goes first might be disadvantage in time
  7.  
  8. 'comment out the one not being tested against the old circle method
  9. 'start## = TIMER
  10. 'CIRCLE (915, 305), 300, _RGBA32(100, 100, 100, 100), , , 1
  11. 'NewCircleFill 915, 305, 300, _RGBA32(0, 100, 0, 100)
  12. 'FOR i = 1 TO 10000
  13. '    NewCircleFill 915, 305, 300, _RGBA32(0, 100, 0, 100)
  14. 'NEXT
  15. 'NewCircleTime## = TIMER - start##
  16.  
  17. start## = TIMER
  18. CIRCLE (915, 305), 300, _RGBA32(100, 100, 100, 100), , , 1
  19. EllipseFill 915, 305, 300, 300, _RGBA32(0, 100, 0, 100)
  20. FOR i = 1 TO 10000
  21.     EllipseFill 915, 305, 300, 300, _RGBA32(0, 100, 0, 100)
  22. EllipseTime## = TIMER - start##
  23.  
  24. ' ==================================================== compare to the old gold standard
  25. start## = TIMER
  26. CIRCLE (305, 305), 300, _RGBA32(100, 100, 100, 100), , , 1
  27. CircleFill 305, 305, 300, _RGBA32(0, 100, 0, 100)
  28. FOR i = 1 TO 10000
  29.     CircleFill 305, 305, 300, _RGBA32(0, 100, 0, 100)
  30. OldCircleTime## = TIMER - start##
  31.  
  32. 'Comment out one of next 2 below
  33.  
  34. 'PRINT "Old circle time:"; OldCircleTime##; ", New circle time:"; NewCircleTime##
  35.  
  36. PRINT "Old circle time:"; OldCircleTime##; ", Ellipse fill time:"; EllipseTime##
  37.  
  38.  
  39. 'old circle fill
  40. SUB CircleFill (CX AS INTEGER, CY AS INTEGER, R AS INTEGER, C AS _UNSIGNED LONG)
  41.     DIM Radius AS INTEGER, RadiusError AS INTEGER
  42.     DIM X AS INTEGER, Y AS INTEGER
  43.  
  44.     Radius = ABS(R)
  45.     RadiusError = -Radius
  46.     X = Radius
  47.     Y = 0
  48.  
  49.     IF Radius = 0 THEN PSET (CX, CY), C: EXIT SUB
  50.  
  51.     ' Draw the middle span here so we don't draw it twice in the main loop,
  52.     ' which would be a problem with blending turned on.
  53.     LINE (CX - X, CY)-(CX + X, CY), C, BF
  54.  
  55.     WHILE X > Y
  56.         RadiusError = RadiusError + Y * 2 + 1
  57.         IF RadiusError >= 0 THEN
  58.             IF X <> Y + 1 THEN
  59.                 LINE (CX - Y, CY - X)-(CX + Y, CY - X), C, BF
  60.                 LINE (CX - Y, CY + X)-(CX + Y, CY + X), C, BF
  61.             END IF
  62.             X = X - 1
  63.             RadiusError = RadiusError - X * 2
  64.         END IF
  65.         Y = Y + 1
  66.         LINE (CX - X, CY - Y)-(CX + X, CY - Y), C, BF
  67.         LINE (CX - X, CY + Y)-(CX + X, CY + Y), C, BF
  68.     WEND
  69.  
  70.  
  71. SUB NewCircleFill (cx AS INTEGER, cy AS INTEGER, r AS INTEGER, c AS _UNSIGNED LONG)
  72.     DIM x AS INTEGER
  73.     DIM y AS INTEGER
  74.     DIM e AS INTEGER
  75.  
  76.     x = r
  77.     e = -x
  78.  
  79.     DO WHILE x >= y
  80.         LINE (cx - x, cy - y)-(cx + x, cy - y), c, BF
  81.         IF y <> 0 THEN LINE (cx - x, cy + y)-(cx + x, cy + y), c, BF
  82.  
  83.         y = y + 1
  84.         e = e + y + y
  85.         IF e > 0 THEN
  86.             x = x - 1
  87.             e = e - x - x
  88.         END IF
  89.     LOOP
  90.     x = r
  91.     e = -x
  92.     y = 0
  93.  
  94.     DO WHILE x >= y
  95.         LINE (cx - y, cy - x)-(cx + y, cy - x), c, BF
  96.         LINE (cx - y, cy + x)-(cx + y, cy + x), c, BF
  97.         DO
  98.             y = y + 1
  99.             e = e + y + y
  100.         LOOP UNTIL e > 0
  101.         x = x - 1
  102.         e = e - x - x
  103.     LOOP
  104.  
  105. SUB EllipseFill (cx AS INTEGER, cy AS INTEGER, rx AS INTEGER, ry AS INTEGER, c AS _UNSIGNED LONG)
  106.     DIM a AS LONG, b AS LONG
  107.     DIM x AS LONG, y AS LONG
  108.     DIM xx AS LONG, yy AS LONG
  109.     DIM sx AS LONG, sy AS LONG
  110.     DIM e AS LONG
  111.  
  112.     a = 2 * rx * rx
  113.     b = 2 * ry * ry
  114.     x = rx
  115.     xx = ry * ry * (1 - rx - rx)
  116.     yy = rx * rx
  117.     sx = b * rx
  118.  
  119.     DO WHILE sx >= sy
  120.         LINE (cx - x, cy - y)-(cx + x, cy - y), c, BF
  121.         IF y <> 0 THEN LINE (cx - x, cy + y)-(cx + x, cy + y), c, BF
  122.  
  123.         y = y + 1
  124.         sy = sy + a
  125.         e = e + yy
  126.         yy = yy + a
  127.  
  128.         IF (e + e + xx) > 0 THEN
  129.             x = x - 1
  130.             sx = sx - b
  131.             e = e + xx
  132.             xx = xx + b
  133.         END IF
  134.     LOOP
  135.  
  136.     x = 0
  137.     y = ry
  138.     xx = rx * ry
  139.     yy = rx * rx * (1 - ry - ry)
  140.     e = 0
  141.     sx = 1
  142.     sy = a * ry
  143.  
  144.     DO WHILE sx <= sy
  145.         LINE (cx - x, cy - y)-(cx + x, cy - y), c, BF
  146.         LINE (cx - x, cy + y)-(cx + x, cy + y), c, BF
  147.  
  148.         DO
  149.             x = x + 1
  150.             sx = sx + b
  151.             e = e + xx
  152.             xx = xx + b
  153.         LOOP UNTIL (e + e + yy) > 0
  154.  
  155.         y = y - 1
  156.         sy = sy - a
  157.         e = e + yy
  158.         yy = yy + a
  159.  
  160.     LOOP
  161.  
  162.  
  163.  

I first test one drawing of each for alpha test, then I run them through long loops of redrawing for timed test.

BTW, the first CIRCLE just draws a circle to compare border edges to QB64's circle.

« Last Edit: November 04, 2018, 08:53:21 am by bplus »