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,
impl<C, Item, Cap> QuadTree<C, Item, Cap>where
Cap: Capacity,
C: Coordinate,
Sourcepub fn new_with_capacity(boundary: Boundary<C>, capacity: Cap) -> Self
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);
Sourcepub fn insert_at(
&mut self,
point: impl Into<Point<C>>,
value: Item,
) -> Result<(), QuadTreeError<C>>
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());
Sourcepub fn insert_at_unchecked(&mut self, point: impl Into<Point<C>>, value: Item)
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);
Sourcepub fn query<A>(&self, area: A) -> Query<'_, C, A, Item, Cap> ⓘwhere
A: Area<C>,
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]);
Sourcepub fn query_points<A>(&self, area: A) -> QueryPoints<'_, C, A, Item, Cap> ⓘwhere
A: Area<C>,
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),
]);
Sourcepub fn iter_points(&self) -> IterPoints<'_, C, Item, Cap> ⓘ
pub fn iter_points(&self) -> IterPoints<'_, C, Item, Cap> ⓘ
Get an iterator over all items and their coordinates.
Source§impl<C, Item, Cap> QuadTree<C, Item, Cap>where
Cap: Capacity,
C: Coordinate,
Item: AsPoint<C>,
impl<C, Item, Cap> QuadTree<C, Item, Cap>where
Cap: Capacity,
C: Coordinate,
Item: AsPoint<C>,
Sourcepub fn insert(&mut self, item: Item) -> Result<(), QuadTreeError<C>>
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());
Sourcepub fn insert_unchecked(&mut self, item: Item)
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,
impl<C, Item> QuadTree<C, Item, DynCap>where
C: Coordinate,
Sourcepub fn new_with_dyn_cap(boundary: Boundary<C>, cap: usize) -> Self
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,
impl<C, Item, const CAP: usize> QuadTree<C, Item, ConstCap<CAP>>where
C: Coordinate,
Sourcepub fn new_with_const_cap(boundary: Boundary<C>) -> Self
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,
impl<C, Item: Clone, Cap: Clone> Clone for QuadTree<C, Item, Cap>where
C: Coordinate + Clone,
Source§impl<C, Item: Debug, Cap: Debug> Debug for QuadTree<C, Item, Cap>where
C: Coordinate + Debug,
impl<C, Item: Debug, Cap: Debug> Debug for QuadTree<C, Item, Cap>where
C: Coordinate + Debug,
Source§impl<C, Item: PartialEq, Cap: PartialEq> PartialEq for QuadTree<C, Item, Cap>where
C: Coordinate + PartialEq,
impl<C, Item: PartialEq, Cap: PartialEq> PartialEq for QuadTree<C, Item, Cap>where
C: Coordinate + PartialEq,
impl<C, Item: Eq, Cap: Eq> Eq for QuadTree<C, Item, Cap>where
C: Coordinate + Eq,
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>
impl<C, Item, Cap> RefUnwindSafe for QuadTree<C, Item, Cap>
impl<C, Item, Cap> Send for QuadTree<C, Item, Cap>
impl<C, Item, Cap> Sync for QuadTree<C, Item, Cap>
impl<C, Item, Cap> Unpin for QuadTree<C, Item, Cap>
impl<C, Item, Cap> UnwindSafe for QuadTree<C, Item, Cap>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more