euclid icon indicating copy to clipboard operation
euclid copied to clipboard

When the type is a floating-point number, precision issues may arise.

Open kongbai1996 opened this issue 2 months ago • 1 comments

The generic PartialEq implementation for Size2D directly uses ==, which loses precision when the type is float. Size3D and Point2D have similar issues. I added tests with floating-point numbers in the test_add function of Size2D, and indeed they failed:

let s1 = Size2D::new(0.1, 0.0);
let s2 = Size2D::new(0.2, 0.0);
assert_eq!(s1 + s2, Size2D::new(0.3, 0.0));
assert_eq!(s1 + &s2, Size2D::new(0.3, 0.0));

kongbai1996 avatar Nov 05 '25 03:11 kongbai1996