def matter(cls, m: Matter) -> Matter: assert m.n_color() <= 2 if m.is_mesh: return m elif m.n_color() == 0: return m elif m.n_color() == 1: color_count = m.color_count() for c in range(10): if color_count[c] > 0 and c != m.background_color: base_color = c new_matter: Matter = m.copy() new_values = m.background_color * np.ones(m.shape, dtype=np.int) new_values[m.values == m.background_color] = base_color new_matter.set_values(new_values) return new_matter else: # m.n_color() == 2 color_count = m.color_count() switch = [] for c in range(10): if color_count[c] > 0 and c != m.background_color: switch.append(c) new_matter: Matter = m.copy() new_values = m.background_color * np.ones(m.shape, dtype=np.int) new_values[m.values == switch[0]] = switch[1] new_values[m.values == switch[1]] = switch[0] new_matter.set_values(new_values) return new_matter
def matter(cls, m: Matter) -> Matter: new_matter: Matter = m.copy() new_values = m.background_color * np.ones(m.shape, dtype=np.int) keep_color = m.max_color() new_values[m.values == keep_color] = keep_color new_matter.set_values(new_values) return new_matter
def matter(cls, m: Matter, n_row, n_col): assert m.a is not None assert m.a > 0 if m.b is None: assert max(m.a * n_row, m.a * n_col) <= 30 new_matter: Matter = m.copy() new_matter.set_values(duplicate_array(m.values, m.a, m.a)) new_matter.x0 = 0 new_matter.y0 = 0 return new_matter, m.a, m.a else: assert m.b > 0 assert max(m.a * n_row, m.b * n_col) <= 30 new_matter: Matter = m.copy() new_matter.set_values(duplicate_array(m.values, m.a, m.b)) new_matter.x0 = 0 new_matter.y0 = 0 return new_matter, m.a, m.b
def matter(cls, m: Matter, color_add: int) -> Matter: res_bool = cls.array(m.values) new_values = m.values.copy() new_values[res_bool] = color_add new_m: Matter = m.copy() new_m.set_values(new_values) return new_m
def matter(cls, m: Matter, hole_type: str) -> Matter: if m.is_filled_rectangle() and min(m.shape) >= 3: new_matter = m.copy() new_values = m.values.copy() if hole_type == "simple": new_values[1:-1, 1:-1] = m.background_color elif hole_type == "mesh": new_values[1:-1:2, 1:-1:2] = m.background_color elif hole_type == "mesh_x": new_values[1:-1:2, 1:-1:2] = m.background_color new_values[2:-1:2, 2:-1:2] = m.background_color else: raise NotImplementedError new_matter.set_values(new_values) return new_matter else: return m
def point_cross_fit_mat(m: Matter, n_row, n_col, op_arr: np.array) -> Matter: assert m.n_color() == 1 color_cnt = m.color_count() color_cnt[m.background_color] = 0 m_color = [c for c in range(10) if color_cnt[c] > 0][0] x_arr = np.zeros((n_row, n_col), dtype=np.int) x_arr[m.x0:m.x0 + m.shape[0], m.y0:m.y0 + m.shape[1]] = m.values res_arr = point_cross_fit_arr(x_arr, m_color, op_arr[m_color]) new_values = np.zeros(x_arr.shape, dtype=int) new_values[res_arr == 1] = m_color new_values[res_arr == 0] = m.background_color new_matter = m.copy() new_matter.set_values(new_values) new_matter.x0 = 0 new_matter.y0 = 0 return new_matter
def matter(cls, m: Matter, color_add: int) -> Matter: new_matter: Matter = m.copy() new_values = m.values.copy() new_values[new_values == m.background_color] = color_add new_matter.set_values(new_values) return new_matter
def matter(cls, m: Matter, new_background: np.int) -> Matter: new_matter: Matter = m.copy() new_matter.background_color = new_background new_values = m.values.copy() new_matter.set_values(new_values) return new_matter
def matter(cls, m: Matter) -> Matter: new_values = connect_col(m.values, m.background_color) new_matter: Matter = m.copy() new_matter.set_values(new_values) return new_matter
def rot_270(m: Matter) -> Matter: assert m.is_square() new_matter: Matter = m.copy() new_matter.set_values(array.rot_270(m.values)) return new_matter
def transpose(m: Matter) -> Matter: assert m.is_square() new_matter: Matter = m.copy() new_matter.set_values(array.transpose(m.values)) return new_matter
def rot_180(m: Matter) -> Matter: new_matter: Matter = m.copy() new_matter.set_values(array.rot_180(m.values)) return new_matter
def rev_col(m: Matter) -> Matter: new_matter: Matter = m.copy() new_matter.set_values(array.rev_col(m.values)) return new_matter
def matter_y(cls, m_y: Matter, y_arr: np.array) -> Matter: new_matter_y = m_y.copy() new_matter_y.set_values(y_arr) return new_matter_y
def matter(cls, m: Matter, m_row, m_col) -> Matter: new_matter: Matter = m.copy() new_matter.set_values(zoom_array(m.values, m_row, m_col)) new_matter.x0 = m.x0 * m_row new_matter.y0 = m.y0 * m_col return new_matter