Struct QuadTree

Source
pub struct QuadTree<C, Item, Cap = DynCap>
where C: Coordinate,
{ /* private fields */ }
Expand description

§Parameter

C: The type used for coordinates Item: The type to be saved CAP: The maximum capacity of each level

Implementations§

Source§

impl<C, Item, Cap> QuadTree<C, Item, Cap>
where Cap: Capacity, C: Coordinate,

Source

pub fn new_with_capacity(boundary: Boundary<C>, capacity: Cap) -> Self

Create a new quad tree for a given area where each level of the tree has a given capacity.

§Example
use qutee::*;
struct MyItem;
let tree = QuadTree::<_, MyItem, DynCap>::new_with_capacity(Boundary::between_points((10,10), (20,20)), DynCap::new(20));
assert_eq!(tree.capacity(), 20);
Source

pub fn insert_at( &mut self, point: impl Into<Point<C>>, value: Item, ) -> Result<(), QuadTreeError<C>>

Insert new item into the quad tree.

§Errors

Returns an error if the point is out of bounds.

§Example
use qutee::*;
let mut tree = QuadTree::<_,_,ConstCap<2>>::new_with_const_cap(Boundary::between_points((0,0), (10,10)));
assert!(tree.insert_at((5,5), ()).is_ok());
assert!(tree.insert_at((11,11), ()).is_err());
Source

pub fn insert_at_unchecked(&mut self, point: impl Into<Point<C>>, value: Item)

Same as insert_at except that no bounds check is performed.

§Example
use qutee::*;
let mut tree = QuadTree::<_,_,ConstCap<2>>::new_with_const_cap(Boundary::between_points((0,0), (10,10)));
tree.insert_at_unchecked((5,5), ());
assert_eq!(tree.iter().count(), 1);
Source

pub fn query<A>(&self, area: A) -> Query<'_, C, A, Item, Cap>
where A: Area<C>,

Get all items in a given area.

§Example
use qutee::*;
let mut tree = QuadTree::<_,_,ConstCap<2>>::new_with_const_cap(Boundary::between_points((0,0), (10,10)));
tree.insert_at((3,5), 1);
tree.insert_at((1,0), 2);
tree.insert_at((7,3), 4);
tree.insert_at((9,4), 5);
let mut res = tree.query(Boundary::between_points((2,1), (8,9))).copied().collect::<Vec<_>>();
res.sort();
assert_eq!(res, vec![1,4]);
Source

pub fn query_points<A>(&self, area: A) -> QueryPoints<'_, C, A, Item, Cap>
where A: Area<C>,

Get all items in a given area and their coordinates.

§Example
use qutee::*;
let mut tree = QuadTree::<_,_,ConstCap<2>>::new_with_const_cap(Boundary::between_points((0,0), (10,10)));
tree.insert_at((3,5), 1);
tree.insert_at((1,0), 2);
tree.insert_at((7,3), 4);
tree.insert_at((9,4), 5);
let mut res = tree.query_points(Boundary::between_points((2,1), (8,9))).copied().collect::<Vec<_>>();
res.sort_by(|a,b| a.1.cmp(&b.1));
assert_eq!(res, vec![
    ((3,5).into(), 1),
    ((7,3).into(), 4),
]);
Source

pub fn iter(&self) -> Iter<'_, C, Item, Cap>

Get an iterator over all items.

Source

pub fn iter_points(&self) -> IterPoints<'_, C, Item, Cap>

Get an iterator over all items and their coordinates.

Source

pub fn boundary(&self) -> &Boundary<C>

Returns the boundary of this QuadTree

Source

pub fn capacity(&self) -> usize

Returns the capacity

Source§

impl<C, Item, Cap> QuadTree<C, Item, Cap>
where Cap: Capacity, C: Coordinate, Item: AsPoint<C>,

Source

pub fn insert(&mut self, item: Item) -> Result<(), QuadTreeError<C>>

Insert a new item

§Errors

Returns an error if the item is out of bounds.

§Example
use qutee::*;
struct Item {
    x: usize,
    y: usize,
}
impl AsPoint<usize> for Item {
    fn as_point(&self) -> Point<usize> {
        (self.x, self.y).into()
    }
}
let mut quad_tree = QuadTree::new_with_dyn_cap(Boundary::between_points((0,0),(10,10)), 5);
assert!(quad_tree.insert(Item {
    x: 5,
    y: 5,
}).is_ok());
Source

pub fn insert_unchecked(&mut self, item: Item)

Same as insert except that no bounds check is performed.

Source§

impl<C, Item> QuadTree<C, Item, DynCap>
where C: Coordinate,

Source

pub fn new_with_dyn_cap(boundary: Boundary<C>, cap: usize) -> Self

Create a new QuadTree

Source§

impl<C, Item, const CAP: usize> QuadTree<C, Item, ConstCap<CAP>>
where C: Coordinate,

Source

pub fn new_with_const_cap(boundary: Boundary<C>) -> Self

Create a new QuadTree with a constant capacity

Trait Implementations§

Source§

impl<C, Item: Clone, Cap: Clone> Clone for QuadTree<C, Item, Cap>
where C: Coordinate + Clone,

Source§

fn clone(&self) -> QuadTree<C, Item, Cap>

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<C, Item: Debug, Cap: Debug> Debug for QuadTree<C, Item, Cap>
where C: Coordinate + Debug,

Source§

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

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

impl<C, Item: PartialEq, Cap: PartialEq> PartialEq for QuadTree<C, Item, Cap>
where C: Coordinate + PartialEq,

Source§

fn eq(&self, other: &QuadTree<C, Item, Cap>) -> 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<C, Item: Eq, Cap: Eq> Eq for QuadTree<C, Item, Cap>
where C: Coordinate + Eq,

Source§

impl<C, Item, Cap> StructuralPartialEq for QuadTree<C, Item, Cap>
where C: Coordinate,

Auto Trait Implementations§

§

impl<C, Item, Cap> Freeze for QuadTree<C, Item, Cap>
where Cap: Freeze, C: Freeze,

§

impl<C, Item, Cap> RefUnwindSafe for QuadTree<C, Item, Cap>

§

impl<C, Item, Cap> Send for QuadTree<C, Item, Cap>
where Cap: Send, C: Send, Item: Send,

§

impl<C, Item, Cap> Sync for QuadTree<C, Item, Cap>
where Cap: Sync, C: Sync, Item: Sync,

§

impl<C, Item, Cap> Unpin for QuadTree<C, Item, Cap>
where Cap: Unpin, C: Unpin, Item: Unpin,

§

impl<C, Item, Cap> UnwindSafe for QuadTree<C, Item, Cap>
where Cap: UnwindSafe, C: UnwindSafe, Item: 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.