-
Notifications
You must be signed in to change notification settings - Fork 68
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
Can't use PointExt methods in custom implementation #46
Comments
Could you produce a minimal but complete example so we can build and hopefully fix this locally? |
use rstar::{Point, AABB};
// use rstar::point::PointExt; //module 'rstar::point' is private
fn main() {
let p = Sample::new([0., 0.], 1.);
}
struct Sample<P>
where
P: Point
{
aabb: AABB<P>,
}
impl<P> Sample<P>
where P: Point
{
fn new(center: P, size: f64) -> Self <> {
let p1 = center.sub(P::from_value(size / 2.));
let p2 = center.add(P::from_value(size / 2.));
Sample {
aabb: AABB::from_corners(p1, p2)
}
}
}
|
And what do you think about implementing AABB::from_center() by default? |
Thank you for the worked example. So I think the request here is to make the |
If that would suffice to fulfill your use case, then IMHO it would be preferable to exposing all of |
In 'rsrar-demo' it works somehow and I decided that it should work for me too.
Not sure what does it exactly mean, but most likely you are right. I understand that as if I need this functionality, then it's better to implement it by myself? |
The demo also only uses the public API (https://docs.rs/rstar/0.8.2/rstar/trait.Point.html). It's just
The possible alternatives at the moment are scarce:
I know that both options add quite a bit of boilerplate. I've opened #28 a while ago to investigate how to better support other libraries but have not had a stroke of genius so far. Please let me know if you have any remaining questions, otherwise I'll go ahead and close this issue in favour of #28. |
@Stoeoef Thanks for the explanation! No more questions, it's pretty clear. |
I was actually suggesting that we add a |
Adding |
For experimentation, I cloned the repository and tried to create my own primitive. impl<P> AABB<P>
where
P: Point<Scalar=f64>
{
pub fn from_center(center: P, size: f64) -> Self {
let size: P = P::from_value(size / 2.);
let p1: P = center.add(&size);
let p2: P = center.sub(&size);
AABB::from_corners(p1, p2)
}
} Actually, AABB implementation has something similar (but more clever): fn center(&self) -> Self::Point {
let one = <Self::Point as Point>::Scalar::one();
let two = one + one;
self.lower.component_wise(&self.upper, |x, y| (x + y) / two)
}
This is a dilemma) And I don't have any wise solution to this problem, I'm too nooby for this type of situations. I don't think that it's necessary to add |
And, if to be clear, I'm trying to implement something like |
I'm trying something like:
and it drops the error:
items from traits can only be used if the trait is in scope
In 'rstar-demo' there is an example:
and it's works, but the same doesn't work for me.
The text was updated successfully, but these errors were encountered: