def _factor_from_algorithm(self, cell: Tuple[int, int], fac_algo: Factor) -> None: """Helper for factor actions. Args: cell (Tuple[int, int]): The clicked cell. fac_algo (Factor): The facorize algorithm to use. """ components = fac_algo.get_components() facs = fac_algo.factors() for fac, component in zip(facs, components): if cell in component: self._add_tiling(fac) break
def test_reducible_factorisations(): t = Tiling(obstructions=[ GriddedPerm((0, 1), ((0, 0), ) * 2), GriddedPerm((0, 1), ((1, 1), ) * 2), GriddedPerm((0, 1), ((2, 2), ) * 2), ]) fo = Factor(t) f1 = Tiling(obstructions=[ GriddedPerm((0, 1), ((0, 0), ) * 2), GriddedPerm((0, 1), ((1, 1), ) * 2), ]) f2 = Tiling(obstructions=[GriddedPerm((0, 1), ((0, 0), ) * 2)]) assert set([f1, f2]) in map(set, fo.reducible_factorisations()) assert [f2, f2, f2] not in fo.reducible_factorisations()
def test_factorable(factor1, factor2, not_fact_tiling): assert factor1.factorable() assert factor2.factorable() empty_tiling = Tiling() assert not Factor(empty_tiling).factorable() point_tiling = Tiling( obstructions=[ GriddedPerm((0, 1), ((0, 0), (0, 0))), GriddedPerm((1, 0), ((0, 0), (0, 0))), ], requirements=[[GriddedPerm((0, ), ((0, 0), ))]], ) assert not Factor(point_tiling).factorable() assert not Factor(not_fact_tiling).factorable()
def _factor(self, x: int, y: int, _button: int, _modifiers: int) -> None: """Factor the clicked cell. Args: x (int): The x coordinate of the mouse click. y (int): The y coordinate of the mouse click. _button (int): The mouse button clicked. Unused. _modifiers (int): If combinded with modifiers (e.g. ctrl). Unused. """ tplot = self._current() self._factor_from_algorithm(tplot.get_cell(Point(x, y)), Factor(tplot.tiling))
def __call__(self, comb_class: Tiling) -> Iterator[VerificationRule]: assert self.perms_to_check is not None, "perms_to_check was never set" # It is a waste of time to check a factorable tiling, since we will check its # children eventually. if Factor(comb_class).factorable(): return algo = SubclassVerificationAlgorithm(comb_class, self.perms_to_check) if algo.subclasses: yield SubclassVerificationStrategy(algo.subclasses)(comb_class, tuple())
def test_factors(tplaced_tracked, tplaced_tracked_factored1, tplaced_tracked_factored2): assert len(tplaced_tracked_factored1.assumptions) == 2 assert all( isinstance(ass, TrackingAssumption) for ass in tplaced_tracked_factored1.assumptions) assert tplaced_tracked_factored1.assumptions[0].gps == ( GriddedPerm.single_cell((0, ), (0, 0)), ) assert tplaced_tracked_factored1.assumptions[1].gps == ( GriddedPerm.single_cell((0, ), (1, 0)), ) assert set(Factor(tplaced_tracked).factors()) == set( [tplaced_tracked_factored1, tplaced_tracked_factored2])
def test_get_components(factor1, factor2): comp1 = {(1, 1), (1, 2), (2, 2)} comp2 = {(0, 0), (3, 0)} assert comp1 in factor1.get_components() assert comp2 in factor1.get_components() assert len(factor1.get_components()) == 2 comp1 = {(0, 0), (0, 1), (1, 0), (1, 1)} comp2 = {(2, 2), (3, 2), (4, 2), (2, 3), (3, 3), (4, 3)} assert comp1 in factor2.get_components() assert comp2 in factor2.get_components() assert len(factor1.get_components()) == 2 empty_tiling = Tiling() assert Factor(empty_tiling).get_components() == tuple() point_tiling = Tiling( obstructions=[ GriddedPerm((0, 1), ((0, 0), (0, 0))), GriddedPerm((1, 0), ((0, 0), (0, 0))), ], requirements=[[GriddedPerm((0, ), ((0, 0), ))]], ) assert Factor(point_tiling).get_components() == ({(0, 0)}, )
def factor2(tiling2): return Factor(tiling2)
def factor1(tiling1): return Factor(tiling1)
def test_init(tiling1): f = Factor(tiling1) assert f._tiling == tiling1 assert f._active_cells == frozenset([(0, 0), (1, 1), (2, 2), (1, 2), (3, 0)]) assert isinstance(f._cell_unionfind, UnionFind)