Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "quadtree_rs"
version = "0.1.3"
authors = ["James Adam Buckland <james.adam.buckland@gmail.com>"]
edition = "2018"
edition = "2021"
description = "Point/region Quadtree with support for overlapping regions."

publish = true
Expand All @@ -26,9 +26,9 @@ license = "Apache-2.0"
maintenance = { status = "actively-developed" }

[dependencies]
num = "0.2"
derive_builder = "0.7"
serde = { version = "1.0.152", features = ["derive"], optional=true}
num = "0.4"
derive_builder = "0.12"
serde = { version = "1", features = ["derive"], optional = true }

[features]
serde = ["dep:serde"]
Expand All @@ -39,5 +39,9 @@ serde = ["dep:serde"]
[dev-dependencies.cargo-husky]
version = "1"
default-features = false # Disable features which are enabled by default
features = ["precommit-hook", "run-cargo-test", "run-cargo-clippy", "run-cargo-fmt"]

features = [
"precommit-hook",
"run-cargo-test",
"run-cargo-clippy",
"run-cargo-fmt",
]
18 changes: 8 additions & 10 deletions src/area.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,11 @@

//! A rectangular region in the tree.

use crate::point::Point;
use num::PrimInt;
#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};
use {
crate::point,
num::PrimInt,
std::{cmp::PartialOrd, default::Default, fmt::Debug},
};
use std::{cmp::PartialOrd, default::Default, fmt::Debug};

/// A rectangular region in 2d space.
///
Expand All @@ -37,7 +35,7 @@ pub struct Area<U>
where
U: PrimInt + Default + PartialOrd,
{
anchor: point::Point<U>,
anchor: Point<U>,
#[builder(default = "(U::one(), U::one())")]
dimensions: (U, U),
}
Expand Down Expand Up @@ -101,7 +99,7 @@ where
U: PrimInt + Default,
{
/// The top-left coordinate (anchor) of the region.
pub fn anchor(&self) -> point::Point<U> {
pub fn anchor(&self) -> Point<U> {
self.anchor
}

Expand Down Expand Up @@ -152,7 +150,7 @@ where
}

/// Whether or not an area contains a point.
pub fn contains_pt(self, pt: point::Point<U>) -> bool {
pub fn contains_pt(self, pt: Point<U>) -> bool {
self.contains(
AreaBuilder::default()
.anchor(pt)
Expand All @@ -164,9 +162,9 @@ where

// NB: The center point is an integer and thus rounded, i.e. a 2x2 region at (0,0) has a center
// at (0,0), when in reality the center would be at (0.5, 0.5).
pub(crate) fn center_pt(&self) -> point::Point<U> {
pub(crate) fn center_pt(&self) -> Point<U> {
self.anchor()
+ point::Point {
+ Point {
x: self.width() / Self::two(),
y: self.height() / Self::two(),
}
Expand Down
12 changes: 3 additions & 9 deletions src/entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,11 @@
//! A view into a single entry in the Quadtree.
// Influenced by https://doc.rust-lang.org/std/collections/hash_map/enum.Entry.html.

use crate::{area::Area, point::Point};
use num::PrimInt;
#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};
use {
crate::{area::Area, point::Point},
num::PrimInt,
std::default::Default,
};
use std::default::Default;

/// A region/value association in the [`Quadtree`].
///
Expand Down Expand Up @@ -80,8 +78,6 @@ impl<U, V> Entry<U, V>
where
U: PrimInt + Default,
{
// pub

/// The returned region.
pub fn area(&self) -> Area<U> {
self.region
Expand Down Expand Up @@ -112,8 +108,6 @@ where
&self.value
}

// pub(crate)

pub(crate) fn new((region, value): (Area<U>, V), handle: u64) -> Self {
Self {
region,
Expand Down
12 changes: 5 additions & 7 deletions src/handle_iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,9 @@
// See the License for the specific language governing permissions and
// limitations under the License.

use {
crate::{area::Area, qtinner::QTInner, traversal::Traversal},
num::PrimInt,
std::{collections::HashSet, default::Default, iter::FusedIterator},
};
use crate::{area::Area, qtinner::QTInner, traversal::Traversal};
use num::PrimInt;
use std::{collections::HashSet, default::Default, iter::FusedIterator};

#[derive(Clone, Debug)]
pub(crate) struct HandleIter<'a, U>
Expand All @@ -33,7 +31,7 @@ impl<'a, U> HandleIter<'a, U>
where
U: PrimInt + Default,
{
pub(crate) fn new(qt: &'a QTInner<U>, search_area: Area<U>) -> HandleIter<'a, U> {
pub(crate) fn new(qt: &'a QTInner<U>, search_area: Area<U>) -> Self {
HandleIter {
search_area,
handle_stack: vec![],
Expand Down Expand Up @@ -114,7 +112,7 @@ where
if let Some(qt) = self.qt_stack.pop() {
// Push my sub quadrants onto the qt_stack too.
if let Some(sub_quadrants) = qt.subquadrants().as_ref() {
for sub_quadrant in sub_quadrants {
for sub_quadrant in &**sub_quadrants {
if sub_quadrant.region().intersects(self.search_area) {
self.qt_stack.push(sub_quadrant)
}
Expand Down
16 changes: 7 additions & 9 deletions src/iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,12 @@
// See the License for the specific language governing permissions and
// limitations under the License.

use {
crate::{
area::Area, entry::Entry, handle_iter::HandleIter, qtinner::QTInner, traversal::Traversal,
types::StoreType,
},
num::PrimInt,
std::iter::FusedIterator,
use crate::{
area::Area, entry::Entry, handle_iter::HandleIter, qtinner::QTInner, traversal::Traversal,
StoreType,
};
use num::PrimInt;
use std::iter::FusedIterator;

/// An iterator over all regions and values of a [`Quadtree`].
///
Expand All @@ -40,7 +38,7 @@ impl<'a, U, V> Iter<'a, U, V>
where
U: PrimInt + Default,
{
pub(crate) fn new(qt: &'a QTInner<U>, store: &'a StoreType<U, V>) -> Iter<'a, U, V> {
pub(crate) fn new(qt: &'a QTInner<U>, store: &'a StoreType<U, V>) -> Self {
Iter {
store,
handle_iter: HandleIter::new(qt, qt.region()),
Expand Down Expand Up @@ -133,7 +131,7 @@ where
qt: &'a QTInner<U>,
store: &'a StoreType<U, V>,
traversal_method: Traversal,
) -> Query<'a, U, V>
) -> Self
where
U: PrimInt + Default,
{
Expand Down
Loading