shithub: drawterm

Download patch

ref: 5f074880c5c2cd8a23883271bb7e27939e769186
parent: 176099bb8164a5b9f7bb7d98db480e08d0b5c5e2
author: cinap_lenrek <cinap_lenrek@felloff.net>
date: Sat Mar 9 14:51:48 EST 2019

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

--- a/libmemdraw/arc.c	Tue Feb 12 22:05:46 2019
+++ b/libmemdraw/arc.c	Sat Mar  9 14:51:48 2019
@@ -24,9 +24,6 @@
 	{1,-1}
 };
 
-static
-Point p00;
-
 /*
  * make a "wedge" mask covering the desired angle and contained in
  * a surrounding square; draw a full ellipse; intersect that with the
@@ -40,13 +37,13 @@
 	Point p,	bnd[8];
 	Memimage *wedge, *figure, *mask;
 
-	if(a < 0)
-		a = -a;
-	if(b < 0)
-		b = -b;
-	w = t;
-	if(w < 0)
-		w = 0;
+	if(phi == 0)
+		return;
+	if(phi <= -360 || phi >= 360){
+		memellipse(dst, c, a, b, t, src, sp, op);
+		return;
+	}
+	alpha %= 360;
 	alpha = -alpha;		/* compensate for upside-down coords */
 	phi = -phi;
 	beta = alpha + phi;
@@ -56,10 +53,6 @@
 		beta = tmp;
 		phi = -phi;
 	}
-	if(phi >= 360){
-		memellipse(dst, c, a, b, t, src, sp, op);
-		return;
-	}
 	while(alpha < 0)
 		alpha += 360;
 	while(beta < 0)
@@ -70,6 +63,15 @@
 		 * icossin returns point at radius ICOSSCALE.
 		 * multiplying by m1 moves it outside the ellipse
 		*/
+
+	if(a < 0)
+		a = -a;
+	if(b < 0)
+		b = -b;
+	w = t;
+	if(w < 0)
+		w = 0;
+
 	rect = Rect(-a-w, -b-w, a+w+1, b+w+1);
 	m = rect.max.x;	/* inradius of bounding square */
 	if(m < rect.max.y)
@@ -96,19 +98,19 @@
 	if(wedge == nil)
 		goto Return;
 	memfillcolor(wedge, DTransparent);
-	memfillpoly(wedge, bnd, i, ~0, memopaque, p00, S);
+	memfillpoly(wedge, bnd, i, ~0, memopaque, ZP, S);
 	figure = allocmemimage(rect, GREY1);
 	if(figure == nil)
 		goto Return;
 	memfillcolor(figure, DTransparent);
-	memellipse(figure, p00, a, b, t, memopaque, p00, S);
+	memellipse(figure, ZP, a, b, t, memopaque, ZP, S);
 	mask = allocmemimage(rect, GREY1);
 	if(mask == nil)
 		goto Return;
 	memfillcolor(mask, DTransparent);
 	memimagedraw(mask, rect, figure, rect.min, wedge, rect.min, S);
 	c = subpt(c, dst->r.min);
-	memdraw(dst, dst->r, src, subpt(sp, c), mask, subpt(p00, c), op);
+	memdraw(dst, dst->r, src, subpt(sp, c), mask, subpt(ZP, c), op);
 
     Return:
 	freememimage(wedge);
--- a/libmemdraw/ellipse.c	Tue Feb 12 22:05:46 2019
+++ b/libmemdraw/ellipse.c	Sat Mar  9 14:51:48 2019
@@ -164,8 +164,6 @@
 	}
 }
 
-static Point p00 = {0, 0};
-
 /*
  * a brushed ellipse
  */
@@ -180,7 +178,7 @@
 	if(p->disc == nil)
 		return;
 	memfillcolor(p->disc, DTransparent);
-	memellipse(p->disc, p00, t, t, -1, memopaque, p00, p->op);
+	memellipse(p->disc, ZP, t, t, -1, memopaque, ZP, p->op);
 	oy = y;
 	ox = 0;
 	nx = x = step(s);
@@ -211,7 +209,7 @@
 
 /*	print("R %d,%d %d,%d\n", x0, y0, x1, y1); /**/
 	r = Rect(p->c.x+x0, p->c.y+y0, p->c.x+x1+1, p->c.y+y1+1);
-	memdraw(p->dst, r, p->src, addpt(p->sp, r.min), memopaque, p00, p->op);
+	memdraw(p->dst, r, p->src, addpt(p->sp, r.min), memopaque, ZP, p->op);
 }
 
 /*