.288675134594812882254574390251, -0.5};
/* these all are for a hex one unit across */
-double hexptvd[6][2] = {
+static double hexptvd[6][2] = {
{.577350269189625764509148780502, 0.0}, /* 1.0/sqrt3 */
{.288675134594812882254574390251, 0.5}, /* 0.5/sqrt3 */
{-.288675134594812882254574390251, 0.5},
{.288675134594812882254574390251, -0.5}
};
+#if 0
+
/* TODO how is this related? to the above? */
-double texptvd[6][2] = {
+static double texptvd[6][2] = {
{1.154700538379251529018297561004, 0.5}, /* 2.0/sqrt3 */
{.866025403784438646763723170753, 1.0}, /* 1.5/sqrt3 */
{.288675134594812882254574390251, 1.0},
{.866025403784438646763723170753, 0.0}
};
-double hexpthd[6][2] = {
+static double hexpthd[6][2] = {
{0.0, .577350269189625764509148780502},
{0.5, .288675134594812882254574390251},
{0.5, -.288675134594812882254574390251},
{-0.5, .288675134594812882254574390251}
};
+#endif
+
void HL_vertices(int cantor, double *vc) {
int i;
double xc, yc;
* your input coordinates first.
*/
int HL_cantor_bin(double x, double y) {
- int i, j;
-
- HL_hexbin(1.0, x, y, &i, &j);
- return HL_cantor_xy(i, j);
+ return HL_hexbin(1.0, x, y, 0, 0);
}
static int xy2ijk(int x, int y, int *i, int *j, int *k) {
return range * 6;
}
+int HL_adjacent_hex(int start, int dir) {
+ if (dir < 0 || dir > 5) return 0;
+
+ return HL_adjhex(start, dir);
+}
+
/* direction 0 is positive X , counter clockwise from there */
int HL_adjhex(int start, int dir) {
int c[3];
return HL_cantor_ijkp(c);
}
-/* returns last hex in found path */
-int HL_findpath(int start, int end, int *path, int size) {
- return 0;
-}
-
int HL_cantor_xyp(int *xy) {
return HL_cantor_xy(xy[0], xy[1]);
}
return low;
}
-#ifdef ASTAR
-
-struct astar_hex {
- int hex;
- int f, g, h;
- int parent;
-};
-
-struct astar {
- int open, closed; /* how many in open or closed */
- int closedroom, openroom; /* how much is malloced */
- struct astar_hex *openlist;
- struct astar_hex *closedlist;
- int known, index;
- int error;
-};
-
-static void astar_init(struct astar *state) {
- state->open = 0;
- state->closed = 0;
- state->closedroom = 0;
- state->openroom = 0;
- state->openlist = 0;
- state->closedlist = 0;
- state->error = 0;
- state->known = 0;
- state->index = 0;
-
- return;
-}
-
-static void removeopen(struct astar *s, int hex) {
- int index;
-
- if (s->error) return;
- if (s->open == 0) return;
-
- if (s->known != hex) {
- for (index = 0; index < s->open; index++) {
- if (s->openlist[index].hex == hex) break;
- }
- } else {
- index = s->index;
- s->known = 0; s->index = 0;
- }
- s->openlist[index] = s->openlist[open];
- s->open--;
-}
-
-static void addopen(struct astar *s, int hex) {
- struct astar_hex *mem;
- if (s->error) return;
-
- if (s->open + 1 > s->openroom) {
- mem = realloc(s->openlist, s->openroom * 2 * sizeof *mem);
- if (mem == NULL) {
- s->error = errno;
- return;
- }
- state->openlist = mem;
- s->openroom = s->openroom * 2;
- }
-
- s->openlist[s->open].hex = hex;
- s->openlist[s->open].f = 0;
- s->openlist[s->open].g = 0;
- s->openlist[s->open].h = 0;
- s->known = hex;
- s->index = s->open;
- s->open = s->open + 1;
-}
-
-int lowrank(struct astar *s) {
- int f;
- int hex;
- int i;
-
- if (!s || s->open = 0) return 0;
-
- hex = s->openlist[0].hex;
- f = s->openlist[0].f;
-
- for(i=1; i < s->open; i++) {
- if (s->openlist[i].f < f) {
- hex = s->openlist[i].hex;
- f = s->openlist[i].f;
- }
- /* TODO check s->openlist[i].tiebreak */
- }
-
- return hex;
-}
-
-static int default_metric(int a, int b) {
- return 1;
-}
-
-/*
- * find a path from start to end. we use A*
- */
-int HL_findpath(int start, int end, int psize, int *path,
- double (*metric)(int,int)) {
- int neighbors[6];
- int count;
- int cur = 0;
- struct astar state;
- int neighbor;
-
- if (start == end) return 0;
- if (!metric) metric = default_metric;
-
- astar_init(&state);
- addopen(&state, start);
-
- while (1) {
- cur = lowrank(&state);
- if (cur == end) {
- break;
- }
- addclosed(&state, cur);
- count = HL_hexes_at_range(cur->hex, 1, neighbors, 6);
- for (i=0;i<count;i++) {
- neighbor = neighbors[i];
- cost = g(&state, current) + metric(current, neighbor);
- if (inopen(&state, neighbor) && cost < g(&state, neighbor)) {
- removeopen(&state, neighbor);
- } else
- if (inclosed(&state, neighbor) && cost < g(&state, neighbor)) {
- /* should never happen with
- * admissible heuristic
- */
- removeclosed(&state, neighbor);
- } else
- if (!inopen(&state, neighbor) && !inclosed(&state, neighbor)) {
- addopen(&state, neighbor);
- setg(&state, neighbor, cost);
- setrank(&state, neighbor, cost + h(neighbor,end));
- setparent(&state, neighbor, current);
- } else {
- abort();
- }
- }
- }
-
- count = 0;
- while (parent(&state, cur) != start) {
- count++;
- cur = parent(&state, cur);
- }
- cur = end;
- while (parent(&state, cur) != start) {
- path[count--] = cur;
- cur = parent(&state, cur);
- }
-
-}
-
-#endif
-
static int inversenatcantor(int cantor, int *x, int *y) {
int w, t, py;
return 1;
}
+#if 0
+
static int hex_iso(struct hex *h) {
if (h->iso) return 1;
return 1;
}
+#endif
+
int HL_hexbin(double width, double x, double y, int *i, int *j) {
double z, rx, ry, rz;
double abs_dx, abs_dy, abs_dz;