bitshifter / glam-rs

A simple and fast linear algebra library for games and graphics
Apache License 2.0
1.46k stars 145 forks source link

Inconsistent/missing scalar implementation of le/ge functions for Vec3A compared to sse2 #518

Closed EriKWDev closed 1 month ago

EriKWDev commented 2 months ago

On x86, this compiles fine.

point.le(&Vec3A::splat(0.5))

On macbook M2, which uses the implementation in src/f32/scalar as opposed to the src/f32/sse2/ which my stationary uses, we get the following compilation error

   |
26 | ...   point.le(&Vec3A::splat(0.5)) && point.ge(&Vec3A::splat(-0...
   |                      ^^ Vec3A is not an iterator
   |
  ::: glam-rs-bbec0e101ff938b0/29413fa/src/f32/scalar/vec3a.rs:30:1
   |
30 | pub struct Vec3A {
   | ---------------- doesn't satisfy Vec3A: Iterator
   |
   = note: the following trait bounds were not satisfied:
           Vec3A: Iterator
           which is required by &mut Vec3A: Iterator

I don't know what implementing Iterator has to do with supporting the PartialOrd trait, but rustc is very determined that is the reason.

bitshifter commented 2 months ago

That's an interesting one. Is point in this code also a Vec3A?

bitshifter commented 1 month ago

I have fixed this, it will break your code though sorry.

The SIMD types use Deref to give direct access to .x, .y etc. The return type used by Deref was deriving PartialOrd, which is why your code was working in this instance. It wasn't intended, PartialOrd was removed from glam types a long time ago (see #138, #168). You should be able to achieve the same thing with point.cmple(&Vec3A::splat(0.5)).all() I think.