X-Git-Url: https://git.ao2.it/flexagon-toolkit.git/blobdiff_plain/23f35964b301e77eaa007aa75fe9f768f2761a5c..refs/heads/master:/src/flexagon/hexaflexagon_diagram.py?ds=sidebyside diff --git a/src/flexagon/hexaflexagon_diagram.py b/src/flexagon/hexaflexagon_diagram.py index 4bb029b..7b09c94 100755 --- a/src/flexagon/hexaflexagon_diagram.py +++ b/src/flexagon/hexaflexagon_diagram.py @@ -43,6 +43,10 @@ class HexaflexagonDiagram(object): self.plan_origin = (self.x_border * 2. + self.hexagon_radius / 2., self.x_border + self.triangle_radius / 3.) + # The offset of the backfaces relative to the first hexagon + self.backfaces_offsets = (0, + (self.hexagon_radius + self.x_border) * 2) + self.hexagons_color_map = [(1, 0, 0), (0, 1, 0), (0, 0, 1)] def _init_centers(self): @@ -66,6 +70,15 @@ class HexaflexagonDiagram(object): def get_triangle_center(self, triangle): return self.triangles_centers[triangle.hexagon.index][triangle.index] + def get_triangle_center_in_backfaces(self, triangle): + """Get the center of this triangle but in the backface""" + x0, y0 = self.backfaces_offsets + + backface_triangle_index = triangle.get_backface_index() + x, y = self.triangles_centers[triangle.hexagon.index][backface_triangle_index] + + return x0 + x, y0 + y + def get_triangle_center_in_plan(self, triangle): x0, y0 = self.plan_origin i, j = self.hexaflexagon.get_triangle_plan_position(triangle) @@ -91,6 +104,18 @@ class HexaflexagonDiagram(object): return self.backend.calc_rotate_translate_transform(src_x, src_y, dest_x, dest_y, theta) + def get_triangle_backfaces_transform(self, triangle): + """Calculate the transformation matrix from a triangle in an hexagon to + the correspondent triangle in a backface. + + Return the matrix as a list of values sorted in row-major order.""" + src_x, src_y = self.get_triangle_center(triangle) + dest_x, dest_y = self.get_triangle_center_in_backfaces(triangle) + theta = triangle.get_angle_in_backface_relative_to_hexagon() + + return self.backend.calc_rotate_translate_transform(src_x, src_y, + dest_x, dest_y, theta) + def draw_hexagon_template(self, hexagon): for triangle in hexagon.triangles: cx, cy = self.get_triangle_center(triangle)