]> pd.if.org Git - hexagon/blobdiff - hexagon.c
Added make target to make test files.
[hexagon] / hexagon.c
index 123e5cfa2539928b357a178f3bef9402c685df0f..264734c6c95ee17493d39f0cad5ce411821377da 100644 (file)
--- a/hexagon.c
+++ b/hexagon.c
@@ -31,6 +31,17 @@ double HL_fand[16] = {
        .577350269189625764509148780502, 0.0
 };
 
+double HL_hfand[16] = {
+       0.0, 0.0,
+       0.0, .577350269189625764509148780502,
+       0.5, .288675134594812882254574390251,
+       0.5, -.288675134594812882254574390251,
+       0.0, -.577350269189625764509148780502,
+       -0.5, -.288675134594812882254574390251,
+       -0.5, .288675134594812882254574390251,
+       0.0, .577350269189625764509148780502
+};
+
 float HL_fanf[16] = {
        0.0f, 0.0f,
        .577350269189625764509148780502f, 0.0f,
@@ -42,6 +53,21 @@ float HL_fanf[16] = {
        .577350269189625764509148780502f, 0.0f
 };
 
+float HL_hfanf[16] = {
+       0.0f, 0.0f,
+       0.0f, .577350269189625764509148780502f,
+       0.5f, .288675134594812882254574390251f,
+       0.5f, -.288675134594812882254574390251f,
+       0.0f, -.577350269189625764509148780502f,
+       -0.5f, -.288675134594812882254574390251f,
+       -0.5f, .288675134594812882254574390251f,
+       0.0f, .577350269189625764509148780502f
+};
+
+/* size of a square that will exactly fit in a hexagon */
+/* 2.0/(1+sqrt(3.0)) */
+double HL_square = .73205080756887729352;
+
 /* these all are for a hex one unit across */
 static double          hexptvd[6][2] = {
        {.577350269189625764509148780502, 0.0}, /* 1.0/sqrt3 */
@@ -459,14 +485,16 @@ static int hex_iso(struct hex *h) {
 
 #endif
 
+#define COS30 (.866025403784438646763723170752)
+
 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;
        int ix, iy, iz, s;
        struct hex h;
 
-       /* TODO just hard-code this cosine */
-       x = x / cos(30 * M_PI / 180.0); /* rotated X coord */
+       /*x = x / cos(30 * M_PI / 180.0); */ /* rotated X coord */
+       x = x / COS30;
        y = y - x / 2.0; /* adjustment for rotated X */
 
        /* adjust for actual hexwidth */