def case_assert(cls, c_x: Case, c_y: Case, color=False):
     # color
     if color:
         color_x = c_x.color_count()
         color_y = c_y.color_count()
         flag_color = True
         for color_ in range(10):
             if color_ == c_x.background_color:
                 continue
             if color_x[color_] != color_y[color_] != 0:
                 flag_color = False
         if flag_color:
             return True, True
     # simply keep
     y_values = c_y.repr_values()
     if c_x.shape == c_y.shape:
         for m in c_x.matter_list:
             if (m.values == y_values[m.x0:m.x0 + m.shape[0],
                                      m.y0:m.y0 + m.shape[1]]).min():
                 pass
             elif (c_x.background_color == y_values[m.x0:m.x0 + m.shape[0],
                                                    m.y0:m.y0 +
                                                    m.shape[1]]).min():
                 pass
             else:
                 return False, False
         return True, False
     return False, False
 def case_row_col(cls, c: Case) -> Case:
     new_case = c.copy()
     new_values = cls.auto_fill_row_col(c.repr_values(), c.background_color)
     new_case.matter_list = [
         Matter(new_values, background_color=c.background_color, new=True)
     ]
     return new_case
Example #3
0
    def case(cls, c: Case) -> Case:

        res_arr = c.repr_fractal_values()

        new_case: Case = c.copy()
        new_case.shape = res_arr.shape
        new_case.matter_list = [Matter(res_arr, background_color=c.background_color, new=True)]
        return new_case
Example #4
0
 def case(cls, c: Case) -> Case:
     new_case: Case = c.copy()
     new_background = c.max_color()
     m: Matter
     new_case.matter_list = [
         cls.matter(m, new_background) for m in c.matter_list
     ]
     new_case.background_color = new_background
     return new_case
 def case(cls, c_x: Case, pattern_arr: np.array) -> Case:
     x_values = c_x.repr_values()
     if c_x.color_delete is None:
         new_x_values = cls.array(x_values, pattern_arr,
                                  c_x.background_color)
     else:
         new_x_values = cls.array(x_values, pattern_arr, c_x.color_delete)
     new_case: Case = c_x.copy()
     new_case.matter_list = [Matter(new_x_values, new=True)]
     return new_case
Example #6
0
 def case_col(cls, c: Case) -> Case:
     new_case = c.copy()
     if c.color_delete is None:
         new_values = cls.auto_fill_symmetry_col_background(c.repr_values())
     else:
         new_values = cls.auto_fill_symmetry_col(c.repr_values(),
                                                 c.color_delete)
     new_case.matter_list = [
         Matter(new_values, background_color=c.background_color, new=True)
     ]
     return new_case
Example #7
0
 def case(cls, c: Case) -> Case:
     new_case = c.copy()
     m: Matter
     if c.color_add is not None:
         color_add = c.color_add
     else:
         color_add = c.max_color()
     new_case.matter_list = [
         cls.matter(m, color_add) for m in c.matter_list
     ]
     return new_case
Example #8
0
 def case(cls, c: Case, full) -> Case:
     assert c.shape[0] > 2 and c.shape[1] > 2
     new_case = c.copy()
     if c.color_delete is None:
         new_values = cls.array(c.repr_values(), c.background_color, full)
     else:
         new_values = cls.array(c.repr_values(), c.color_delete, full)
     new_case.matter_list = [
         Matter(new_values, background_color=c.background_color, new=True)
     ]
     return new_case
Example #9
0
 def case(cls, c: Case) -> Case:
     if c.color_delete is not None:
         new_case = c.copy()
         new_values = fill_somewhere(c.repr_values(), c.color_delete)
         new_case.matter_list = [
             Matter(new_values,
                    background_color=c.background_color,
                    new=True)
         ]
         return new_case
     else:
         return c
Example #10
0
 def case_xy(cls, c_x: Case, c_y: Case) -> dict:
     temp_c_x = c_x.copy()
     temp_c_x.matter_list = [cls.matter_temp(m) for m in c_x.matter_list]
     x_repr = temp_c_x.repr_values()
     y_repr = c_y.repr_values()
     assert x_repr.shape == y_repr.shape
     res_dict = dict()
     for v in np.unique(x_repr):
         if v >= 10:
             new_w = np.unique(y_repr[x_repr == v])
             # print(x_repr, y_repr, new_w)
             assert new_w.shape[0] == 1
             res_dict[v - 10] = new_w[0]
     return res_dict
 def case_m(cls, c: Case, m_row, m_col) -> Case:
     new_case: Case = c.copy()
     new_case.matter_list = [
         cls.matter(m, m_row, m_col) for m in c.matter_list
     ]
     new_case.shape = c.shape[0] * m_row, c.shape[1] * m_col
     return new_case
 def case(cls, c: Case, full: bool) -> Case:
     new_case: Case = c.copy()
     m: Matter
     new_case.matter_list = [
         m if m.is_mesh else cls.matter(m, full) for m in c.matter_list
     ]
     return new_case
 def case(cls, c: Case, hole_type: str) -> Case:
     new_case: Case = c.copy()
     m: Matter
     new_case.matter_list = [
         cls.matter(m, hole_type) for m in c.matter_list
     ]
     return new_case
Example #14
0
 def case(cls, c: Case, allow_diagonal: bool, boundary_none: bool) -> Case:
     assert len(c.matter_list) == 1
     new_case = c.copy()
     new_case.matter_list = cls.matter(c.matter_list[0], allow_diagonal,
                                       c.background_color, boundary_none)
     # print(len(new_case.matter_list))
     return new_case
 def case(cls, c: Case) -> Case:
     assert c.color_add is not None
     new_case: Case = c.copy()
     new_case.matter_list = [
         cls.matter(m, c.color_add) for m in c.matter_list
     ]
     return new_case
Example #16
0
 def case(cls, c: Case) -> Case:
     m: Matter
     new_case = c.copy()
     new_case.matter_list = [
         m if m.is_mesh else cls.matter(m) for m in c.matter_list
     ]
     return new_case
 def case_fit(cls, c: Case, ca: AbstractCase):
     new_case: Case = c.copy()
     new_case.matter_list = []
     for m, y in zip(c.matter_list, ca.y_list):
         if y:
             new_case.matter_list.append(m.deepcopy())
     return new_case
Example #18
0
    def case(cls, c: Case) -> Case:
        m: Matter
        x0_arr = np.array([m.x0 for m in c.matter_list if not m.is_mesh])
        y0_arr = np.array([m.y0 for m in c.matter_list if not m.is_mesh])
        x1_arr = np.array([m.x0 + m.shape[0] for m in c.matter_list if not m.is_mesh])
        y1_arr = np.array([m.y0 + m.shape[1] for m in c.matter_list if not m.is_mesh])

        non_mesh_list = [m for m in c.matter_list if not m.is_mesh]
        c_arr = np.arange(len(non_mesh_list))

        # same shape
        assert len(non_mesh_list) >= 2
        assert len({m.shape[0] for m in non_mesh_list}) == 1
        assert len({m.shape[1] for m in non_mesh_list}) == 1
        matter_shape = non_mesh_list[0].shape

        res_arr = align_xy(x0_arr, y0_arr, x1_arr, y1_arr, c_arr)

        new_case: Case = c.copy()
        new_case.shape = res_arr.shape[0] * matter_shape[0], res_arr.shape[1] * matter_shape[1]
        new_case.matter_list = []
        for i in range(res_arr.shape[0]):
            for j in range(res_arr.shape[1]):
                m = non_mesh_list[res_arr[i, j]]
                m_add = m.deepcopy()
                m_add.x0 = i * matter_shape[0]
                m_add.y0 = j * matter_shape[1]
                new_case.matter_list.append(m_add)
        return new_case
def set_color_add(c: Case, color_add: int) -> Case:
    new_case = c.copy()
    new_case.matter_list = [
        attr_mat.set_color_add(m, color_add) for m in c.matter_list
    ]
    new_case.color_add = color_add
    return new_case
def set_shape(c: Case, new_shape: Tuple[int, int]) -> Case:
    assert new_shape[0] >= c.shape[0]
    assert new_shape[1] >= c.shape[1]
    new_case = c.copy()
    new_case.matter_list = c.matter_list[:]
    new_case.n_row, new_case.col = new_shape
    return new_case
 def case(cls, c: Case, op: str, const: int) -> Case:
     assert c.color_add is not None
     new_case: Case = c.copy()
     m: Matter
     new_case.matter_list = [
         cls.matter(m, op, const, c.color_add) for m in c.matter_list
     ]
     return new_case
 def case(cls, c: Case, allow_diagonal: bool) -> Case:
     assert len(c.matter_list) == 1
     new_case = c.copy()
     new_case.matter_list = cls.matter(c.matter_list[0], allow_diagonal)
     # a <- n_cell by default
     for m in new_case.matter_list:
         m.a = m.n_cell()
     return new_case
Example #23
0
 def case(cls, c: Case) -> Case:
     m: Matter
     new_case = c.copy()
     new_case.matter_list = [m.deepcopy() for m in c.matter_list]
     for m in new_case.matter_list:
         m.a = m.n_color()
     new_case.matter_list = list(sorted(new_case.matter_list, key=lambda x: -x.a))
     return new_case
 def case(cls, c: Case) -> Case:
     assert len(c.matter_list) == 1
     new_case: Case = c.copy()
     new_matter, m_row, m_col = cls.matter(c.matter_list[0], c.shape[0],
                                           c.shape[1])
     new_case.matter_list = [new_matter]
     new_case.shape = c.shape[0] * m_row, c.shape[1] * m_col
     return new_case
 def case_x(cls, c_x: Case, x0: int, x1: int, y0: int, y1: int) -> Case:
     new_case_x = c_x.copy()
     new_case_x.matter_list = [cls.matter_x(m_x) for m_x in c_x.matter_list]
     new_case_x.display_x0 = x0
     new_case_x.display_x1 = x1
     new_case_x.display_y0 = y0
     new_case_x.display_y1 = y1
     return new_case_x
Example #26
0
def hand_pick_case(c: Case, ind: int) -> Case:
    new_case: Case = c.copy()
    new_matter: Matter = c.matter_list[ind % len(c.matter_list)].deepcopy()
    new_matter.x0 = 0
    new_matter.y0 = 0
    new_case.matter_list = [new_matter]
    new_case.shape = new_matter.shape
    return new_case
Example #27
0
 def case_assert(cls, c_x: Case, c_y: Case):
     assert len(c_x.matter_list) > 1
     res_values = c_y.repr_values()
     for m in c_x.matter_list:
         if m.shape == res_values.shape:
             if (m.values == res_values).min():
                 return True
     return False
def point_cross_fit_case(c: Case, op_arr: np.array) -> Case:

    new_case: Case = c.copy()
    new_case.matter_list = [
        point_cross_fit_mat(m, c.shape[0], c.shape[1], op_arr)
        for m in c.matter_list
    ]

    return new_case
 def case(cls, c: Case) -> Case:
     m: Matter
     new_case = c.copy()
     new_case.matter_list = [m.deepcopy() for m in c.matter_list]
     for m in new_case.matter_list:
         if m.a is None:
             pass
         else:
             m.a = m.a % 2
     return new_case
 def case_y(cls, c_y: Case, new_y_arr, x0: int, x1: int, y0: int,
            y1: int) -> Case:
     new_case_y = c_y.copy()
     new_case_y.matter_list = [cls.matter_y(c_y.matter_list[0], new_y_arr)]
     new_case_y.shape = new_y_arr.shape
     new_case_y.display_x0 = x0
     new_case_y.display_x1 = x1
     new_case_y.display_y0 = y0
     new_case_y.display_y1 = y1
     return new_case_y