ref: fd9da88e582c0d1a4340bbc51fd899c719ed60b3
parent: 3e38012538f96fa06dcd8a3808a0f2936e83b5a4
author: qwx <qwx@sciops.net>
date: Thu Mar 17 03:07:21 EDT 2022
map: distance and conversion functions, resetting masp
--- a/path/map.c
+++ b/path/map.c
@@ -7,6 +7,59 @@
Node *map;
int mapwidth, mapheight;
+Vertex
+n2p(Node *n)
+{
+ return (Vertex){(n - map) % mapwidth, (n - map) / mapwidth};
+}
+
+Node *
+p2n(Vertex p)
+{
+ return map + p.y * mapwidth + p.x;
+}
+
+double
+eucdist(Node *a, Node *b)
+{
+ int dx, dy;
+ Vertex p, q;
+
+ p = n2p(a);
+ q = n2p(b);
+ dx = p.x - q.x;
+ dy = p.y - q.y;
+ return sqrt(dx *dx + dy *dy);
+}
+
+double
+octdist(Node *a, Node *b)
+{
+ int dx, dy;
+ Vertex p, q;
+
+ p = n2p(a);
+ q = n2p(b);
+ dx = abs(p.x - q.x);
+ dy = abs(p.y - q.y);
+ return 1 * (dx + dy) + MIN(dx, dy) * (SQRT2 - 2 * 1);
+}
+
+int
+isblocked(Node *n)
+{
+ return n->blocked;
+}
+
+void
+resetmap(void)
+{
+ Node *n;
+
+ for(n=map; n<map+mapwidth*mapheight; n++)
+ memset(&n->PNode, 0, sizeof n->PNode);
+}
+
void
initmap(void)
{