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

RFC: Use extension trait to simplify combinator usage. #123

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
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
2 changes: 1 addition & 1 deletion rstar/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ pub use crate::algorithm::rstar::RStarInsertionStrategy;
pub use crate::algorithm::selection_functions::SelectionFunction;
pub use crate::envelope::Envelope;
pub use crate::node::{ParentNode, RTreeNode};
pub use crate::object::{PointDistance, RTreeObject};
pub use crate::object::{PointDistance, RTreeObject, RTreeObjectExt};
pub use crate::params::{DefaultParams, InsertionStrategy, RTreeParams};
pub use crate::point::{Point, RTreeNum};
pub use crate::rtree::RTree;
Expand Down
33 changes: 33 additions & 0 deletions rstar/src/object.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::aabb::AABB;
use crate::envelope::Envelope;
use crate::point::{Point, PointExt};
use crate::primitives::{CachedEnvelope, GeomWithData};

/// An object that can be inserted into an r-tree.
///
Expand Down Expand Up @@ -225,3 +226,35 @@ where
}
}
}

/// TODO
pub trait RTreeObjectExt: RTreeObject {
/// TODO
fn with_data<S>(self, data: S) -> GeomWithData<Self, S>
where
Self: Sized;

/// TODO
fn cached_envelope(self) -> CachedEnvelope<Self>
where
Self: Sized;
}

impl<T> RTreeObjectExt for T
where
T: RTreeObject,
{
fn with_data<S>(self, data: S) -> GeomWithData<Self, S>
where
Self: Sized,
{
GeomWithData::new(self, data)
}

fn cached_envelope(self) -> CachedEnvelope<Self>
where
Self: Sized,
{
CachedEnvelope::new(self)
}
}