--- /dev/null
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+
+#include "hexagon.h"
+
+/*
+ * -s scale by n
+ * -h horizontal layout
+ * -r rotate grid n degrees counter clockwise
+ * -n append a newline
+ */
+int main(int ac, char *av[]) {
+ double scale = 1.0;
+#if 0
+ double rotate = 0.0;
+ double tx = 0.0, ty = 0.0; /* translation */
+ int horizontal = 0;
+ int newline = 0;
+#endif
+ int x, y;
+ char *format = NULL;
+
+ if (ac < 2) {
+ fprintf(stderr, "must give a command\n");
+ exit(EXIT_FAILURE);
+ }
+
+ if (!strcmp(av[1], "center")) {
+ struct HL_hex hex;
+ struct HL_point center;
+
+ x = strtol(av[2], NULL, 10);
+ y = strtol(av[3], NULL, 10);
+ hex = HL_hex_xy(x, y);
+ center = HL_hexcenter(hex);
+ printf(format ? format : "%f %f\n", center.x, center.y);
+ }
+ else if (!strcmp(av[1], "polar")) {
+ /* angle, radius */
+ struct HL_point pt;
+ double angle, dist;
+
+ angle = strtod(av[2], NULL);
+ dist = strtod(av[3], NULL);
+
+ pt = HL_polar(angle, dist, NULL);
+ printf(format ? format : "%f %f\n", pt.x, pt.y);
+ }
+ else if (!strcmp(av[1], "bin")) {
+ struct HL_hex hex;
+ /* angle, radius */
+ double px, py;
+ px = strtod(av[2], NULL);
+ py = strtod(av[3], NULL);
+
+ hex = HL_hexbin(scale, px, py);
+ printf(format ? format : "%d %d\n", hex.x, hex.y);
+ }
+ else if (!strcmp(av[1], "distance")) {
+ struct HL_hex from, to;
+ int x, y, n;
+
+ n = sscanf(av[2], "%d:%d", &x, &y);
+ if (n != 2) {
+ n = atoi(av[2]);
+ x = n % 100;
+ y = n / 100;
+ }
+ from.x = x;
+ from.y = y;
+
+ n = sscanf(av[3], "%d:%d", &x, &y);
+ if (n != 2) {
+ n = atoi(av[3]);
+ x = n % 100;
+ y = n / 100;
+ }
+ to.x = x;
+ to.y = y;
+
+ n = HL_distance(from, to);
+ printf(format ? format : "%d\n", n);
+ }
+
+ return 0;
+}