shithub: asif

Download patch

ref: 4fc3d01480226fa78b93aff1c5f09a42b2f3d430
parent: 114fd38270ce1ed89694548e11f854ad501376f4
author: qwx <qwx@sciops.net>
date: Sat Mar 26 12:26:54 EDT 2022

drw: draw predecessor arrows

--- a/path/dat.h
+++ b/path/dat.h
@@ -16,9 +16,12 @@
 	Node *from;
 	Pairheap *pq;
 };
+enum{
+	Nodesz = 8,
+};
 struct Node{
 	int blocked;
-	PNode;		// generalize later
+	PNode;
 };
 extern Node *map;
 extern int mapwidth, mapheight;
--- a/path/drw.c
+++ b/path/drw.c
@@ -11,9 +11,6 @@
 typedef Vertex Point;
 
 enum{
-	Nodesz = 8,
-};
-enum{
 	Cbg,
 	Cgrid,
 	Cfree,
@@ -81,29 +78,13 @@
 }
 
 static void
-drawmap(void)
+drawnodes(void)
 {
-	Rectangle r;
 	Node *n;
+	Rectangle r;
 	Image *c;
 
-	draw(view, view->r, col[Cfree], nil, ZP);
-	r = viewr;
-	while(r.min.x < viewr.max.x){
-		r.max.x = r.min.x;
-		line(view, r.min, r.max, 0, 0, 0, col[Cgrid], ZP);
-		r.min.x += Nodesz;
-	}
-	r = viewr;
-	while(r.min.y < viewr.max.y){
-		r.max.y = r.min.y;
-		line(view, r.min, r.max, 0, 0, 0, col[Cgrid], ZP);
-		r.min.y += Nodesz;
-	}
 	for(n=map; n<map+mapwidth*mapheight; n++){
-		r.min.x = (n - map) % mapwidth * Nodesz + 1;
-		r.min.y = (n - map) / mapwidth * Nodesz + 1;
-		r.max = addpt(r.min, Pt(Nodesz-1, Nodesz-1));
 		if(n->blocked)
 			c = col[Cblocked];
 		else if(n == start)
@@ -118,8 +99,46 @@
 			c = col[Copen];
 		else
 			continue;
+		r.min = n2s(n);
+		r.max = addpt(r.min, Pt(Nodesz-1, Nodesz-1));
 		draw(view, r, c, nil, ZP);
 	}
+}
+
+static void
+drawfrom(void)
+{
+	Node *n;
+	Point p0, p1;
+
+	for(n=map; n<map+mapwidth*mapheight; n++){
+		if(!n->open)
+			continue;
+		p1 = addpt(n2s(n), Pt(Nodesz / 2, Nodesz / 2));
+		p0 = addpt(n2s(n->from), Pt(Nodesz / 2, Nodesz / 2));
+		line(view, p0, p1, Endarrow, 0, 0, col[Cgrid], ZP);
+	}
+}
+static void
+drawmap(void)
+{
+	Rectangle r;
+
+	draw(view, view->r, col[Cfree], nil, ZP);
+	r = viewr;
+	while(r.min.x < viewr.max.x){
+		r.max.x = r.min.x;
+		line(view, r.min, r.max, 0, 0, 0, col[Cgrid], ZP);
+		r.min.x += Nodesz;
+	}
+	r = viewr;
+	while(r.min.y < viewr.max.y){
+		r.max.y = r.min.y;
+		line(view, r.min, r.max, 0, 0, 0, col[Cgrid], ZP);
+		r.min.y += Nodesz;
+	}
+	drawnodes();
+	drawfrom();
 }
 
 static void