From 382e2be48ae8f3914bb443f27f5091c730095e6c Mon Sep 17 00:00:00 2001 From: Antonio Ospite Date: Wed, 27 Jun 2018 20:19:10 +0200 Subject: [PATCH] tetraflexagon_diagram: add a function to calculate the tile offset in a square --- src/flexagon/tetraflexagon_diagram.py | 5 ++--- src/flexagon/tritetraflexagon.py | 6 ++++++ 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/flexagon/tetraflexagon_diagram.py b/src/flexagon/tetraflexagon_diagram.py index 5d810de..ab3da17 100755 --- a/src/flexagon/tetraflexagon_diagram.py +++ b/src/flexagon/tetraflexagon_diagram.py @@ -54,9 +54,8 @@ class TetraflexagonDiagram(object): for tile in square.tiles: # offset by 1 or -1 times the tile radius - tile_cx = cx + self.tile_radius * ((tile.index % 2) * 2 - 1) - tile_cy = cy + self.tile_radius * ((tile.index > 1) * 2 - 1) - self.tiles_centers[square.index][tile.index] = (tile_cx, tile_cy) + tile_xoffset, tile_yoffset = tile.calc_offset_in_square(self.tile_side) + self.tiles_centers[square.index][tile.index] = (cx + tile_xoffset, cy + tile_yoffset) def get_square_center(self, square): return self.squares_centers[square.index] diff --git a/src/flexagon/tritetraflexagon.py b/src/flexagon/tritetraflexagon.py index 8a70069..767d42f 100755 --- a/src/flexagon/tritetraflexagon.py +++ b/src/flexagon/tritetraflexagon.py @@ -25,6 +25,12 @@ class Tile(object): self.square = square self.index = index + def calc_offset_in_square(self, side): + xoffset = side / 2 * ((self.index % 2) * 2 - 1) + yoffset = side / 2 * ((self.index > 1) * 2 - 1) + + return xoffset, yoffset + @staticmethod def calc_plan_coordinates(side, i, j): xoffset = side / 2 + j * side -- 2.1.4