Shape

Struct Shape 

Source
pub struct Shape {
    pub orow: usize,
    pub ocol: usize,
    pub colour: Colour,
    pub cells: Matrix<Cell>,
}

Fields§

§orow: usize§ocol: usize§colour: Colour§cells: Matrix<Cell>

Implementations§

Source§

impl Shape

Source

pub fn new(orow: usize, ocol: usize, cells: &Matrix<Cell>) -> Self

Source

pub fn new_cells(cells: &Matrix<Cell>) -> Self

Source

pub fn new_sized_coloured(rows: usize, cols: usize, colour: Colour) -> Self

Source

pub fn new_sized_coloured_position( orow: usize, ocol: usize, row: usize, col: usize, colour: Colour, ) -> Self

Source

pub fn new_empty() -> Self

Source

pub fn trivial() -> Self

Source

pub fn new9(&self, corners: bool, colour: Colour) -> Self

Source

pub fn is_full(&self) -> bool

Source

pub fn corners(&self) -> (usize, usize, usize, usize)

Source

pub fn same_patch(&self, other: &Self) -> bool

Source

pub fn fill(&self, other: &Self) -> Self

Source

pub fn make_symmetric(&self) -> Self

Source

pub fn col_symmetric_mut(&self, shapes: &mut Shapes)

Source

pub fn new_square(r: usize, c: usize, size: usize, colour: Colour) -> Self

Source

pub fn is_trivial(&self) -> bool

Source

pub fn remove(&mut self, c: &Cell)

Source

pub fn to_shapes(&self) -> Shapes

Source

pub fn to_shapes_coloured(&self) -> Shapes

Source

pub fn to_shapes_base(&self, coloured: bool) -> Shapes

Source

pub fn pixels_in_shape(&self) -> usize

Source

pub fn shrink_any(&self, coloured: bool) -> Self

Source

pub fn remove_border(&self) -> Self

Source

pub fn remove_ragged_left(&self) -> Self

Source

pub fn remove_ragged_right(&self) -> Self

Source

pub fn remove_ragged_top(&self) -> Self

Source

pub fn remove_ragged_bottom(&self) -> Self

Source

pub fn has_ragged_left(&self) -> bool

Source

pub fn has_ragged_right(&self) -> bool

Source

pub fn has_ragged_top(&self) -> bool

Source

pub fn has_ragged_bottom(&self) -> bool

Source

pub fn remove_ragged_border(&self) -> Self

Source

pub fn find_colour_pixel_coords(&self, colour: Colour) -> (usize, usize)

Source

pub fn find_different_pixel_coords(&self) -> (usize, usize)

Source

pub fn find_distinct_colours(&self, bg: Colour) -> Vec<Cell>

Source

pub fn shrink_border(&self) -> Self

Source

pub fn shrink_border_n(&self, n: usize) -> Self

Source

pub fn shrink_border_colour(&self, bg: Colour) -> Self

Source

pub fn shrink_border_colour_n(&self, bg: Colour, n: usize) -> Self

Source

pub fn shrink_left(&self, n: usize) -> Self

Source

pub fn on_edge(&self, grid: &Grid) -> bool

Source

pub fn find_same_row(&self, others: &[Self]) -> Self

Source

pub fn find_same_col(&self, others: &[Self]) -> Self

Source

pub fn shrink(&self) -> Self

Source

pub fn shrink_coloured(&self) -> Self

Source

pub fn euclidian(&self, other: &Self) -> f64

Source

pub fn manhattan(&self, other: &Self) -> usize

Source

pub fn is_diagonal(&self, other: &Self) -> bool

Source

pub fn which_direction(&self, other: &Self) -> Direction

Source

pub fn is_pixel(&self) -> bool

Source

pub fn fill_boundary_colour(&self) -> Self

Source

pub fn fill_boundary_colour_bg(&self, bg: Colour) -> Self

Source

pub fn flood_fill_border_mut( &mut self, ignore_colour: Colour, new_colour: Colour, )

Source

pub fn flood_fill( &self, r: usize, c: usize, ignore_colour: Colour, new_colour: Colour, ) -> Self

Source

pub fn flood_fill_mut( &mut self, r: usize, c: usize, ignore_colour: Colour, new_colour: Colour, )

Source

pub fn sid(m: &Matrix<Cell>, coloured: bool) -> u32

Source

pub fn contains_colour(&self, colour: Colour) -> bool

Source

pub fn has_bg_grid(&self) -> Colour

Source

pub fn has_bg_grid_coloured(&self) -> Colour

Source

pub fn has_bg_grid_not_sq(&self) -> Colour

Source

pub fn has_bg_grid_coloured_not_sq(&self) -> Colour

Source

pub fn gravity_down(&self) -> Self

Source

pub fn gravity_down_colour(&self, colour: Colour) -> Self

Source

pub fn gravity_up(&self) -> Self

Source

pub fn gravity_up_colour(&self, colour: Colour) -> Self

Source

pub fn gravity_right(&self) -> Self

Source

pub fn gravity_right_colour(&self, colour: Colour) -> Self

Source

pub fn gravity_left(&self) -> Self

Source

pub fn gravity_left_colour(&self, colour: Colour) -> Self

Source

pub fn equals(&self, other: &Self) -> Colour

Source

pub fn find_equals(&self, shapes: &Shapes) -> Shape

Source

pub fn equal_position(&self, other: &Self) -> bool

Source

pub fn find_equal_position(&self, shapes: &Shapes) -> Shape

Source

pub fn equal_footprint(&self, other: &Self) -> bool

Source

pub fn find_equal_footprint(&self, shapes: &Shapes) -> Shape

Source

pub fn equal_shape(&self, other: &Self) -> bool

Source

pub fn find_equal_shape(&self, shapes: &Shapes) -> Shape

Source

pub fn show_summary(&self)

Source

pub fn show(&self)

Source

pub fn show_full(&self)

Source

pub fn show_out(&self)

Source

pub fn show_io(&self)

Source

pub fn is_empty(&self) -> bool

Source

pub fn subshape_remain( &self, tlr: usize, sr: usize, tlc: usize, sc: usize, ) -> Self

Source

pub fn subshape(&self, tlr: usize, sr: usize, tlc: usize, sc: usize) -> Self

Source

pub fn subshape_trim( &self, tlr: usize, sr: usize, tlc: usize, sc: usize, ) -> Self

Source

pub fn id(&self) -> String

Source

pub fn above(&self, other: &Self) -> bool

Source

pub fn below(&self, other: &Self) -> bool

Source

pub fn right(&self, other: &Self) -> bool

Source

pub fn left(&self, other: &Self) -> bool

Source

pub fn diag(&self, other: &Self) -> bool

Source

pub fn orientation_horizontal(&self) -> Option<bool>

Source

pub fn size(&self) -> usize

Source

pub fn width(&self) -> usize

Source

pub fn height(&self) -> usize

Source

pub fn origin(&self) -> (usize, usize)

Source

pub fn pixels(&self) -> usize

Source

pub fn same_size(&self, other: &Self) -> bool

Source

pub fn same_shape(&self, other: &Self) -> bool

Source

pub fn same_pixel_positions(&self, other: &Self, same_colour: bool) -> bool

Source

pub fn dimensions(&self) -> (usize, usize)

Source

pub fn density(&self) -> f32

Source

pub fn distinct_colour_cnt(&self) -> usize

Source

pub fn find_layers(&self) -> (usize, Colour, Vec<Direction>)

Source

pub fn paint_layers_mut( &mut self, indent: usize, depth: usize, colour: Colour, dirs: Vec<Direction>, )

Source

pub fn cell_colours(&self) -> Vec<Colour>

Source

pub fn cell_colour_cnt_map(&self) -> BTreeMap<Colour, usize>

Source

pub fn cell_colour_cnt(cells: &Matrix<Cell>, max: bool) -> (Colour, usize)

Source

pub fn cell_colour_cnt_mixed( cells: &Matrix<Cell>, max: bool, mixed: bool, ) -> (Colour, usize)

Source

pub fn colour_cnt(&self, max: bool) -> (Colour, usize)

Source

pub fn majority_colour(&self) -> Colour

Source

pub fn minority_colour(&self) -> Colour

Source

pub fn colour_position(&self, colour: Colour) -> Vec<(usize, usize)>

Source

pub fn origin_centre(&self) -> (usize, usize, usize, usize)

Source

pub fn is_larger(&self, other: &Self) -> bool

Source

pub fn is_smaller(&self, other: &Self) -> bool

Source

pub fn larger(&self, other: &Self) -> Self

Source

pub fn smaller(&self, other: &Self) -> Self

Source

pub fn to_square(&self) -> Self

Source

pub fn to_square_grid(&self) -> Grid

Source

pub fn distance(&self, other: &Self) -> f32

Source

pub fn distance_from(&self, row: usize, col: usize) -> f32

Source

pub fn is_mirrored_r(&self, other: &Self) -> bool

Source

pub fn is_mirrored_c(&self, other: &Self) -> bool

Source

pub fn is_mirror_r(&self) -> bool

Source

pub fn is_mirror_c(&self) -> bool

Source

pub fn mirrored_r(&self) -> Self

Source

pub fn mirrored_c(&self) -> Self

Source

pub fn transposed(&self) -> Self

Source

pub fn is_transposed(&self, other: &Self) -> bool

Source

pub fn rotated_90(&self) -> Self

Source

pub fn rotated_180(&self) -> Self

Source

pub fn rotated_270(&self) -> Self

Source

pub fn rot_rect_90(&self) -> Self

Source

pub fn rot_rect_180(&self) -> Self

Source

pub fn rot_rect_270(&self) -> Self

Source

pub fn extend_line(&self) -> Self

Source

pub fn is_rotated_90(&self, other: &Self) -> bool

Source

pub fn is_rotated_180(&self, other: &Self) -> bool

Source

pub fn is_rotated_270(&self, other: &Self) -> bool

Source

pub fn rotate_90_pos(&self, times: usize, or: usize, oc: usize) -> Self

Source

pub fn to_grid(&self) -> Grid

Source

pub fn to_json(&self) -> String

Source

pub fn cell_count(&self) -> usize

Source

pub fn cell_count_colour(&self, colour: Colour) -> usize

Source

pub fn corner_idx(&self) -> (Self, Direction)

Source

pub fn corner_body(&self, dir: Direction) -> Self

Source

pub fn split_4(&self) -> Vec<Self>

Source

pub fn diff(&self, other: &Self) -> Option<Self>

Source

pub fn diff_orig(&self, other: &Self) -> Option<Self>

Source

pub fn diff_impl(&self, other: &Self, diff: bool) -> Option<Self>

Source

pub fn diff_only_transparent(&self) -> Self

Source

pub fn recolour(&self, from: Colour, to: Colour) -> Self

Source

pub fn recolour_mut(&mut self, from: Colour, to: Colour)

Source

pub fn force_recolour(&self, to: Colour) -> Self

Source

pub fn force_recolour_mut(&mut self, to: Colour)

Source

pub fn uncolour(&self) -> Self

Source

pub fn uncolour_mut(&mut self)

Source

pub fn is_line(&self) -> bool

Source

pub fn is_horizontal_line(&self) -> bool

Source

pub fn is_vertical_line(&self) -> bool

Source

pub fn is_square(&self) -> bool

Source

pub fn has_band(&self, rs: usize, cs: usize) -> (Direction, usize)

Source

pub fn make_square(&self) -> Self

Source

pub fn mut_recolour(&mut self, from: Colour, to: Colour)

Source

pub fn mut_force_recolour(&mut self, to: Colour)

Source

pub fn fill_missing(&self, to: Colour) -> Self

Source

pub fn scale_up(&self, factor: usize) -> Self

Source

pub fn scale_down(&self, factor: usize) -> Self

Source

pub fn has_border_hole( &self, hole: bool, fc: &dyn Fn(usize, usize, usize, usize) -> bool, ) -> bool

Source

pub fn has_border(&self) -> bool

Source

pub fn is_hollow(&self) -> bool

Source

pub fn has_open_border_top(&self) -> bool

Source

pub fn has_open_hole_top(&self) -> bool

Source

pub fn has_open_border_bottom(&self) -> bool

Source

pub fn has_open_hole_bottom(&self) -> bool

Source

pub fn has_open_border_left(&self) -> bool

Source

pub fn has_open_hole_left(&self) -> bool

Source

pub fn has_open_border_right(&self) -> bool

Source

pub fn has_open_hole_right(&self) -> bool

Source

pub fn find_a_border_break(&self) -> (Direction, usize, usize)

Source

pub fn has_border_break(&self) -> (Direction, usize, usize)

Source

pub fn centre_in(&self, other: &Self) -> Self

Source

pub fn put_all_in(&mut self, other: &Self)

Source

pub fn centre_of(&self) -> (usize, usize)

Source

pub fn centre_of_exact(&self) -> (f32, f32)

Source

pub fn nearest_point_idx(&self, points: &Vec<(usize, usize)>) -> usize

Source

pub fn nearest_point(&self, points: &Vec<(usize, usize)>) -> (usize, usize)

Source

pub fn pixel_coords(&self, colour: Colour) -> Option<(usize, usize)>

Source

pub fn move_in(&self, other: &Self) -> Self

Source

pub fn container(&self, other: &Self) -> bool

Source

pub fn can_contain(&self, other: &Self) -> bool

Source

pub fn contained_by(&self, other: &Self) -> bool

Source

pub fn is_contained(&self, other: &Self) -> bool

Source

pub fn contained_in(&self, other: &Self) -> bool

Source

pub fn nest_mut(&mut self, n: usize, colour: Colour)

Source

pub fn patch_in_shape(&self, other: &Self) -> (usize, usize)

Source

pub fn adjacent_r_or_c(&self, other: &Self) -> bool

Source

pub fn touching(&self, other: &Self) -> bool

Source

pub fn find_touching(&self, shapes: &Shapes) -> Shape

Source

pub fn single_colour(&self) -> Option<Colour>

Source

pub fn is_single_colour(&self) -> bool

Source

pub fn translate_row(&self, r: isize) -> Self

Source

pub fn translate_col(&self, c: isize) -> Self

Source

pub fn translate(&self, r: isize, c: isize) -> Self

Source

pub fn translate_absolute_r(&self, r: usize) -> Self

Source

pub fn translate_absolute_c(&self, c: usize) -> Self

Source

pub fn translate_absolute(&self, r: usize, c: usize) -> Self

Source

pub fn have_common_pixel_colour(&self, other: &Self) -> bool

Source

pub fn merge_on_common_pixel(&self, other: &Self) -> Option<Self>

Source

pub fn normalise(&self, si: &Self) -> (Self, Self)

Source

pub fn normalise_key(&self) -> Self

Source

pub fn bare_corners(&self) -> bool

Source

pub fn fit_shape(&self, _shape: &Self) -> Self

Source

pub fn to_origin(&self) -> Self

Source

pub fn to_origin_mut(&mut self)

Source

pub fn to_position(&self, r: usize, c: usize) -> Self

Source

pub fn to_position_mut(&mut self, r: usize, c: usize)

Source

pub fn compare(&self, shape: &Self) -> bool

Source

pub fn copy_into(&self, shape: &Self) -> Self

Source

pub fn position(&self, ci: &Self) -> Self

Source

pub fn has_border_cell(&self, other: &Self) -> bool

Source

pub fn is_subgrid(&self, other: &Self) -> bool

Source

pub fn find_black_patches_limit(&self, limit: usize) -> Shapes

Source

pub fn has_arm(&self, limit: usize) -> (Direction, usize)

Source

pub fn bordered_shape(&self) -> bool

Source

pub fn hollow(&self) -> bool

Source

pub fn hollow_colour_count(&self) -> (Colour, usize)

Source

pub fn full_shape(&self) -> bool

Source

pub fn add_hugging_border(&self, colour: Colour) -> Self

Source

pub fn add_border(&self, colour: Colour) -> Self

Source

pub fn toddle_colour(&self, bg: Colour, fg: Colour) -> Self

Source

pub fn extend_top(&self, n: usize) -> Self

Source

pub fn extend_bottom(&self, n: usize) -> Self

Source

pub fn extend_left(&self, n: usize) -> Self

Source

pub fn extend_right(&self, n: usize) -> Self

Source

pub fn dense(&self) -> bool

Source

pub fn split_shapes(&self) -> Shapes

Source

pub fn de_subshape(&self, shapes: &mut Shapes)

Source

pub fn draw_line(&self, other: &Self, colour: Colour) -> Shape

Source

pub fn fill_lines(&self, colour: Colour) -> Self

Source

pub fn find_first_blacks(&self) -> Vec<(usize, usize)>

Source

pub fn find_first_colours(&self, colour: Colour) -> Vec<(usize, usize)>

Source

pub fn surround( &self, thickness: usize, colour: Colour, all: bool, corners: bool, ) -> Self

Source

pub fn bg_count(&self) -> usize

Source

pub fn split_2(&self) -> Shapes

Source

pub fn cell_category(cells: &Matrix<Cell>) -> Matrix<Cell>

Source

pub fn cell_category_bg(cells: &Matrix<Cell>, bg: Colour) -> Matrix<Cell>

Source

pub fn fill_corners_mut(&mut self, pixels: usize, colour: Colour)

Source

pub fn pixel_position(&self, min_colour: Colour) -> Direction

Source

pub fn chequer( &self, rows: usize, cols: usize, pred: &dyn Fn(usize, usize) -> bool, func: &dyn Fn(&Self) -> Self, blank: bool, ) -> Shapes

Source

pub fn combined_chequer( &self, rows: usize, cols: usize, func: &dyn Fn(&Self, usize, usize) -> Self, ) -> Shapes

Source

pub fn fit_chequer( &self, rc: usize, cc: usize, rstart: usize, cstart: usize, rgap: usize, cgap: usize, rs: usize, cs: usize, func: &dyn Fn(&Self, usize, usize) -> Self, ) -> Shapes

Source

pub fn invert_colour(&self) -> Self

Source

pub fn blank(&self) -> Self

Source

pub fn copy(&self, other: &Self) -> Self

Source

pub fn copy_not_colour(&self, other: &Self, nc: Colour) -> Self

Source

pub fn get_joined(&self) -> Shapes

Source

pub fn fill_centre_mut(&mut self, colour: Colour)

Source

pub fn mid_pixel(&self) -> (usize, usize)

Source

pub fn swap_colours(&mut self, cm: &BTreeMap<Colour, Colour>)

Source

pub fn adjacent_to_pixel(&self, grid: &Grid) -> Vec<Direction>

Trait Implementations§

Source§

impl Clone for Shape

Source§

fn clone(&self) -> Shape

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Shape

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Ord for Shape

Source§

fn cmp(&self, other: &Self) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl PartialEq for Shape

Source§

fn eq(&self, other: &Shape) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialOrd for Shape

Source§

fn partial_cmp(&self, other: &Self) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl Eq for Shape

Auto Trait Implementations§

§

impl Freeze for Shape

§

impl RefUnwindSafe for Shape

§

impl Send for Shape

§

impl Sync for Shape

§

impl Unpin for Shape

§

impl UnwindSafe for Shape

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<Q, K> Comparable<K> for Q
where Q: Ord + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn compare(&self, key: &K) -> Ordering

Compare self to key and return their ordering.
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.