georust / geo

Geospatial primitives and algorithms for Rust
https://crates.io/crates/geo
Other
1.53k stars 198 forks source link

Tests fail on main due to floating point imprecision. #1095

Closed andriyDev closed 11 months ago

andriyDev commented 11 months ago

I ran the tests on main and got test failures for the following:

failures:

---- algorithm::affine_ops::tests::test_transform_composition stdout ----
thread 'algorithm::affine_ops::tests::test_transform_composition' panicked at 'assertion failed: `(left == right)`
  left: `[[4.000000000000001, 0.0, 0.0], [0.0, 4.000000000000001, 0.0], [0.0, 0.0, 1.0]]`,
 right: `[[4.0, 0.0, 0.0], [0.0, 4.0, 0.0], [0.0, 0.0, 1.0]]`', geo\src\algorithm\affine_ops.rs:464:9
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

---- algorithm::rotate::test::test_rotate_around_point_arbitrary stdout ----
thread 'algorithm::rotate::test::test_rotate_around_point_arbitrary' panicked at 'assertion failed: `(left == right)`
  left: `Point(Coord { x: -10.50609665440988, y: 20.564971157455595 })`,
 right: `Point(Coord { x: -10.506096654409877, y: 20.564971157455595 })`', geo\src\algorithm\rotate.rs:360:9

---- algorithm::rotate::test::test_rotate_multipoints stdout ----
thread 'algorithm::rotate::test::test_rotate_multipoints' panicked at 'assert_relative_eq!(multi_points.rotate_around_center(45.), expected_for_center)

    left  = MultiPoint([Point(Coord { x: 0.6464466094067263, y: -0.5606601717798214 }), Point(Coord { x: 0.6464466094067263, y: 0.8535533905932737 }), Point(Coord { x: 1.353553390593274, y: 1.5606601717798214 })])
    right = MultiPoint([Point(Coord { x: 0.6464466094067262, y: -0.5606601717798212 }), Point(Coord { x: 0.6464466094067263, y: 0.8535533905932737 }), Point(Coord { x: 1.353553390593274, y: 1.560660171779821 })])

', geo\src\algorithm\rotate.rs:200:9

failures:
    algorithm::affine_ops::tests::test_transform_composition
    algorithm::rotate::test::test_rotate_around_point_arbitrary
    algorithm::rotate::test::test_rotate_multipoints

These all are just minor floating point errors. I am running on Windows 10, using MSVC, on an i7-8700K. This occurs on both debug and release builds. We likely just need to add approx checks for these tests.

andriyDev commented 11 months ago

One of the doctests also fails.

failures:

---- geo\src\algorithm\rotate.rs - algorithm::rotate::Rotate::rotate_around_point (line 66) stdout ----
Test executable failed (exit code: 101).

stderr:
thread 'main' panicked at 'assertion failed: `(left == right)`
  left: `LineString([Coord { x: 2.9289321881345245, y: 7.0710678118654755 }, Coord { x: 10.0, y: 7.0710678118654755 }, Coord { x: 17.071067811865476, y: 7.0710678118654755 }])`,
 right: `LineString([Coord { x: 2.9289321881345245, y: 7.071067811865475 }, Coord { x: 10.0, y: 7.0710678118654755 }, Coord { x: 17.071067811865476, y: 7.0710678118654755 }])`', geo\src\algorithm\rotate.rs:19:1