This bugzilla service is closed. All entries have been migrated to https://gitlab.com/libeigen/eigen

Bug 999

Summary: AlignedBox Volume/Empty Test Disagree
Product: Eigen Reporter: Christopher J. Hanks <web>
Component: GeometryAssignee: Nobody <eigen.nobody>
Status: RESOLVED FIXED    
Severity: Wrong Result CC: chtz, gael.guennebaud, hauke.heibel, jacob.benoit.1
Priority: Normal Keywords: Documentation
Version: 3.3 (current stable)   
Hardware: All   
OS: All   
Whiteboard:

Description Christopher J. Hanks 2015-04-16 21:46:40 UTC
In an AlignedBox<double 3> structure, two boxes can be fashioned such that their intersection yields a new box with (::volume() > 0) that (::isEmpty() == true).


#include <iostream>
#include <Eigen/Eigen>

int
main()
{
    Eigen::AlignedBox<double, 3> b0(
        Eigen::Vector3d(-1, -1, -1),
        Eigen::Vector3d( 0,  0,  0));

    Eigen::AlignedBox<double, 3> b1(
        Eigen::Vector3d(-1,  2,  2),
        Eigen::Vector3d( 0,  0,  0));

    std::cerr << std::boolalpha
              << (b1.intersection(b0)).volume()  << "\n"
              << (b1.intersection(b0)).isEmpty() << "\n";
    // Prints out:
    // 4
    // true
    return 0;
}
Comment 1 Gael Guennebaud 2015-04-17 09:55:43 UTC
Indeed. Actually this problem is more general as many other methods fail if along at least one dimension the minimum entry is greater than the maximum. They include:

sizes(), volume(), diagonal()

-> all based on sizes(). shall we clamp negative sizes to zero?


sample()

-> it currently returns the min coeff, but that's undocumented


squaredExteriorDistance()

-> what should be the behavior? shall we use the min coeff as for sample?
Comment 2 Christoph Hertzberg 2015-04-17 11:15:44 UTC
You also have b1.volume()==4 and b1.isEmpty(), so b1 is already ill-formed.

I think the problem is that it is not really specified/documented how Eigen handles ill-formed boxes -- also it is not evident that the _min, _max constructor does not automatically make a valid box from the passed corner points.
Comment 3 Christoph Hertzberg 2015-04-20 19:06:12 UTC
I would vote for just improving the documentation (mostly saying that the result of any method is undefined for empty boxes), but keep the current behavior here. I don't think that volume()>0 should be considered in any way equivalent to !isEmpty(). E.g., there is also the case of a one-point box, which has volume 0, but is not empty.

We may consider adding a constructor which automatically takes min and max of the input vectors, if that is required a lot.
Making this the default probably breaks existing code (not sure, if constructing an explicit empty box has any use-case, though)
Comment 4 Christoph Hertzberg 2015-04-30 17:36:08 UTC
I clarified in the documentation that empty boxes can lead to undefined behavior:
https://bitbucket.org/eigen/eigen/commits/cf8979c54
https://bitbucket.org/eigen/eigen/commits/16d9b3559
Comment 5 Nobody 2019-12-04 14:31:55 UTC
-- GitLab Migration Automatic Message --

This bug has been migrated to gitlab.com's GitLab instance and has been closed from further activity.

You can subscribe and participate further through the new bug through this link to our GitLab instance: https://gitlab.com/libeigen/eigen/issues/999.