dimforge / dimforge/nalgebra

Proptest strategy to generate unit vectors does not always yield unit vectors

Open
#1,486 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

Hi,

I made the following proptest strategy:

```

use nalgebra::Unit;
use nalgebra::proptest::vector;
use proptest::prelude::*;

fn arbitrary_unit_vector() -> impl Strategy>> {
any::>()
.prop_filter("Non-zero vector", |v| v.norm() > 0.5)
.prop_map(|v| Unit::new_normalize(v))
}
```

Which I then use as follows:

```
#[test]
fn test_parametric_line_intersection(
intersection_point in arbitrary_point(),
v1 in arbitrary_unit_vector(),
v2 in arbitrary_unit_vector(),
min1 in -10.0 .. 0.0,
max1 in 0.0 .. 10.0,
min2 in -10.0 .. 0.0,
max2 in 0.0 .. 10.0,
)
```

Resulting in the error:

```
Test failed: assertion failed: v2.norm() > 0.5.
minimal failing input: intersection_point = [
0.0,
0.0,
0.0,
], v1 = [
[
0.0,
0.0,
-1.0,
],
], v2 = [
[
-0.0,
0.0,
0.0,
],
], min1 = 0.0, max1 = 0.0, min2 = 0.0, max2 = 0.0
successes: 0
local rejects: 0
global rejects: 0
thread 'geometry::intersection::tests::test_parametric_line_intersection' panicked at src/geometry/intersection.rs:178:13:
assertion failed: v1.norm() > 0.5
```

Note how `v2` has 0 norm, and a negative x-component, despite being wrapped in Unit.

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.