How to use the permuta.mesh_pattern.MeshPattern function in permuta

To help you get started, we’ve selected a few permuta examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github PermutaTriangle / Permuta / permuta / mesh_pattern.py View on Github external
nshading.add((na, nb))

        if shade_dir == DIR_EAST:
            nshading.add((x+1, y))
            nshading.add((x+1, y+1))
        elif shade_dir == DIR_NORTH:
            nshading.add((x, y+1))
            nshading.add((x+1, y+1))
        elif shade_dir == DIR_WEST:
            nshading.add((x, y))
            nshading.add((x, y+1))
        elif shade_dir == DIR_SOUTH:
            nshading.add((x, y))
            nshading.add((x+1, y))

        return MeshPattern(Permutation(list(nperm)), nshading)
github PermutaTriangle / Permuta / permuta / mesh_patterns.py View on Github external
def gen(p, x, y, s):
            if x == self.n+1:
                for r in gen(p, 0, y+1, s):
                    yield r
            elif y == self.n+1:
                yield MeshPattern(p, s)
            else:
                for r in gen(p, x+1, y, s):
                    yield r
                for r in gen(p, x+1, y, s + [(x, y)]):
                    yield r
github PermutaTriangle / Permuta / permuta / mesh_pattern.py View on Github external
def _rotate_right(self):
        """Return self rotated 90 degrees to the right."""
        return MeshPattern(self.pattern.rotate(),
                           set([_rotate_right(len(self.pattern), coordinate)
                                for coordinate in self.shading]))
github PermutaTriangle / Permuta / permuta / mesh_pattern.py View on Github external
def _rotate_left(self):
        """Return self rotated 90 degrees to the left."""
        return MeshPattern(self.pattern.rotate(3),
                           set([_rotate_left(len(self.pattern), coordinate)
                                for coordinate in self.shading]))
github PermutaTriangle / Permuta / permuta / mesh_pattern.py View on Github external
def complement(self):
        # TODO: Docstring, tests
        return MeshPattern(self.pattern.complement(),
                           [(x, len(self.pattern)-y) for (x, y) in self.shading])
github PermutaTriangle / Permuta / permuta / mesh_pattern.py View on Github external
def _rotate_180(self):
        """Return self rotated 180 degrees."""
        return MeshPattern(self.pattern.rotate(2),
                           set([_rotate_180(len(self.pattern), coordinate)
                                for coordinate in self.shading]))
github PermutaTriangle / Permuta / permuta / mesh_pattern.py View on Github external
def __new__(cls, pattern=Permutation(), shading=frozenset(), check=False):
        # TODO: Tests, took into having shading be a sorted tuple of coordinates
        if not isinstance(pattern, Permutation):
            pattern = Permutation(pattern, check=check)
        if not isinstance(shading, frozenset):
            shading = frozenset(shading)
        return super(MeshPattern, cls).__new__(cls, pattern, shading)
github PermutaTriangle / Permuta / permuta / mesh_pattern.py View on Github external
"""Return the mesh pattern induced by indices.

        Args:
            self:
                A mesh pattern.
            indices:  of 
                A list of unique indices of elements in self.

        Returns: permuta.MeshPattern
            A mesh pattern where the pattern is the permutation induced by the
            indices and a region is shaded if and only if the corresponding
            region of self is fully shaded.
        """
        indices = sorted(indices)
        if not indices:
            return MeshPattern()
        pattern = Permutation.to_standard(self.pattern[index] for index in indices)
        vertical = [0]
        vertical.extend(index + 1 for index in indices)
        vertical.append(len(self) + 1)
        horizontal = [0]
        horizontal.extend(sorted(self.pattern[index] for index in indices))
        horizontal.append(len(self) + 1)
        shading = frozenset((x, y)
                            for x in range(len(pattern) + 1)
                            for y in range(len(pattern) + 1)
                            if self.is_shaded((vertical[x],
                                               horizontal[y]),
                                              (vertical[x+1] - 1,
                                               horizontal[y+1] - 1)))
        return MeshPattern(pattern, shading)