Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hash and Default impls, and some type coverage tests #150

Merged
merged 3 commits into from
Jan 7, 2024
Merged
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
2 changes: 2 additions & 0 deletions rstar/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
- Add optional support for the [mint](https://docs.rs/mint/0.5.9/mint/index.html) crate
- Implemented `IntoIter` for `RTree`, i.e. added a owning iterator
- Added cached envelope bulk load benchmark
- Implemented `Hash` for `AABB`, `Line`, and `Rectangle`, provided the `Point` used implements `Hash` itself
- Implemented `Default` for `DefaultParams`

## Changed
- Fixed a stack overflow error in `DrainIterator::next`
Expand Down
2 changes: 1 addition & 1 deletion rstar/src/aabb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use serde::{Deserialize, Serialize};
/// # Type arguments
/// `P`: The struct is generic over which point type is used. Using an n-dimensional point
/// type will result in an n-dimensional bounding box.
#[derive(Clone, Debug, Copy, PartialEq, Eq, Ord, PartialOrd)]
#[derive(Clone, Debug, Copy, PartialEq, Eq, Ord, PartialOrd, Hash)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct AABB<P>
where
Expand Down
2 changes: 1 addition & 1 deletion rstar/src/params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ pub trait RTreeParams: Send + Sync {
}

/// The default parameters used when creating an r-tree without specific parameters.
#[derive(Clone, Copy, PartialEq, Eq)]
#[derive(Clone, Copy, PartialEq, Eq, Default)]
pub struct DefaultParams;

impl RTreeParams for DefaultParams {
Expand Down
28 changes: 24 additions & 4 deletions rstar/src/point.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@ use num_traits::{Bounded, Num, Signed, Zero};
/// Defines a number type that is compatible with rstar.
///
/// rstar works out of the box with the following standard library types:
/// - i32
/// - i64
/// - f32
/// - f64
/// - i8, i16, i32, i64, i128, isize
/// - [Wrapping](core::num::Wrapping) versions of the above
/// - f32, f64
///
/// This type cannot be implemented directly. Instead, it is required to implement
/// all required traits from the `num_traits` crate.
Expand Down Expand Up @@ -397,6 +396,27 @@ impl_point_for_tuple!(0 => a, 1 => b, 2 => c, 3 => d, 4 => e, 5 => f, 6 => g, 7
#[cfg(test)]
mod tests {
use super::*;
use core::num::Wrapping;

#[test]
fn test_types() {
fn assert_impl_rtreenum<S: RTreeNum>() {}

assert_impl_rtreenum::<i8>();
assert_impl_rtreenum::<i16>();
assert_impl_rtreenum::<i32>();
assert_impl_rtreenum::<i64>();
assert_impl_rtreenum::<i128>();
assert_impl_rtreenum::<isize>();
assert_impl_rtreenum::<Wrapping<i8>>();
assert_impl_rtreenum::<Wrapping<i16>>();
assert_impl_rtreenum::<Wrapping<i32>>();
assert_impl_rtreenum::<Wrapping<i64>>();
assert_impl_rtreenum::<Wrapping<i128>>();
assert_impl_rtreenum::<Wrapping<isize>>();
assert_impl_rtreenum::<f32>();
assert_impl_rtreenum::<f64>();
}

macro_rules! test_tuple_configuration {
($($index:expr),*) => {
Expand Down
2 changes: 1 addition & 1 deletion rstar/src/primitives/line.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use num_traits::{One, Zero};
///
/// assert!(tree.contains(&line_1));
/// ```
#[derive(Debug, Clone, Copy, Eq, PartialEq, Ord, PartialOrd)]
#[derive(Debug, Clone, Copy, Eq, PartialEq, Ord, PartialOrd, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct Line<P>
where
Expand Down
2 changes: 1 addition & 1 deletion rstar/src/primitives/rectangle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use crate::point::{Point, PointExt};
///
/// # Type parameters
/// `P`: The rectangle's [Point] type.
#[derive(Debug, Clone, Copy, Eq, PartialEq, Ord, PartialOrd)]
#[derive(Debug, Clone, Copy, Eq, PartialEq, Ord, PartialOrd, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct Rectangle<P>
where
Expand Down