History

libmemdraw: update memarc() and memellipse() from 9front

cinap_lenrek committed 7 years ago

Commit 5f074881 parent 176099b2 files · +21 −21Browse files

Unified · Split

2 files
  1. libmemdraw/arc.c +19 −17
  2. libmemdraw/ellipse.c +2 −4
libmemdraw/arc.c+19−17
@@ -24,9 +24,6 @@ Point corners[] = { · 23 unmodified lines
2424 {1,-1}
2525 };
2626
27−static
28−Point p00;
29−
3027 /*
3128 * make a "wedge" mask covering the desired angle and contained in
3229 * a surrounding square; draw a full ellipse; intersect that with the
@@ -40,13 +37,13 @@ memarc(Memimage *dst, Point c, int a, int b, int t, Memimage *src, Point sp, int · 7 unmodified lines
4037 Point p, bnd[8];
4138 Memimage *wedge, *figure, *mask;
4239
43− if(a < 0)
44− a = -a;
45− if(b < 0)
46− b = -b;
47− w = t;
48− if(w < 0)
49− w = 0;
40+ if(phi == 0)
41+ return;
42+ if(phi <= -360 || phi >= 360){
43+ memellipse(dst, c, a, b, t, src, sp, op);
44+ return;
45+ }
46+ alpha %= 360;
5047 alpha = -alpha; /* compensate for upside-down coords */
5148 phi = -phi;
5249 beta = alpha + phi;
@@ -56,10 +53,6 @@ memarc(Memimage *dst, Point c, int a, int b, int t, Memimage *src, Point sp, int · 3 unmodified lines
5653 beta = tmp;
5754 phi = -phi;
5855 }
59− if(phi >= 360){
60− memellipse(dst, c, a, b, t, src, sp, op);
61− return;
62− }
6356 while(alpha < 0)
6457 alpha += 360;
6558 while(beta < 0)
@@ -70,6 +63,15 @@ memarc(Memimage *dst, Point c, int a, int b, int t, Memimage *src, Point sp, int · 4 unmodified lines
7063 * icossin returns point at radius ICOSSCALE.
7164 * multiplying by m1 moves it outside the ellipse
7265 */
66+
67+ if(a < 0)
68+ a = -a;
69+ if(b < 0)
70+ b = -b;
71+ w = t;
72+ if(w < 0)
73+ w = 0;
74+
7375 rect = Rect(-a-w, -b-w, a+w+1, b+w+1);
7476 m = rect.max.x; /* inradius of bounding square */
7577 if(m < rect.max.y)
@@ -96,19 +98,19 @@ memarc(Memimage *dst, Point c, int a, int b, int t, Memimage *src, Point sp, int · 20 unmodified lines
9698 if(wedge == nil)
9799 goto Return;
98100 memfillcolor(wedge, DTransparent);
99− memfillpoly(wedge, bnd, i, ~0, memopaque, p00, S);
101+ memfillpoly(wedge, bnd, i, ~0, memopaque, ZP, S);
100102 figure = allocmemimage(rect, GREY1);
101103 if(figure == nil)
102104 goto Return;
103105 memfillcolor(figure, DTransparent);
104− memellipse(figure, p00, a, b, t, memopaque, p00, S);
106+ memellipse(figure, ZP, a, b, t, memopaque, ZP, S);
105107 mask = allocmemimage(rect, GREY1);
106108 if(mask == nil)
107109 goto Return;
108110 memfillcolor(mask, DTransparent);
109111 memimagedraw(mask, rect, figure, rect.min, wedge, rect.min, S);
110112 c = subpt(c, dst->r.min);
111− memdraw(dst, dst->r, src, subpt(sp, c), mask, subpt(p00, c), op);
113+ memdraw(dst, dst->r, src, subpt(sp, c), mask, subpt(ZP, c), op);
112114
113115 Return:
114116 freememimage(wedge);
libmemdraw/ellipse.c+2−4
@@ -164,8 +164,6 @@ memellipse(Memimage *dst, Point c, int a, int b, int t, Memimage *src, Point sp, · 163 unmodified lines
164164 }
165165 }
166166
167−static Point p00 = {0, 0};
168−
169167 /*
170168 * a brushed ellipse
171169 */
@@ -180,7 +178,7 @@ bellipse(int y, State *s, Param *p) · 8 unmodified lines
180178 if(p->disc == nil)
181179 return;
182180 memfillcolor(p->disc, DTransparent);
183− memellipse(p->disc, p00, t, t, -1, memopaque, p00, p->op);
181+ memellipse(p->disc, ZP, t, t, -1, memopaque, ZP, p->op);
184182 oy = y;
185183 ox = 0;
186184 nx = x = step(s);
@@ -211,7 +209,7 @@ erect(int x0, int y0, int x1, int y1, Param *p) · 24 unmodified lines
211209
212210 /* print("R %d,%d %d,%d\n", x0, y0, x1, y1); /**/
213211 r = Rect(p->c.x+x0, p->c.y+y0, p->c.x+x1+1, p->c.y+y1+1);
214− memdraw(p->dst, r, p->src, addpt(p->sp, r.min), memopaque, p00, p->op);
212+ memdraw(p->dst, r, p->src, addpt(p->sp, r.min), memopaque, ZP, p->op);
215213 }
216214
217215 /*

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t