Struct TileNet

Source
pub struct TileNet<T> { /* private fields */ }
Expand description

TileNet is the main class in this library

It represents a 2D space with dimensions rows x columns. Each index represents a point in space. Row ‘n’ and column ‘m’ denote the tile from x from n inclusive to n+1 exclusive, and y from m inclusive to m+1 exclusive.

use tile_net::TileNet;
#[derive(Clone, Debug, Default)]
struct Example(i32);
let my_net = TileNet::<Example>::new(10, 10);
println!("{:?}", my_net);

Implementations§

Source§

impl TileNet<usize>

Source

pub fn sample() -> TileNet<usize>

Create a simple sample grid

Source§

impl<T> TileNet<T>
where T: Clone,

Source

pub fn prepare(&mut self) -> TileNetProxy<'_, T>

Create a proxy to be able to get the span of a change

Source

pub fn get_raw(&self) -> &[T]

Get the raw array behind the tilenet

Source

pub fn set_box( &mut self, value: &T, start: (usize, usize), stop: (usize, usize), )

Set a box in the tilenet

Source

pub fn set_row(&mut self, value: &T, row: usize)

Set a row

Source

pub fn set_col(&mut self, value: &T, col: usize)

Set a column

Source

pub fn set(&mut self, value: &T, p: (usize, usize))

Set a single grid point

Source§

impl<T> TileNet<T>
where T: Clone + Default,

Source

pub fn new(x: usize, y: usize) -> TileNet<T>

Create a new tilenet of the size (cols, rows)

The tiles will be Default-created

Source

pub fn resize(&mut self, m: (usize, usize))

Resize the grid

If the grid grows, new tiles will be Default-created

Source§

impl<T> TileNet<T>
where T: Default,

Source

pub fn from_iter<I>(columns: usize, iter: I) -> TileNet<T>
where I: Iterator<Item = T>,

Create a tilenet from an iterator

Takes a column count and an iterator. If the iterator does not describe the entire box the remaining elements are filled in by Default.

Source§

impl<T> TileNet<T>

Source

pub fn row_count(&self) -> usize

Compute the row count

Source

pub fn col_count(&self) -> usize

Get the column count

Source

pub fn get(&self, p: (usize, usize)) -> Option<&T>

Get a reference to a 2D index

Source

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

Get a tuple that describes the size as (cols, rows)

Source

pub fn view_all(&self) -> TileView<'_, T>

Create a proxy view that iterates over all tiles

Source

pub fn view_center_f32( &self, position: (f32, f32), span: (usize, usize), ) -> TileView<'_, T>

Create a proxy view with a span from the center using a float position

Source

pub fn view_center( &self, position: (usize, usize), span: (usize, usize), ) -> TileView<'_, T>

Create a proxy view with a span from the center using an integer position

Source

pub fn view_box( &self, rectangle: (usize, usize, usize, usize), ) -> TileView<'_, T>

Create a view box that iterates over tiles within that box

Source

pub fn get_mut(&mut self, p: (usize, usize)) -> Option<&mut T>

Get a mutable reference to a tile

Source

pub fn collide_set<I>(&self, list: I) -> TileSet<'_, T, I>
where I: Iterator<Item = (i32, i32)>,

Create an iterator of tiles from an iterator over indices

Trait Implementations§

Source§

impl<T: Clone> Clone for TileNet<T>

Source§

fn clone(&self) -> TileNet<T>

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

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

Performs copy-assignment from source. Read more
Source§

impl<T: Debug> Debug for TileNet<T>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<T> Freeze for TileNet<T>

§

impl<T> RefUnwindSafe for TileNet<T>
where T: RefUnwindSafe,

§

impl<T> Send for TileNet<T>
where T: Send,

§

impl<T> Sync for TileNet<T>
where T: Sync,

§

impl<T> Unpin for TileNet<T>
where T: Unpin,

§

impl<T> UnwindSafe for TileNet<T>
where T: UnwindSafe,

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<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> 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.