[noobquestion] Distance between two points

It’s kind of awkward because the solution is probably pretty easy, but I’m new to rust as well as nalgebra, so I don’t know how to solve this.

I got two points (nalgebra::Point<f32, ggez::nalgebra::U2>) and I want to get the distance between them using the nalgebra::distance function. When I insert the two points I get this error:

the trait bound &ggez::nalgebra::Point<f32, ggez::nalgebra::U2>: alga::linear::vector::EuclideanSpace is not satisfied

the trait alga::linear::vector::EuclideanSpace is not implemented for &ggez::nalgebra::Point<f32, ggez::nalgebra::U2>

help: the following implementations were found:
<ggez::nalgebra::Point<N, D> as alga::linear::vector::EuclideanSpace>

How can I solve this?

Hi!

It appears that you are using an older version of nalgebra because the trait alga::linear::vector::EuclideanSpace is no longer required by nalgebra::distance.
Also, are you sure you are using the same version of nalgebra as the one ggez depends on?

I think there is no option to upgrade nalgebra, because I have the version that ggez depends on. (I only have ggez in my dependencies)

Yeah, the upgrade would have to happen in ggez directly.

Looking at the error you are getting more closely I think you may have one level of reference to remove, i.e., you are passing &&Point arguments to ::distance instead of just &Point. Perhaps you are taking a reference of something that is already a ref? Could you perhaps provide here the piece of code that is failing?

1 Like

Well that was a good hint; I removed one reference and was able to solve the issue. Thanks a lot !