瀏覽代碼

refactoring 2

olinox 8 年之前
父節點
當前提交
43f95724af
共有 4 個文件被更改,包括 202 次插入198 次删除
  1. 38 29
      pypog/geometry.py
  2. 1 1
      pypog/grid_objects.py
  3. 1 1
      pypog/painting.py
  4. 162 167
      tests/test_geometry.py

+ 38 - 29
pypog/geometry.py

@@ -14,22 +14,19 @@
     * triangle3d function return the list of the cells in a cone from its apex (xa, ya, za) to its base (xh, yh, zh)
     * pivot function return a list of coordinates after a counterclockwise rotation of a given list of coordinates, around a given center
 
-
     ** By Cro-Ki l@b, 2017 **
 '''
 from math import sqrt
 
-CELL_SHAPES = (4, 6)
 
+# ## Cell shapes
 SQUARE = 4
 FLAT_HEX = 61
 TOP_HEX = 62
 CELL_SHAPES = (SQUARE, FLAT_HEX, TOP_HEX)
 
-ANGLES = (1, 2, 3)
-
-class UnknownCellShape(ValueError): pass
-
+class UnknownCellShape(ValueError):
+    msg = "'cell_shape' has to be a value from CELL_SHAPES"
 
 
 # ## NEIGHBOURS
@@ -37,20 +34,22 @@ class UnknownCellShape(ValueError): pass
 def neighbours(cell_shape, x, y):
     """ returns the list of coords of the neighbours of a cell"""
     if cell_shape == SQUARE:
-        return squ_neighbours(x, y)
+        return squ2_neighbours(x, y)
     elif cell_shape == FLAT_HEX:
-        return fhex_neighbours(x, y)
+        return fhex2_neighbours(x, y)
+    elif cell_shape == TOP_HEX:
+        raise NotImplementedError()
     else:
-        raise ValueError("'cell_shape' has to be a value from CELL_SHAPES")
+        raise UnknownCellShape()
 
-def fhex_neighbours(x, y):
+def fhex2_neighbours(x, y):
     """ returns the list of coords of the neighbours of a cell on an hexagonal grid"""
     if x % 2 == 0:
         return [(x, y - 1), (x + 1, y - 1), (x + 1, y), (x, y + 1), (x - 1, y), (x - 1, y - 1)]
     else:
         return [(x, y - 1), (x + 1, y), (x + 1, y + 1), (x, y + 1), (x - 1, y + 1), (x - 1, y)]
 
-def squ_neighbours(x, y):
+def squ2_neighbours(x, y):
     """ returns the list of coords of the neighbours of a cell on an square grid"""
     return [(x - 1, y - 1), (x, y - 1), (x + 1, y - 1), \
             (x - 1, y), (x + 1, y)  , \
@@ -75,24 +74,26 @@ def zone(cell_shape, x0, y0, radius):
 
 # ## LINES (implementations of bresenham algorithm)
 
-def line2d(cell_shape, x1, y1, x2, y2):
+def line(cell_shape, x1, y1, x2, y2):
     """returns a line from x1,y1 to x2,y2
     grid could be one of the GRIDTYPES values"""
     if not all(isinstance(c, int) for c in [x1, y1, x2, y2]):
         raise TypeError("x1, y1, x2, y2 have to be integers")
     if cell_shape == FLAT_HEX:
-        return fhex_line(x1, y1, x2, y2)
+        return fhex2_line(x1, y1, x2, y2)
     elif cell_shape == SQUARE:
         return squ2_line(x1, y1, x2, y2)
+    elif cell_shape == TOP_HEX:
+        raise NotImplementedError()
     else:
-        raise ValueError("'cell_shape' has to be a value from CELL_SHAPES")
+        raise UnknownCellShape()
 
 def line3d(cell_shape, x1, y1, z1, x2, y2, z2):
     """returns a line from x1,y1,z1 to x2,y2,z2
     grid could be one of the GRIDTYPES values"""
     if not all(isinstance(c, int) for c in [z1, z2]):
         raise TypeError("x1, y1, z1, x2, y2, z2 have to be integers")
-    hoLine = line2d(cell_shape, x1, y1, x2, y2)
+    hoLine = line(cell_shape, x1, y1, x2, y2)
     if z1 == z2:
         return [(x, y, z1) for x, y in hoLine]
     else:
@@ -134,7 +135,7 @@ def squ2_line(x1, y1, x2, y2):
         result.reverse()
     return result
 
-def fhex_line(x1, y1, x2, y2):
+def fhex2_line(x1, y1, x2, y2):
     """Line Bresenham algorithm for hexagonal grid"""
     if (x1, y1) == (x2, y2):
         return [(x1, y1)]
@@ -250,6 +251,8 @@ def hollow_rectangle(x1, y1, x2, y2):
 
 # ## TRIANGLES
 
+ANGLES = (1, 2, 3)
+
 def triangle(cell_shape, xa, ya, xh, yh, iAngle):
     """Returns a list of (x, y) coordinates in a triangle
     A is the top of the triangle, H if the middle of the base
@@ -263,8 +266,10 @@ def triangle(cell_shape, xa, ya, xh, yh, iAngle):
         return squ2_triangle(xa, ya, xh, yh, iAngle)
     elif cell_shape == FLAT_HEX:
         return fhex2_triangle(xa, ya, xh, yh, iAngle)
+    elif cell_shape == TOP_HEX:
+        raise NotImplementedError()
     else:
-        raise ValueError("'cell_shape' has to be a value from CELL_SHAPES")
+        raise UnknownCellShape()
 
 def triangle3d(cell_shape, xa, ya, za, xh, yh, zh, iAngle):
     """Returns a list of (x, y, z) coordinates in a 3d-cone
@@ -287,8 +292,10 @@ def triangle3d(cell_shape, xa, ya, za, xh, yh, zh, iAngle):
         return squ3_triangle(xa, ya, za, xh, yh, zh, iAngle)
     elif cell_shape == FLAT_HEX:
         return fhex3_triangle(xa, ya, za, xh, yh, zh, iAngle)
+    elif cell_shape == TOP_HEX:
+        raise NotImplementedError()
     else:
-        raise ValueError("'cell_shape' has to be a value from CELL_SHAPES")
+        raise UnknownCellShape()
 
 
 def squ2_triangle(xa, ya, xh, yh, iAngle):
@@ -318,7 +325,7 @@ def squ2_triangle(xa, ya, xh, yh, iAngle):
 
     # base (lower slope)
     x1, y1, x2, y2 = min(lines, key=lambda x: (abs ((x[3] - x[1]) / (x[2] - x[0])) if x[2] != x[0] else 10 ** 10))
-    base = line2d(SQUARE, x1, y1, x2, y2)
+    base = line(SQUARE, x1, y1, x2, y2)
     y_base = y1
     lines.remove((x1, y1, x2, y2))
 
@@ -328,7 +335,7 @@ def squ2_triangle(xa, ya, xh, yh, iAngle):
     for x1, y1, x2, y2 in lines:
         if y_top == None:
             y_top = y2
-        hat.extend(line2d(SQUARE, x1, y1, x2, y2))
+        hat.extend(line(SQUARE, x1, y1, x2, y2))
 
     # sense (1 if top is under base, -1 if not)
     sense = 1 if y_top > y_base else -1
@@ -377,7 +384,7 @@ def fhex2_triangle(xa, ya, xh, yh, iAngle):
 
     # base (lower slope)
     x1, y1, x2, y2 = min(segments, key=lambda x: (abs ((x[3] - x[1]) / (x[2] - x[0])) if x[2] != x[0] else 10 ** 10))
-    base = line2d(FLAT_HEX, x1, y1, x2, y2)
+    base = line(FLAT_HEX, x1, y1, x2, y2)
     y_base = y1
     segments.remove((x1, y1, x2, y2))
 
@@ -387,7 +394,7 @@ def fhex2_triangle(xa, ya, xh, yh, iAngle):
     for x1, y1, x2, y2 in segments:
         if y_sommet == None:
             y_sommet = y2
-        chapeau.extend(line2d(FLAT_HEX, x1, y1, x2, y2))
+        chapeau.extend(line(FLAT_HEX, x1, y1, x2, y2))
 
     # sense (1 if top is under base, -1 if not)
     sens = 1 if y_sommet > y_base else -1
@@ -411,7 +418,7 @@ def squ3_triangle(xa, ya, za, xh, yh, zh, iAngle):
 
     length = max(abs(xh - xa), abs(yh - ya))
 
-    vertical_line = line2d(SQUARE, 0, za, length, zh)
+    vertical_line = line(SQUARE, 0, za, length, zh)
 
     # build a dict with X key and value is a list of Z values
     vertical_line_dict = {d:[] for d, z in vertical_line}
@@ -445,7 +452,7 @@ def fhex3_triangle(xa, ya, za, xh, yh, zh, iAngle):
 
     length = max(abs(xuh - xua), abs(yuh - yua), abs(zuh - zua))
 
-    vertical_line = line2d(SQUARE, 0, za, length, zh)
+    vertical_line = line(SQUARE, 0, za, length, zh)
 
     # build a dict with X key and value is a list of Z values
     vertical_line_dict = {d:[] for d, z in vertical_line}
@@ -496,14 +503,16 @@ def pivot(cell_shape, center, coordinates, rotations):
 
     # call the method according to cells shape
     if cell_shape == SQUARE:
-        return squ_pivot(center, coordinates, rotations)
+        return squ2_pivot(center, coordinates, rotations)
     elif cell_shape == FLAT_HEX:
-        return fhex_pivot(center, coordinates, rotations)
+        return fhex2_pivot(center, coordinates, rotations)
+    elif cell_shape == TOP_HEX:
+        raise NotImplementedError()
     else:
-        raise ValueError("'cell_shape' has to be a value from CELL_SHAPES")
+        raise UnknownCellShape()
 
 
-def fhex_pivot(center, coordinates, rotations):
+def fhex2_pivot(center, coordinates, rotations):
     """pivot 'rotations' times the coordinates (list of (x, y) tuples)
     around the center coordinates (x,y)
     On hexagonal grid, rotates of 60 degrees each time"""
@@ -523,7 +532,7 @@ def fhex_pivot(center, coordinates, rotations):
         result.append((xr, yr))
     return result
 
-def squ_pivot(center, coordinates, rotations):
+def squ2_pivot(center, coordinates, rotations):
     """pivot 'rotations' times the coordinates (list of (x, y) tuples)
     around the center coordinates (x,y)
     On square grid, rotates of 90 degrees each time"""

+ 1 - 1
pypog/grid_objects.py

@@ -88,7 +88,7 @@ class Grid(object):
         return (x > 0 and x <= self._width and y > 0 and y <= self._height)
 
     def line(self, x1, y1, x2, y2):
-        return geometry.line2d(self.cell_shape, x1, y1, x2, y2)
+        return geometry.line(self.cell_shape, x1, y1, x2, y2)
 
     def line3d(self, x1, y1, z1, x2, y2, z2):
         return geometry.line3d(self.cell_shape, x1, y1, z1, x2, y2, z2)

+ 1 - 1
pypog/painting.py

@@ -129,7 +129,7 @@ class LinePencil(BasePencil):
         # use a set because of performance (should we generalize the use of sets for coordinates lists?)
         result = set([])
 
-        line = set(geometry.line2d(self._grid.cell_shape, x0, y0, x, y))
+        line = set(geometry.line(self._grid.cell_shape, x0, y0, x, y))
 
         # apply size with geometry.zone
         if self._grid.size >= 1:

+ 162 - 167
tests/test_geometry.py

@@ -1,5 +1,7 @@
 '''
 
+    Tests for 'geometry' module
+
     ** By Cro-Ki l@b, 2017 **
 '''
 import unittest
@@ -9,19 +11,54 @@ from pypog import geometry
 
 class Test(unittest.TestCase):
 
-    def test_line_errors(self):
-        self.assertRaises(TypeError, geometry.line2d, geometry.FLAT_HEX, "a", 1, 1, 1)
-        self.assertRaises(TypeError, geometry.line2d, geometry.FLAT_HEX, 1, "a", 1, 1)
-        self.assertRaises(TypeError, geometry.line2d, geometry.FLAT_HEX, 1, 1, "a", 1)
-        self.assertRaises(TypeError, geometry.line2d, geometry.FLAT_HEX, 1, 1, 1, "a")
-        self.assertRaises(ValueError, geometry.line2d, 0, 1, 1, 1, 1)
+    # # neighbours
 
-        self.assertRaises(TypeError, geometry.line3d, geometry.FLAT_HEX, 1, 1, "a", 1, 1, 1)
-        self.assertRaises(TypeError, geometry.line3d, geometry.FLAT_HEX, 1, 1, 1, 1, 1, "a")
+    def test_neighbours(self):
+        """ test for geometry.neighbours """
+        for coord in ((0, 0), (-10, -10), (10, 10)):
+            x, y = coord
+            self.assertEqual(geometry.neighbours(geometry.FLAT_HEX, x, y), geometry.fhex2_neighbours(x, y))
+            self.assertEqual(geometry.neighbours(geometry.SQUARE, x, y), geometry.squ2_neighbours(x, y))
+
+    def test_fhex2_neighbours(self):
+        """ test for geometry.fhex2_neighbours """
+        self.assertCountEqual(geometry.fhex2_neighbours(3, 3), [(3, 2), (4, 3), (4, 4), (3, 4), (2, 4), (2, 3)])
+        self.assertCountEqual(geometry.fhex2_neighbours(4, 4), [(4, 3), (5, 3), (5, 4), (4, 5), (3, 4), (3, 3)])
+
+    def test_squ2_neighbours(self):
+        """ test for geometry.squ2_neighbours """
+        self.assertCountEqual(geometry.squ2_neighbours(3, 3), [(2, 3), (2, 2), (3, 2), (4, 2), (4, 3), (4, 4), (3, 4), (2, 4)])
+
+    def test_zone(self):
+        """ test for geometry.zone """
+        self.assertRaises(TypeError, geometry.zone, 5, 0, 0, "a")
+        self.assertRaises(TypeError, geometry.zone, 5, "a", 0, 1)
+        self.assertRaises(TypeError, geometry.zone, 5, 0, "a", 1)
+        self.assertRaises(ValueError, geometry.zone, 5, 0, 0, -1)
+        self.assertRaises(ValueError, geometry.zone, -1, 0, 0, 1)
+        self.assertRaises(ValueError, geometry.zone, "a", 0, 0, 1)
+
+        self.assertCountEqual(geometry.zone(geometry.FLAT_HEX, 3, 3, 0), [(3, 3)])
+        self.assertCountEqual(geometry.zone(geometry.FLAT_HEX, 3, 3, 1), [(3, 2), (2, 3), (3, 3), (4, 3), (4, 4), (3, 4), (2, 4)])
+        self.assertCountEqual(geometry.zone(geometry.FLAT_HEX, 3, 3, 2), [(3, 2), (1, 3), (5, 4), (4, 5), (1, 4), (2, 3), (4, 2), \
+                                                            (2, 5), (5, 3), (1, 2), (3, 5), (3, 3), (4, 4), (3, 1), \
+                                                            (4, 3), (2, 2), (3, 4), (2, 4), (5, 2)])
+
+        self.assertCountEqual(geometry.zone(geometry.SQUARE, 3, 3, 0), [(3, 3)])
+        self.assertCountEqual(geometry.zone(geometry.SQUARE, 3, 3, 1), [(3, 2), (3, 3), (4, 4), (2, 3), (4, 3), (2, 2), (4, 2), (3, 4), (2, 4)])
+        self.assertCountEqual(geometry.zone(geometry.SQUARE, 3, 3, 2), [(2, 4), (3, 2), (5, 4), (1, 3), (4, 5), (2, 1), (1, 4), (2, 3), (4, 2), \
+                                                                    (5, 1), (2, 5), (3, 5), (5, 3), (1, 2), (3, 3), (5, 5), (4, 4), (3, 1), \
+                                                                    (1, 5), (4, 3), (2, 2), (4, 1), (5, 2), (3, 4), (1, 1)])
+
+    # # lines
 
     def test_line2d(self):
-        """ 2d line on square or hexagonal grid """
-        cell_shape = geometry.FLAT_HEX
+        """ test for geometry.line """
+        self.assertRaises(TypeError, geometry.line, geometry.FLAT_HEX, "a", 1, 1, 1)
+        self.assertRaises(TypeError, geometry.line, geometry.FLAT_HEX, 1, "a", 1, 1)
+        self.assertRaises(TypeError, geometry.line, geometry.FLAT_HEX, 1, 1, "a", 1)
+        self.assertRaises(TypeError, geometry.line, geometry.FLAT_HEX, 1, 1, 1, "a")
+        self.assertRaises(ValueError, geometry.line, 0, 1, 1, 1, 1)
 
         attended = {
                     geometry.FLAT_HEX:    {
@@ -52,13 +89,14 @@ class Test(unittest.TestCase):
                    }
 
         for cell_shape, tests in attended.items():
-            for args, result in tests.items():
-                line = geometry.line2d(cell_shape, *args)
-                self.assertEqual(line, result)
+            for args, attended in tests.items():
+                result = geometry.line(cell_shape, *args)
+                self.assertEqual(result, attended)
 
     def test_line3d(self):
-        """ 3d line on hexagonal and square grid """
-        cell_shape = geometry.FLAT_HEX
+        """ test for geometry.line3d """
+        self.assertRaises(TypeError, geometry.line3d, geometry.FLAT_HEX, 1, 1, "a", 1, 1, 1)
+        self.assertRaises(TypeError, geometry.line3d, geometry.FLAT_HEX, 1, 1, 1, 1, 1, "a")
 
         attended = {
                     geometry.FLAT_HEX:    {
@@ -85,76 +123,22 @@ class Test(unittest.TestCase):
                 line = geometry.line3d(cell_shape, *args)
                 self.assertEqual(line, result)
 
-    def test_neighbours(self):
-        for coord in ((0, 0), (-10, -10), (10, 10)):
-            x, y = coord
-            self.assertEqual(geometry.neighbours(geometry.FLAT_HEX, x, y), geometry.fhex_neighbours(x, y))
-            self.assertEqual(geometry.neighbours(geometry.SQUARE, x, y), geometry.squ_neighbours(x, y))
-
-    def test_fhex_neighbours(self):
-        self.assertCountEqual(geometry.fhex_neighbours(3, 3), [(3, 2), (4, 3), (4, 4), (3, 4), (2, 4), (2, 3)])
-        self.assertCountEqual(geometry.fhex_neighbours(4, 4), [(4, 3), (5, 3), (5, 4), (4, 5), (3, 4), (3, 3)])
-
-    def test_squ_neighbours(self):
-        self.assertCountEqual(geometry.squ_neighbours(3, 3), [(2, 3), (2, 2), (3, 2), (4, 2), (4, 3), (4, 4), (3, 4), (2, 4)])
-
-    def test_pivot_errors(self):
+    def test_squ2_line(self):
+        """ test for geometry.squ2_line """
+        pass
 
-        # invalid cell shape
-        self.assertRaises(ValueError, geometry.pivot, 0, (0, 0), [(0, 0)], 1)
+    def test_fhex2_line(self):
+        """ test for geometry.fhex2_line """
+        pass
 
-        self.assertRaises(TypeError, geometry.pivot, 0, "a"    , [(0, 0)], 1)
-        self.assertRaises(ValueError, geometry.pivot, 0, ("a", 0), [(0, 0)], 1)
-
-        self.assertRaises(TypeError, geometry.pivot, 0, (0, 0), 0, 1)
-        self.assertRaises(ValueError, geometry.pivot, 0, (0, 0), ["a", (0, 0)], 1)
-        self.assertRaises(ValueError, geometry.pivot, 0, (0, 0), [("a", 0), (0, 0)], 1)
-
-        self.assertRaises(TypeError, geometry.pivot, 0, (0, 0), 1, "a")
-
-    def test_hex_pivot(self):
-        """ pivot on hexagonal grid """
-
-        attended = [
-                    [(5, 5), (4, 5), (6, 6)],
-                    [(5, 6), (4, 7), (6, 6)],
-                    [(6, 7), (6, 8), (6, 6)],
-                    [(7, 6), (8, 7), (6, 6)],
-                    [(7, 5), (8, 5), (6, 6)],
-                    [(6, 5), (6, 4), (6, 6)],
-                    [(5, 5), (4, 5), (6, 6)]
-                   ]
-
-
-        for i in range(len(attended)):
-            self.assertCountEqual(geometry.pivot(geometry.FLAT_HEX, (6, 6), [(6, 6)], i), [(6, 6)])
-            result = geometry.pivot(geometry.FLAT_HEX, (6, 6), [(5, 5), (4, 5), (6, 6)], i)
-            self.assertCountEqual(result, attended[i])
-
-    def test_squ_pivot(self):
-        """ pivot on square grid """
-        attended = [
-                    [(6, 6), (6, 5), (5, 5), (5, 6)],
-                    [(6, 6), (5, 6), (5, 7), (6, 7)],
-                    [(6, 6), (6, 7), (7, 7), (7, 6)],
-                    [(6, 6), (7, 6), (7, 5), (6, 5)],
-                    [(6, 6), (6, 5), (5, 5), (5, 6)]
-                   ]
-
-        for i in range(len(attended)):
-            self.assertCountEqual(geometry.pivot(geometry.SQUARE, (6, 6), [(6, 6)], i), [(6, 6)])
-            result = geometry.pivot(geometry.SQUARE, (6, 6), [(6, 6), (6, 5), (5, 5), (5, 6)], i)
-            self.assertCountEqual(result, attended[i])
-
-
-    def test_rectangle_errors(self):
-        for method in (geometry.rectangle, geometry.hollow_rectangle):
-            self.assertRaises(TypeError, method, "a", 1, 1, 1)
-            self.assertRaises(TypeError, method, 1, "a", 1, 1)
-            self.assertRaises(TypeError, method, 1, 1, "a", 1)
-            self.assertRaises(TypeError, method, 1, 1, 1, "a")
 
+    # # Rectangles
     def test_rectangle(self):
+        """ test for geometry.rectangle """
+        self.assertRaises(TypeError, geometry.rectangle, "a", 1, 1, 1)
+        self.assertRaises(TypeError, geometry.rectangle, 1, "a", 1, 1)
+        self.assertRaises(TypeError, geometry.rectangle, 1, 1, "a", 1)
+        self.assertRaises(TypeError, geometry.rectangle, 1, 1, 1, "a")
 
         self.assertEquals(geometry.rectangle(0, 0, 0, 0), [(0, 0)])
         self.assertCountEqual(geometry.rectangle(0, 0, 1, 1), [(0, 0), (0, 1), (1, 1), (1, 0)])
@@ -166,6 +150,13 @@ class Test(unittest.TestCase):
                                                        (7, 6), (8, 7), (4, 8), (5, 7), (6, 8), (7, 7), (8, 8), (7, 8), (5, 8), (8, 3), (6, 3), (4, 3),
                                                        (5, 3)])
 
+    def test_hollow_rectangle(self):
+        """ test for geometry.hollow_rectangle """
+        self.assertRaises(TypeError, geometry.hollow_rectangle, "a", 1, 1, 1)
+        self.assertRaises(TypeError, geometry.hollow_rectangle, 1, "a", 1, 1)
+        self.assertRaises(TypeError, geometry.hollow_rectangle, 1, 1, "a", 1)
+        self.assertRaises(TypeError, geometry.hollow_rectangle, 1, 1, 1, "a")
+
         self.assertEquals(geometry.hollow_rectangle(0, 0, 0, 0), [(0, 0)])
         self.assertCountEqual(geometry.hollow_rectangle(0, 0, 1, 1), [(0, 0), (0, 1), (1, 1), (1, 0)])
         self.assertCountEqual(geometry.hollow_rectangle(1, 1, 0, 0), [(0, 0), (0, 1), (1, 1), (1, 0)])
@@ -174,15 +165,25 @@ class Test(unittest.TestCase):
                                                               (3, 5), (3, 6), (3, 7), (3, 8), (3, 9), (4, 9), (5, 9), (6, 9), (7, 9), (8, 9),
                                                               (8, 3), (6, 3), (4, 3), (5, 3)])
 
-    def test_triangle_errors(self):
+    # # Triangles
 
+
+    def test_triangle(self):
+        """ test for geometry.triangle """
         for cell_shape in (geometry.FLAT_HEX, geometry.SQUARE):
             self.assertRaises(TypeError, geometry.triangle, cell_shape, "a", 1, 1, 1, 1)
             self.assertRaises(TypeError, geometry.triangle, cell_shape, 1, "a", 1, 1, 1)
             self.assertRaises(TypeError, geometry.triangle, cell_shape, 1, 1, "a", 1, 1)
             self.assertRaises(TypeError, geometry.triangle, cell_shape, 1, 1, 1, "a", 1)
             self.assertRaises(ValueError, geometry.triangle, cell_shape, 1, 1, 1, 1, -1)
+        self.assertRaises(ValueError, geometry.triangle, 0, 1, 1, 1, 1, 1)
 
+        for i in geometry.ANGLES:
+            self.assertCountEqual(geometry.triangle(cell_shape, 0, 0, 0, 0, i), [(0, 0)])
+
+    def test_triangle3d(self):
+        """ test for geometry.triangle3d """
+        for cell_shape in (geometry.FLAT_HEX, geometry.SQUARE):
             self.assertRaises(TypeError, geometry.triangle3d, cell_shape, "a", 1, 1, 1, 1, 1, 1)
             self.assertRaises(TypeError, geometry.triangle3d, cell_shape, 1, "a", 1, 1, 1, 1, 1)
             self.assertRaises(TypeError, geometry.triangle3d, cell_shape, 1, 1, "a", 1, 1, 1, 1)
@@ -190,65 +191,41 @@ class Test(unittest.TestCase):
             self.assertRaises(TypeError, geometry.triangle3d, cell_shape, 1, 1, 1, 1, "a", 1, 1)
             self.assertRaises(TypeError, geometry.triangle3d, cell_shape, 1, 1, 1, 1, 1, "a", 1)
             self.assertRaises(ValueError, geometry.triangle3d, cell_shape, 1, 1, 1, 1, 1, 1, -1)
-
-        self.assertRaises(ValueError, geometry.triangle, 0, 1, 1, 1, 1, 1)
         self.assertRaises(ValueError, geometry.triangle3d, 0, 1, 1, 1, 1, 1, 1, 1)
 
     def test_squ2_triangle(self):
-        """test triangle algorithms on square grid"""
+        """ test for geometry.squ2_triangle """
         cell_shape = geometry.SQUARE
-
-        for i in geometry.ANGLES:
-            self.assertCountEqual(geometry.triangle(cell_shape, 0, 0, 0, 0, i), [(0, 0)])
-
         # TODO: check and validate
+
 #         # left to right
-#         self.assertCountEqual(geometry.triangle(cell_shape, 2, 3, 4, 3, 1), [])
-#         self.assertCountEqual(geometry.triangle(cell_shape, 2, 3, 4, 3, 2), [])
-#         self.assertCountEqual(geometry.triangle(cell_shape, 2, 3, 4, 3, 3), [])
+#         # TODO: complete
 #
 #         # top to bottom
-#         self.assertCountEqual(geometry.triangle(cell_shape, 2, 3, 4, 3, 2), [])
-#         self.assertCountEqual(geometry.triangle(cell_shape, 2, 3, 4, 3, 2), [])
-#         self.assertCountEqual(geometry.triangle(cell_shape, 2, 3, 4, 3, 3), [])
+#         # TODO: complete
 #
 #         # right to left
-#         self.assertCountEqual(geometry.triangle(cell_shape, 2, 3, 4, 3, 1), [])
-#         self.assertCountEqual(geometry.triangle(cell_shape, 2, 3, 4, 3, 2), [])
-#         self.assertCountEqual(geometry.triangle(cell_shape, 2, 3, 4, 3, 3), [])
+#         # TODO: complete
 #
 #         # bottom to top
-#         self.assertCountEqual(geometry.triangle(cell_shape, 2, 3, 4, 3, 1), [])
-#         self.assertCountEqual(geometry.triangle(cell_shape, 2, 3, 4, 3, 2), [])
-#         self.assertCountEqual(geometry.triangle(cell_shape, 2, 3, 4, 3, 3), [])
+#         # TODO: complete
 #
 #         # top left to bottom right
-#         self.assertCountEqual(geometry.triangle(cell_shape, 2, 3, 4, 3, 1), [])
-#         self.assertCountEqual(geometry.triangle(cell_shape, 2, 3, 4, 3, 2), [])
-#         self.assertCountEqual(geometry.triangle(cell_shape, 2, 3, 4, 3, 3), [])
+#         # TODO: complete
 #
 #         # bottom right to top left
-#         self.assertCountEqual(geometry.triangle(cell_shape, 2, 3, 4, 3, 1), [])
-#         self.assertCountEqual(geometry.triangle(cell_shape, 2, 3, 4, 3, 2), [])
-#         self.assertCountEqual(geometry.triangle(cell_shape, 2, 3, 4, 3, 3), [])
+#         # TODO: complete
 #
 #         # top right to bottom left
-#         self.assertCountEqual(geometry.triangle(cell_shape, 2, 3, 4, 3, 1), [])
-#         self.assertCountEqual(geometry.triangle(cell_shape, 2, 3, 4, 3, 2), [])
-#         self.assertCountEqual(geometry.triangle(cell_shape, 2, 3, 4, 3, 3), [])
+#         # TODO: complete
 #
 #         # bottom right to top left
-#         self.assertCountEqual(geometry.triangle(cell_shape, 2, 3, 4, 3, 1), [])
-#         self.assertCountEqual(geometry.triangle(cell_shape, 2, 3, 4, 3, 2), [])
-#         self.assertCountEqual(geometry.triangle(cell_shape, 2, 3, 4, 3, 3), [])
-
+#         # TODO: complete
 
 
     def test_fhex2_triangle(self):
-        """test triangle algorithms on hexagonal grid"""
+        """ test for geometry.fhex2_triangle """
         cell_shape = geometry.FLAT_HEX
-        for i in geometry.ANGLES:
-            self.assertCountEqual(geometry.triangle(cell_shape, 0, 0, 0, 0, i), [(0, 0)])
 
         # left to right
         self.assertCountEqual(geometry.triangle(cell_shape, 2, 3, 4, 3, 1), [(3, 3), (3, 4), (3, 3), (4, 5), (4, 4), (4, 3), (4, 2), (4, 1), (4, 1), (3, 1), (3, 2), (2, 3)])
@@ -258,78 +235,96 @@ class Test(unittest.TestCase):
         # TODO: check and validate
 
 #         # top to bottom
-#         self.assertCountEqual(geometry.triangle(cell_shape, 2, 3, 4, 3, 1), [])
-#         self.assertCountEqual(geometry.triangle(cell_shape, 2, 3, 4, 3, 2), [])
-#         self.assertCountEqual(geometry.triangle(cell_shape, 2, 3, 4, 3, 3), [])
-#
+#         # TODO: complete
+
         # right to left
         self.assertCountEqual(geometry.triangle(cell_shape, 4, 3, 2, 3, 1), [(3, 2), (3, 1), (3, 2), (2, 1), (2, 2), (2, 3), (2, 4), (2, 5), (2, 5), (3, 4), (3, 3), (4, 3)])
         self.assertCountEqual(geometry.triangle(cell_shape, 4, 3, 2, 3, 2), [(3, 2), (2, 2), (2, 3), (2, 4), (2, 4), (3, 3), (4, 3)])
         self.assertCountEqual(geometry.triangle(cell_shape, 4, 3, 2, 3, 3), [(3, 2), (2, 2), (2, 3), (2, 4), (2, 4), (3, 3), (4, 3)])
 
 #         # bottom to top
-#         self.assertCountEqual(geometry.triangle(cell_shape, 2, 3, 4, 3, 1), [])
-#         self.assertCountEqual(geometry.triangle(cell_shape, 2, 3, 4, 3, 2), [])
-#         self.assertCountEqual(geometry.triangle(cell_shape, 2, 3, 4, 3, 3), [])
-#
+#         # TODO: complete
+
 #         # top left to bottom right
-#         self.assertCountEqual(geometry.triangle(cell_shape, 2, 3, 4, 3, 1), [])
-#         self.assertCountEqual(geometry.triangle(cell_shape, 2, 3, 4, 3, 2), [])
-#         self.assertCountEqual(geometry.triangle(cell_shape, 2, 3, 4, 3, 3), [])
-#
+#         # TODO: complete
+
 #         # bottom right to top left
-#         self.assertCountEqual(geometry.triangle(cell_shape, 2, 3, 4, 3, 1), [])
-#         self.assertCountEqual(geometry.triangle(cell_shape, 2, 3, 4, 3, 2), [])
-#         self.assertCountEqual(geometry.triangle(cell_shape, 2, 3, 4, 3, 3), [])
-#
+#         # TODO: complete
+
 #         # top right to bottom left
-#         self.assertCountEqual(geometry.triangle(cell_shape, 2, 3, 4, 3, 1), [])
-#         self.assertCountEqual(geometry.triangle(cell_shape, 2, 3, 4, 3, 2), [])
-#         self.assertCountEqual(geometry.triangle(cell_shape, 2, 3, 4, 3, 3), [])
-#
-#         # bottom right to top left
-#         self.assertCountEqual(geometry.triangle(cell_shape, 2, 3, 4, 3, 1), [])
-#         self.assertCountEqual(geometry.triangle(cell_shape, 2, 3, 4, 3, 2), [])
-#         self.assertCountEqual(geometry.triangle(cell_shape, 2, 3, 4, 3, 3), [])
+#         # TODO: complete
 
+#         # bottom right to top left
+#         # TODO: complete
 
 
     def test_squ3_triangle(self):
-        """test triangle3d algorithms on square grid"""
+        """ test for geometry.squ3_triangle """
         cell_shape = geometry.SQUARE
         # TODO: complete
 
     def test_fhex3_triangle(self):
-        """test triangle3d algorithms on hexagonal grid"""
+        """ test for geometry.fhex3_triangle """
         cell_shape = geometry.FLAT_HEX
         # TODO: complete
 
-    def test_zone(self):
-        """test the errors due to bad parameters"""
-        self.assertRaises(TypeError, geometry.zone, 5, 0, 0, "a")
-        self.assertRaises(TypeError, geometry.zone, 5, "a", 0, 1)
-        self.assertRaises(TypeError, geometry.zone, 5, 0, "a", 1)
-        self.assertRaises(ValueError, geometry.zone, 5, 0, 0, -1)
-        self.assertRaises(ValueError, geometry.zone, -1, 0, 0, 1)
-        self.assertRaises(ValueError, geometry.zone, "a", 0, 0, 1)
 
-    def test_hex_zone(self):
-        """ test the zone algo for hexagonal grid """
-        cell_shape = geometry.FLAT_HEX
-        self.assertCountEqual(geometry.zone(cell_shape, 3, 3, 0), [(3, 3)])
-        self.assertCountEqual(geometry.zone(cell_shape, 3, 3, 1), [(3, 2), (2, 3), (3, 3), (4, 3), (4, 4), (3, 4), (2, 4)])
-        self.assertCountEqual(geometry.zone(cell_shape, 3, 3, 2), [(3, 2), (1, 3), (5, 4), (4, 5), (1, 4), (2, 3), (4, 2), \
-                                                            (2, 5), (5, 3), (1, 2), (3, 5), (3, 3), (4, 4), (3, 1), \
-                                                            (4, 3), (2, 2), (3, 4), (2, 4), (5, 2)])
+    # # Translations, rotations
+    def test_pivot(self):
+        """ test for geometry.pivot """
+        self.assertRaises(ValueError, geometry.pivot, 0, (0, 0), [(0, 0)], 1)
 
-    def test_squ_zone(self):
-        """ test the zone algo for square grid """
-        cell_shape = geometry.SQUARE
-        self.assertCountEqual(geometry.zone(cell_shape, 3, 3, 0), [(3, 3)])
-        self.assertCountEqual(geometry.zone(cell_shape, 3, 3, 1), [(3, 2), (3, 3), (4, 4), (2, 3), (4, 3), (2, 2), (4, 2), (3, 4), (2, 4)])
-        self.assertCountEqual(geometry.zone(cell_shape, 3, 3, 2), [(2, 4), (3, 2), (5, 4), (1, 3), (4, 5), (2, 1), (1, 4), (2, 3), (4, 2), \
-                                                                    (5, 1), (2, 5), (3, 5), (5, 3), (1, 2), (3, 3), (5, 5), (4, 4), (3, 1), \
-                                                                    (1, 5), (4, 3), (2, 2), (4, 1), (5, 2), (3, 4), (1, 1)])
+        self.assertRaises(TypeError, geometry.pivot, 0, "a"    , [(0, 0)], 1)
+        self.assertRaises(ValueError, geometry.pivot, 0, ("a", 0), [(0, 0)], 1)
+
+        self.assertRaises(TypeError, geometry.pivot, 0, (0, 0), 0, 1)
+        self.assertRaises(ValueError, geometry.pivot, 0, (0, 0), ["a", (0, 0)], 1)
+        self.assertRaises(ValueError, geometry.pivot, 0, (0, 0), [("a", 0), (0, 0)], 1)
+
+        self.assertRaises(TypeError, geometry.pivot, 0, (0, 0), 1, "a")
+
+    def test_fhex2_pivot(self):
+        """ test for geometry.fhex2_pivot """
+        attended = [
+                    [(5, 5), (4, 5), (6, 6)],
+                    [(5, 6), (4, 7), (6, 6)],
+                    [(6, 7), (6, 8), (6, 6)],
+                    [(7, 6), (8, 7), (6, 6)],
+                    [(7, 5), (8, 5), (6, 6)],
+                    [(6, 5), (6, 4), (6, 6)],
+                    [(5, 5), (4, 5), (6, 6)]
+                   ]
+
+
+        for i in range(len(attended)):
+            self.assertCountEqual(geometry.pivot(geometry.FLAT_HEX, (6, 6), [(6, 6)], i), [(6, 6)])
+            result = geometry.pivot(geometry.FLAT_HEX, (6, 6), [(5, 5), (4, 5), (6, 6)], i)
+            self.assertCountEqual(result, attended[i])
+
+    def test_squ2_pivot(self):
+        """ test for geometry.squ2_pivot """
+        attended = [
+                    [(6, 6), (6, 5), (5, 5), (5, 6)],
+                    [(6, 6), (5, 6), (5, 7), (6, 7)],
+                    [(6, 6), (6, 7), (7, 7), (7, 6)],
+                    [(6, 6), (7, 6), (7, 5), (6, 5)],
+                    [(6, 6), (6, 5), (5, 5), (5, 6)]
+                   ]
+
+        for i in range(len(attended)):
+            self.assertCountEqual(geometry.pivot(geometry.SQUARE, (6, 6), [(6, 6)], i), [(6, 6)])
+            result = geometry.pivot(geometry.SQUARE, (6, 6), [(6, 6), (6, 5), (5, 5), (5, 6)], i)
+            self.assertCountEqual(result, attended[i])
+
+
+    # # cubic coordinates
+    def test_cv_cube_off(self):
+        """ test for geometry.cv_cube_off """
+        pass
+
+    def test_cv_off_cube(self):
+        """ test for geometry.cv_off_cube """
+        pass
 
 if __name__ == "__main__":
     unittest.main()