servo / euclid

Geometry primitives (basic linear algebra) for Rust
Other
458 stars 102 forks source link

Difference in behavior in `from_points` methods #390

Closed kyren closed 4 years ago

kyren commented 4 years ago

I noticed today that there's a difference in behavior between Rect::from_points and Box2D::from_points.

Rect::from_points if given a single point will create a 0-sized rect whose origin is the single given point, this is exactly what I would have expected:

https://docs.rs/euclid/0.20.6/src/euclid/rect.rs.html#279-311

However, Box2D::from_points if given a single point will return Box2D::zero(), which is entirely not what I would have expected:

https://docs.rs/euclid/0.20.6/src/euclid/box2d.rs.html#284-329

Are you open to changing the behavior on Box2D / Box3D? This is very unexpected behavior for me, especially considering a zero volume box can't really sensibly be an error condition (at least in the way it works now):

    let p = Point2D::new(1., 2.);

    // Box is [(0, 0), (0, 0)]
    let b1 = Box2D::from_points([p].iter().copied());

    // Box is zero volume box [(1, 2), (1, 2)]
    let b2 = Box2D::from_points([p, p].iter().copied());
nical commented 4 years ago

I agree that the Box2D/3D behavior is confusing, let's align it with Rect.