dimforge / dimforge/nalgebra

distance_squared should work with integers

Open
#751 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
Rust
Stars
4.8k
Forks
565
PR merge metrics
No merged PRs in 30d

Description

It looks like the ``distance_squared`` function only works with floats. It makes sense that the ``distance`` function does not work with integers due to the square rooting, but ``distances_squared`` does not have this limitation. Any input with only integers gives an integer output.

Throughout my code I have to constantly cast back and forth between ``Point`` and ``Point`` like:

```
let coords_as_f32 = Point3::new(coords.x as f32, coords.y as f32, coords.z as f32);
let chunk_pos_as_f32 = Point3::new(chunk_pos.x as f32, chunk_pos.y as f32, chunk_pos.z as f32);
if nalgebra::distance_squared(&coords_as_f32, &chunk_pos_as_f32) < RENDER_DISTANCE.pow(2) as f32 {
// ...
```

Which could be simplified to the following, if this arbitrary restriction was removed:

```
if nalgebra::distance_squared(&coords, &chunk_pos) < RENDER_DISTANCE.pow(2) {
// ...
```

Let me know if I am missing something, or just overlooked an existing function somewhere.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.