New user self-registration is disabled due to spam. Please email eigen-core-team @ if you need an account.
Before reporting a bug, please make sure that your Eigen version is up-to-date!
Bug 999 - AlignedBox Volume/Empty Test Disagree
Summary: AlignedBox Volume/Empty Test Disagree
Alias: None
Product: Eigen
Classification: Unclassified
Component: Geometry (show other bugs)
Version: 3.3 (current stable)
Hardware: All All
: Normal Wrong Result
Assignee: Nobody
Keywords: Documentation
Depends on:
Reported: 2015-04-16 21:46 UTC by Christopher J. Hanks
Modified: 2015-04-30 17:36 UTC (History)
4 users (show)


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>

    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?


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


-> 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:

Note You need to log in before you can comment on or make changes to this bug.