https://github.com/akkartik/mu/blob/main/509bezier.mu
1
2
3
4
5
6
7
8
9
10
11
12
13
14 fn draw-monotonic-bezier screen: (addr screen), x0: int, y0: int, x1: int, y1: int, x2: int, y2: int, color: int {
15 var xx: int
16 var yy: int
17 var xy: int
18 var sx: int
19 var sy: int
20
21 var tmp/eax: int <- copy x2
22 tmp <- subtract x1
23 copy-to sx, tmp
24
25 tmp <- copy y2
26 tmp <- subtract y1
27 copy-to sy, tmp
28
29 tmp <- copy x0
30 tmp <- subtract x1
31 copy-to xx, tmp
32
33 tmp <- copy y0
34 tmp <- subtract y1
35 copy-to yy, tmp
36
37 var cur-f/xmm4: float <- convert xx
38 {
39 var sy-f/xmm1: float <- convert sy
40 cur-f <- multiply sy-f
41 var tmp2-f/xmm1: float <- convert yy
42 var sx-f/xmm2: float <- convert sx
43 tmp2-f <- multiply sx-f
44 cur-f <- subtract tmp2-f
45 }
46
47 {
48 tmp <- copy xx
49 tmp <- multiply sx
50 compare tmp, 0
51 break-if-<=
52 abort "bezier: gradient of x changes sign"
53 }
54
55 {
56 tmp <- copy yy
57 tmp <- multiply sy
58 compare tmp, 0
59 break-if-<=
60 abort "bezier: gradient of y changes sign"
61 }
62
63 {
64
65 var dist1/ecx: int <- copy sx
66 {
67 dist1 <- multiply sx
68 {
69 break-if-not-overflow
70 abort "bezier: overflow 1"
71 }
72 tmp <- copy sy
73 tmp <- multiply sy
74 {
75 break-if-not-overflow
76 abort "bezier: overflow 2"
77 }
78 dist1 <- add tmp
79 }
80
81 var dist2/edx: int <- copy xx
82 {
83 dist2 <- multiply xx
84 {
85 break-if-not-overflow
86 abort "bezier: overflow 3"
87 }
88 tmp <- copy yy
89 tmp <- multiply yy
90 {
91 break-if-not-overflow
92 abort "bezier: overflow 4"
93 }
94 dist2 <- add tmp
95 }
96
97 compare dist1, dist2
98 break-if-<=
99
100 tmp <- copy x0
101 copy-to x2, tmp
102 tmp <- copy sx
103 tmp <- add x1
104 copy-to x0, tmp
105
106 tmp <- copy y0
107 copy-to y2, tmp
108 tmp <- copy sy
109 tmp <- add y1
110 copy-to y0, tmp
111
112