bugfix in bezier
This commit is contained in:
parent
518816fd45
commit
ba3f67cacb
67
509bezier.mu
67
509bezier.mu
|
@ -43,6 +43,20 @@ fn draw-monotonic-bezier screen: (addr screen), x0: int, y0: int, x1: int, y1: i
|
|||
tmp2-f <- multiply sx-f
|
||||
cur-f <- subtract tmp2-f
|
||||
}
|
||||
set-cursor-position 0/screen, 0/x, 0x1d/y
|
||||
draw-text-wrapping-right-then-down-from-cursor-over-full-screen 0/screen, "A ", 4/fg 0/bg
|
||||
draw-int32-decimal-wrapping-right-then-down-from-cursor-over-full-screen 0/screen, sx, 4/fg 0/bg
|
||||
draw-text-wrapping-right-then-down-from-cursor-over-full-screen 0/screen, " ", 4/fg 0/bg
|
||||
draw-int32-decimal-wrapping-right-then-down-from-cursor-over-full-screen 0/screen, sy, 4/fg 0/bg
|
||||
draw-text-wrapping-right-then-down-from-cursor-over-full-screen 0/screen, " ", 4/fg 0/bg
|
||||
draw-int32-decimal-wrapping-right-then-down-from-cursor-over-full-screen 0/screen, xx, 4/fg 0/bg
|
||||
draw-text-wrapping-right-then-down-from-cursor-over-full-screen 0/screen, " ", 4/fg 0/bg
|
||||
draw-int32-decimal-wrapping-right-then-down-from-cursor-over-full-screen 0/screen, yy, 4/fg 0/bg
|
||||
draw-text-wrapping-right-then-down-from-cursor-over-full-screen 0/screen, " ", 4/fg 0/bg
|
||||
draw-int32-decimal-wrapping-right-then-down-from-cursor-over-full-screen 0/screen, xy, 4/fg 0/bg
|
||||
{
|
||||
var foo/eax: int <- render-float-decimal 0/screen, cur-f, 3/precision, 0x30/x, 0x1d/y, 4/fg, 0/bg
|
||||
}
|
||||
# if (xx*sx > 0) abort
|
||||
{
|
||||
tmp <- copy xx
|
||||
|
@ -96,6 +110,8 @@ fn draw-monotonic-bezier screen: (addr screen), x0: int, y0: int, x1: int, y1: i
|
|||
# if (dist1 <= dist2) break
|
||||
compare dist1, dist2
|
||||
break-if-<=
|
||||
set-cursor-position 0/screen, 0/x 0x1e/y
|
||||
draw-text-wrapping-right-then-down-from-cursor-over-full-screen 0/screen, "swap", 4/fg 0/bg
|
||||
# swap x0 and x2
|
||||
tmp <- copy x0
|
||||
copy-to x2, tmp
|
||||
|
@ -113,9 +129,22 @@ fn draw-monotonic-bezier screen: (addr screen), x0: int, y0: int, x1: int, y1: i
|
|||
var negative-1-f/xmm1: float <- convert negative-1
|
||||
cur-f <- multiply negative-1-f
|
||||
}
|
||||
set-cursor-position 0/screen, 0/x, 0x1f/y
|
||||
draw-text-wrapping-right-then-down-from-cursor-over-full-screen 0/screen, "B ", 4/fg 0/bg
|
||||
draw-int32-decimal-wrapping-right-then-down-from-cursor-over-full-screen 0/screen, sx, 4/fg 0/bg
|
||||
draw-text-wrapping-right-then-down-from-cursor-over-full-screen 0/screen, " ", 4/fg 0/bg
|
||||
draw-int32-decimal-wrapping-right-then-down-from-cursor-over-full-screen 0/screen, sy, 4/fg 0/bg
|
||||
draw-text-wrapping-right-then-down-from-cursor-over-full-screen 0/screen, " ", 4/fg 0/bg
|
||||
draw-int32-decimal-wrapping-right-then-down-from-cursor-over-full-screen 0/screen, xx, 4/fg 0/bg
|
||||
draw-text-wrapping-right-then-down-from-cursor-over-full-screen 0/screen, " ", 4/fg 0/bg
|
||||
draw-int32-decimal-wrapping-right-then-down-from-cursor-over-full-screen 0/screen, yy, 4/fg 0/bg
|
||||
draw-text-wrapping-right-then-down-from-cursor-over-full-screen 0/screen, " ", 4/fg 0/bg
|
||||
draw-int32-decimal-wrapping-right-then-down-from-cursor-over-full-screen 0/screen, xy, 4/fg 0/bg
|
||||
{
|
||||
var foo/eax: int <- render-float-decimal 0/screen, cur-f, 3/precision, 0x30/x, 0x1f/y, 4/fg, 0/bg
|
||||
}
|
||||
var x/ecx: int <- copy x0
|
||||
var y/edx: int <- copy y0
|
||||
set-cursor-position 0/screen, 0/x 0x1f/y
|
||||
var zero-f: float
|
||||
# plot a curved part if necessary
|
||||
$draw-monotonic-bezier:curve: {
|
||||
|
@ -129,6 +158,10 @@ fn draw-monotonic-bezier screen: (addr screen), x0: int, y0: int, x1: int, y1: i
|
|||
tmp <- subtract x
|
||||
tmp <- sgn tmp
|
||||
copy-to sx, tmp
|
||||
# xx *= sx
|
||||
tmp <- copy sx
|
||||
tmp <- multiply xx
|
||||
copy-to xx, tmp
|
||||
# yy += sy
|
||||
tmp <- copy sy
|
||||
add-to yy, tmp
|
||||
|
@ -137,6 +170,24 @@ fn draw-monotonic-bezier screen: (addr screen), x0: int, y0: int, x1: int, y1: i
|
|||
tmp <- subtract y
|
||||
tmp <- sgn tmp
|
||||
copy-to sy, tmp
|
||||
# yy *= sy
|
||||
tmp <- copy sy
|
||||
tmp <- multiply yy
|
||||
copy-to yy, tmp
|
||||
set-cursor-position 0/screen, 0/x, 0x20/y
|
||||
draw-text-wrapping-right-then-down-from-cursor-over-full-screen 0/screen, "E ", 4/fg 0/bg
|
||||
draw-int32-decimal-wrapping-right-then-down-from-cursor-over-full-screen 0/screen, sx, 4/fg 0/bg
|
||||
draw-text-wrapping-right-then-down-from-cursor-over-full-screen 0/screen, " ", 4/fg 0/bg
|
||||
draw-int32-decimal-wrapping-right-then-down-from-cursor-over-full-screen 0/screen, sy, 4/fg 0/bg
|
||||
draw-text-wrapping-right-then-down-from-cursor-over-full-screen 0/screen, " ", 4/fg 0/bg
|
||||
draw-int32-decimal-wrapping-right-then-down-from-cursor-over-full-screen 0/screen, xx, 4/fg 0/bg
|
||||
draw-text-wrapping-right-then-down-from-cursor-over-full-screen 0/screen, " ", 4/fg 0/bg
|
||||
draw-int32-decimal-wrapping-right-then-down-from-cursor-over-full-screen 0/screen, yy, 4/fg 0/bg
|
||||
draw-text-wrapping-right-then-down-from-cursor-over-full-screen 0/screen, " ", 4/fg 0/bg
|
||||
draw-int32-decimal-wrapping-right-then-down-from-cursor-over-full-screen 0/screen, xy, 4/fg 0/bg
|
||||
{
|
||||
var foo/eax: int <- render-float-decimal 0/screen, cur-f, 3/precision, 0x30/x, 0x20/y, 4/fg, 0/bg
|
||||
}
|
||||
# xy = 2*xx*xy
|
||||
tmp <- copy xx
|
||||
tmp <- multiply yy
|
||||
|
@ -175,6 +226,7 @@ fn draw-monotonic-bezier screen: (addr screen), x0: int, y0: int, x1: int, y1: i
|
|||
tmp-f <- multiply sy-f
|
||||
compare tmp-f, zero-f
|
||||
break-if-float>=
|
||||
abort "negate"
|
||||
#
|
||||
negate xx
|
||||
negate yy
|
||||
|
@ -184,6 +236,19 @@ fn draw-monotonic-bezier screen: (addr screen), x0: int, y0: int, x1: int, y1: i
|
|||
var negative-1-f/xmm1: float <- convert negative-1
|
||||
cur-f <- multiply negative-1-f
|
||||
}
|
||||
set-cursor-position 0/screen, 0/x, 0x1d/y
|
||||
draw-int32-decimal-wrapping-right-then-down-from-cursor-over-full-screen 0/screen, sx, 4/fg 0/bg
|
||||
draw-text-wrapping-right-then-down-from-cursor-over-full-screen 0/screen, " ", 4/fg 0/bg
|
||||
draw-int32-decimal-wrapping-right-then-down-from-cursor-over-full-screen 0/screen, sy, 4/fg 0/bg
|
||||
draw-text-wrapping-right-then-down-from-cursor-over-full-screen 0/screen, " ", 4/fg 0/bg
|
||||
draw-int32-decimal-wrapping-right-then-down-from-cursor-over-full-screen 0/screen, xx, 4/fg 0/bg
|
||||
draw-text-wrapping-right-then-down-from-cursor-over-full-screen 0/screen, " ", 4/fg 0/bg
|
||||
draw-int32-decimal-wrapping-right-then-down-from-cursor-over-full-screen 0/screen, yy, 4/fg 0/bg
|
||||
draw-text-wrapping-right-then-down-from-cursor-over-full-screen 0/screen, " ", 4/fg 0/bg
|
||||
draw-int32-decimal-wrapping-right-then-down-from-cursor-over-full-screen 0/screen, xy, 4/fg 0/bg
|
||||
{
|
||||
var foo/eax: int <- render-float-decimal 0/screen, cur-f, 3/precision, 0x30/x, 0x1d/y, 4/fg, 0/bg
|
||||
}
|
||||
var four/ebx: int <- copy 4
|
||||
var dx-f/xmm5: float <- convert four
|
||||
var dy-f/xmm6: float <- convert four
|
||||
|
|
16
bezier.c
16
bezier.c
|
@ -8,24 +8,30 @@ void setPixel(int x, int y) {
|
|||
void plotQuadBezierSeg(int x0, int y0, int x1, int y1, int x2, int y2)
|
||||
{
|
||||
int sx = x2-x1, sy = y2-y1;
|
||||
long xx = x0-x1, yy = y0-y1, xy; /* relative values for checks */
|
||||
long xx = x0-x1, yy = y0-y1, xy=0; /* relative values for checks */
|
||||
double dx, dy, err, cur = xx*sy-yy*sx; /* curvature */
|
||||
|
||||
assert(xx*sx <= 0 && yy*sy <= 0); /* sign of gradient must not change */
|
||||
|
||||
printf("0 sx %d sy %d xx %ld yy %ld xy %ld cur %g\n", sx, sy, xx, yy, xy, cur);
|
||||
printf("A sx %d sy %d xx %ld yy %ld cur %g\n", sx, sy, xx, yy, cur);
|
||||
if (sx*(long)sx+sy*(long)sy > xx*xx+yy*yy) { /* begin with longer part */
|
||||
printf("swap\n");
|
||||
x2 = x0; x0 = sx+x1; y2 = y0; y0 = sy+y1; cur = -cur; /* swap P0 P2 */
|
||||
}
|
||||
printf("B sx %d sy %d xx %ld yy %ld xy %ld cur %g\n", sx, sy, xx, yy, xy, cur);
|
||||
if (cur != 0) { /* no straight line */
|
||||
xx += sx; xx *= sx = x0 < x2 ? 1 : -1; /* x step direction */
|
||||
yy += sy; yy *= sy = y0 < y2 ? 1 : -1; /* y step direction */
|
||||
xy = 2*xx*yy; xx *= xx; yy *= yy; /* differences 2nd degree */
|
||||
printf("E sx %d sy %d xx %ld yy %ld xy %ld cur %g\n", sx, sy, xx, yy, xy, cur);
|
||||
xy = 2*xx*yy;
|
||||
printf("F sx %d sy %d xx %ld yy %ld xy %ld cur %g\n", sx, sy, xx, yy, xy, cur);
|
||||
xx *= xx; yy *= yy; /* differences 2nd degree */
|
||||
printf("M sx %d sy %d xx %ld yy %ld xy %ld cur %g\n", sx, sy, xx, yy, xy, cur);
|
||||
if (cur*sx*sy < 0) { /* negated curvature? */
|
||||
printf("negate\n");
|
||||
xx = -xx; yy = -yy; xy = -xy; cur = -cur;
|
||||
}
|
||||
printf("1 sx %d sy %d xx %ld yy %ld xy %ld cur %g\n", sx, sy, xx, yy, xy, cur);
|
||||
printf("N sx %d sy %d xx %ld yy %ld xy %ld cur %g\n", sx, sy, xx, yy, xy, cur);
|
||||
dx = 4.0*sy*cur*(x1-x0)+xx-xy; /* differences 1st degree */
|
||||
dy = 4.0*sx*cur*(y0-y1)+yy-xy;
|
||||
xx += xx; yy += yy; err = dx+dy+xy; /* error 1st step */
|
||||
|
@ -41,6 +47,6 @@ void plotQuadBezierSeg(int x0, int y0, int x1, int y1, int x2, int y2)
|
|||
}
|
||||
|
||||
int main(void) {
|
||||
plotQuadBezierSeg(1, 1, 0x80, 0x100, 0x200, 0x140);
|
||||
plotQuadBezierSeg(0x200, 0x20, 0x180, 0x90, 0x180, 0x160);
|
||||
return 0;
|
||||
}
|
||||
|
|
2
ex11.mu
2
ex11.mu
|
@ -14,7 +14,7 @@
|
|||
fn main screen: (addr screen), keyboard: (addr keyboard), data-disk: (addr disk) {
|
||||
var env-storage: environment
|
||||
var env/esi: (addr environment) <- address env-storage
|
||||
initialize-environment env, 0x80 0x80, 0x200 0x180, 0x380 0x280
|
||||
initialize-environment env, 0x200 0x20, 0x180 0x90, 0x180 0x160
|
||||
{
|
||||
render screen, env
|
||||
edit keyboard, env
|
||||
|
|
Loading…
Reference in New Issue