Struct tile_net::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 copy 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<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> 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 Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

source§

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

Mutably borrows from an owned value. 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 Twhere 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 Twhere T: Clone,

§

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 Twhere U: Into<T>,

§

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 Twhere U: TryFrom<T>,

§

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.