fix monogfx.disc() inaccurracy

This commit is contained in:
Irmen de Jong
2025-10-05 23:03:53 +02:00
parent 44741a8e32
commit 9aff280d10
4 changed files with 14 additions and 101 deletions

View File

@@ -595,23 +595,12 @@ drawmode: ora cx16.r15L
return return
ubyte @zp yy = 0 ubyte @zp yy = 0
word @zp decisionOver2 = (1 as word)-radius word @zp decisionOver2 = (1 as word)-radius
uword last_y3 = ycenter+radius
uword last_y4 = ycenter-radius
uword new_y3, new_y4
while radius>=yy { while radius>=yy {
horizontal_line(xcenter-radius, ycenter+yy, radius*$0002+1, draw) horizontal_line(xcenter-radius, ycenter+yy, radius*$0002+1, draw)
horizontal_line(xcenter-radius, ycenter-yy, radius*$0002+1, draw) horizontal_line(xcenter-radius, ycenter-yy, radius*$0002+1, draw)
new_y3 = ycenter+radius horizontal_line(xcenter-yy, ycenter+radius, yy*$0002+1, draw)
if new_y3 != last_y3 { horizontal_line(xcenter-yy, ycenter-radius, yy*$0002+1, draw)
horizontal_line(xcenter-yy, last_y3, yy*$0002+1, draw)
last_y3 = new_y3
}
new_y4 = ycenter-radius
if new_y4 != last_y4 {
horizontal_line(xcenter-yy, last_y4, yy*$0002+1, draw)
last_y4 = new_y4
}
yy++ yy++
if decisionOver2>=0 { if decisionOver2>=0 {
radius-- radius--
@@ -620,10 +609,6 @@ drawmode: ora cx16.r15L
decisionOver2 += yy*$0002 decisionOver2 += yy*$0002
decisionOver2++ decisionOver2++
} }
; draw the final two spans
yy--
horizontal_line(xcenter-yy, last_y3, yy*$0002+1, draw)
horizontal_line(xcenter-yy, last_y4, yy*$0002+1, draw)
} }
sub safe_disc(uword @zp xcenter, uword @zp ycenter, ubyte @zp radius, bool draw) { sub safe_disc(uword @zp xcenter, uword @zp ycenter, ubyte @zp radius, bool draw) {
@@ -634,23 +619,12 @@ drawmode: ora cx16.r15L
return return
ubyte @zp yy = 0 ubyte @zp yy = 0
word @zp decisionOver2 = (1 as word)-radius word @zp decisionOver2 = (1 as word)-radius
uword last_y3 = ycenter+radius
uword last_y4 = ycenter-radius
uword new_y3, new_y4
while radius>=yy { while radius>=yy {
safe_horizontal_line(xcenter-radius, ycenter+yy, radius*$0002+1, draw) safe_horizontal_line(xcenter-radius, ycenter+yy, radius*$0002+1, draw)
safe_horizontal_line(xcenter-radius, ycenter-yy, radius*$0002+1, draw) safe_horizontal_line(xcenter-radius, ycenter-yy, radius*$0002+1, draw)
new_y3 = ycenter+radius safe_horizontal_line(xcenter-yy, ycenter+radius, yy*$0002+1, draw)
if new_y3 != last_y3 { safe_horizontal_line(xcenter-yy, ycenter-radius, yy*$0002+1, draw)
safe_horizontal_line(xcenter-yy, last_y3, yy*$0002+1, draw)
last_y3 = new_y3
}
new_y4 = ycenter-radius
if new_y4 != last_y4 {
safe_horizontal_line(xcenter-yy, last_y4, yy*$0002+1, draw)
last_y4 = new_y4
}
yy++ yy++
if decisionOver2>=0 { if decisionOver2>=0 {
radius-- radius--
@@ -659,10 +633,6 @@ drawmode: ora cx16.r15L
decisionOver2 += yy*$0002 decisionOver2 += yy*$0002
decisionOver2++ decisionOver2++
} }
; draw the final two spans
yy--
safe_horizontal_line(xcenter-yy, last_y3, yy*$0002+1, draw)
safe_horizontal_line(xcenter-yy, last_y4, yy*$0002+1, draw)
} }
sub plot(uword @zp xx, uword @zp yy, bool @zp draw) { sub plot(uword @zp xx, uword @zp yy, bool @zp draw) {

View File

@@ -302,23 +302,11 @@ monogfx {
return return
ubyte @zp yy = 0 ubyte @zp yy = 0
word @zp decisionOver2 = (1 as word)-radius word @zp decisionOver2 = (1 as word)-radius
uword last_y3 = ycenter+radius
uword last_y4 = ycenter-radius
uword new_y3, new_y4
while radius>=yy { while radius>=yy {
horizontal_line(xcenter-radius, ycenter+yy, radius*$0002+1, draw) horizontal_line(xcenter-radius, ycenter+yy, radius*$0002+1, draw)
horizontal_line(xcenter-radius, ycenter-yy, radius*$0002+1, draw) horizontal_line(xcenter-radius, ycenter-yy, radius*$0002+1, draw)
new_y3 = ycenter+radius horizontal_line(xcenter-yy, ycenter+radius, yy*$0002+1, draw)
if new_y3 != last_y3 { horizontal_line(xcenter-yy, ycenter-radius, yy*$0002+1, draw)
horizontal_line(xcenter-yy, last_y3, yy*$0002+1, draw)
last_y3 = new_y3
}
new_y4 = ycenter-radius
if new_y4 != last_y4 {
horizontal_line(xcenter-yy, last_y4, yy*$0002+1, draw)
last_y4 = new_y4
}
yy++ yy++
if decisionOver2>=0 { if decisionOver2>=0 {
radius-- radius--
@@ -327,10 +315,6 @@ monogfx {
decisionOver2 += yy*$0002 decisionOver2 += yy*$0002
decisionOver2++ decisionOver2++
} }
; draw the final two spans
yy--
horizontal_line(xcenter-yy, last_y3, yy*$0002+1, draw)
horizontal_line(xcenter-yy, last_y4, yy*$0002+1, draw)
} }
sub safe_disc(uword @zp xcenter, uword @zp ycenter, ubyte @zp radius, bool draw) { sub safe_disc(uword @zp xcenter, uword @zp ycenter, ubyte @zp radius, bool draw) {
@@ -340,23 +324,11 @@ monogfx {
return return
ubyte @zp yy = 0 ubyte @zp yy = 0
word @zp decisionOver2 = (1 as word)-radius word @zp decisionOver2 = (1 as word)-radius
uword last_y3 = ycenter+radius
uword last_y4 = ycenter-radius
uword new_y3, new_y4
while radius>=yy { while radius>=yy {
safe_horizontal_line(xcenter-radius, ycenter+yy, radius*$0002+1, draw) safe_horizontal_line(xcenter-radius, ycenter+yy, radius*$0002+1, draw)
safe_horizontal_line(xcenter-radius, ycenter-yy, radius*$0002+1, draw) safe_horizontal_line(xcenter-radius, ycenter-yy, radius*$0002+1, draw)
new_y3 = ycenter+radius safe_horizontal_line(xcenter-yy, ycenter+radius, yy*$0002+1, draw)
if new_y3 != last_y3 { safe_horizontal_line(xcenter-yy, ycenter-radius, yy*$0002+1, draw)
safe_horizontal_line(xcenter-yy, last_y3, yy*$0002+1, draw)
last_y3 = new_y3
}
new_y4 = ycenter-radius
if new_y4 != last_y4 {
safe_horizontal_line(xcenter-yy, last_y4, yy*$0002+1, draw)
last_y4 = new_y4
}
yy++ yy++
if decisionOver2>=0 { if decisionOver2>=0 {
radius-- radius--
@@ -365,10 +337,6 @@ monogfx {
decisionOver2 += yy*$0002 decisionOver2 += yy*$0002
decisionOver2++ decisionOver2++
} }
; draw the final two spans
yy--
safe_horizontal_line(xcenter-yy, last_y3, yy*$0002+1, draw)
safe_horizontal_line(xcenter-yy, last_y4, yy*$0002+1, draw)
} }
sub plot(uword @zp xx, uword @zp yy, bool @zp draw) { sub plot(uword @zp xx, uword @zp yy, bool @zp draw) {

View File

@@ -2,6 +2,7 @@ TODO
==== ====
check the accuracy of the various disc routines (filled circles), they seem less accurate than the circle routine (virt monogfx) check the accuracy of the various disc routines (filled circles), they seem less accurate than the circle routine (virt monogfx)
check disc and circle draw in paint
LONG TYPE LONG TYPE

View File

@@ -1,42 +1,16 @@
%import graphics %import monogfx
main { main {
sub start() { sub start() {
graphics.enable_bitmap_mode() monogfx.lores()
uword radius uword radius
for radius in 1 to 10 { for radius in 1 to 10 {
graphics.circle(30*radius, 100, lsb(radius)) monogfx.circle(30*radius, 100, lsb(radius), true)
graphics.disc(30*radius, 130, lsb(radius)) monogfx.disc(30*radius, 130, lsb(radius), true)
mydisc(30*radius, 160, lsb(radius)) monogfx.safe_disc(30*radius, 160, lsb(radius), true)
} }
repeat {} repeat {}
} }
sub mydisc(uword xcenter, ubyte ycenter, ubyte radius) {
; Warning: NO BOUNDS CHECKS. Make sure circle fits in the screen.
; Midpoint algorithm.
if radius==0
return
ubyte @zp ploty
ubyte @zp yy = 0
word @zp decisionOver2 = (1 as word)-radius
while radius>=yy {
graphics.horizontal_line(xcenter-radius, ycenter+yy, radius*2+1)
graphics.horizontal_line(xcenter-radius, ycenter-yy, radius*2+1)
graphics.horizontal_line(xcenter-yy, ycenter+radius, yy*2+1)
graphics.horizontal_line(xcenter-yy, ycenter-radius, yy*2+1)
yy++
if decisionOver2>=0 {
radius--
decisionOver2 -= radius*$0002
}
decisionOver2 += yy*$0002
decisionOver2++
}
}
} }