2D point converts into 3D vector
- Dominant language
- Rust
- Stars
- 4.8k
- Forks
- 565
- PR merge metrics
- No merged PRs in 30d
Description
I've come across a weird behavior that really baffled me initially.
This compiles with nalgebra 0.29:
``` rust
let _: nalgebra::SVector = nalgebra::point![1.0, 2.0].into();
```
It converts an `OPoint` into an `SVector`, using `Into`.
Here's the same, with debug output:
``` rust
let v: nalgebra::SVector = dbg!(nalgebra::point![1.0, 2.0]).into();
dbg!(v);
```
Output of first `dbg!`:
```
nalgebra::point![1.0, 2.0] = OPoint {
coords: Matrix {
data: [
[
1.0,
2.0,
],
],
},
}
```
Second `dbg!`:
```
v = Matrix {
data: [
[
1.0,
2.0,
1.0,
],
],
}
```
I have some code that is generic over dimensions and uses an `Into>` ([[1]](https://github.com/hannobraun/fornjot/blob/47804e082550e9e7fd8ec499d4df57d4edf653ce/fj/src/syntax.rs#L106)), and this was really confusing. I was expecting that `Into` to get me conversions from arrays, maybe points of the same dimension, but not this.
This seems to be the `From` implementation that's responsible: https://github.com/dimforge/nalgebra/blob/1bc919e0dbf2f7e83fab8aed37c1a06fe1b4fc93/src/geometry/point_conversion.rs#L76-L85
It calls `to_homogeneous`. I'm sure this is useful in some cases, but it seems way too magical to me. Personally, I would remove this conversion as too confusing, but maybe someone with a more extensive math background than me would disagree. In any case, I wanted to leave my feedback.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.