Compiler errors when upgrading to 0.22

I just upgraded to 0.22 and am getting various compiler errors for unsatisfied traits.

Am I missing something overall that I’m supposed to do in the new version?

Some examples:

Matrix4::new_orthographic

error[E0277]: the trait bound `{float}: nalgebra::RealField` is not satisfied
  --> src\renderer.rs:85:26
   |
85 |         let camera_mat = Matrix4::new_orthographic( 0.0, stage_area.width as f32, 0.0, stage_area.height as f32, -100.0, 100.0);
   |                          ^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `nalgebra::RealField` is not implemented for `{float}`
   |
   = note: required by `nalgebra::base::cg::<impl nalgebra::Matrix<N, nalgebra::U4, nalgebra::U4, <nalgebra::DefaultAllocator as nalgebra::allocator::Allocator<N, nalgebra::U4, nalgebra::U4>>::Buffer>>::new_orthographic`

Unit::new_normalize

error[E0277]: the trait bound `{float}: nalgebra::ComplexField` is not satisfied
  --> src\systems.rs:45:44
   |
45 |             let axis = Unit::new_normalize(Vector3::new(0.0, 0.0, 1.0));
   |                                            ^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `nalgebra::ComplexField` is not implemented for `{float}`
   |
   = help: the following implementations were found:
             <nalgebra::Complex<N> as nalgebra::ComplexField>
   = note: required because of the requirements on the impl of `nalgebra::SimdComplexField` for `{float}`
   = note: required because of the requirements on the impl of `nalgebra::Normed` for `nalgebra::Matrix<{float}, nalgebra::U3, nalgebra::U1, nalgebra::ArrayStorage<{float}, nalgebra::U3, nalgebra::U1>>`
   = note: required by `nalgebra::Unit::<T>::new_normalize`

UnitQuaternion::from_axis_angle

error[E0277]: the trait bound `{float}: nalgebra::RealField` is not satisfied
   --> src\systems.rs:46:26
    |
46  |             let coords = UnitQuaternion::from_axis_angle(&axis, value.to_radians()).coords;
    |                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `nalgebra::RealField` is not implemented for `{float}`
    |
   ::: C:\Users\david\.cargo\registry\src\github.com-1ecc6299db9ec823\nalgebra-0.22.0\src\geometry\quaternion_construction.rs:223:13
    |
223 |         SB: Storage<N, U3>,
    |             -------------- required by this bound in `nalgebra::geometry::quaternion_construction::<impl nalgebra::Unit<nalgebra::Quaternion<N>>>::from_axis_angle`
    |
    = note: required because of the requirements on the impl of `nalgebra::SimdRealField` for `{float}`

Note that I also get an error when using more explicit types of float:

error[E0277]: the trait bound `f32: nalgebra::RealField` is not satisfied
  --> src\renderer.rs:85:39
   |
85 | ...   let camera_mat:Matrix4<f32> = Matrix4::new_orthographic( 0.0f32, stage_area.width as f32, 0.0f32, stage_area.height as f32, -100.0f...
   |                                     ^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `nalgebra::RealField` is not implemented for `f32`
   |
   = note: required by `nalgebra::base::cg::<impl nalgebra::Matrix<N, nalgebra::U4, nalgebra::U4, <nalgebra::DefaultAllocator as nalgebra::allocator::Allocator<N, nalgebra::U4, nalgebra::U4>>::Buffer>>::new_orthographic`

Also note that the whole chain of crates, as far as I can see, only uses 0.22:

app: https://github.com/dakom/shipyard-scenegraph/blob/71437d9599be45ab50c74ea17904631795ea4e0d/example/Cargo.toml#L14
crate: https://github.com/dakom/shipyard-scenegraph/blob/71437d9599be45ab50c74ea17904631795ea4e0d/crate/Cargo.toml#L18

Error in CI: https://github.com/dakom/shipyard-scenegraph/runs/1115876707#step:9:172

Hi!

One thing that changed in the latest version of nalgebra is the fact that the use of libm for special math functions is now opt-in. Therefore using default-features = false for nalgebra will disable all the RealField implementation because no implementation of sin, cos, etc. will be available. So if you are targeting a #[no-std] environment you can use the dependency:

nalgebra = { version = "0.22.0", default-features = [ "libm" ] }

If you are not targeting a #[no-std]environment, you can simply leave the default-features enabled.

1 Like

Hmm not sure why I had default features off… I am mostly targeting wasm though.

Thanks!

tiny nitpick in case anyone else lands here, default-features expects a boolean so I have

nalgebra = { version = "0.22.0", default-features = false, features = ["libm"] }