You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently, to indicate empty Intervals we use the condition that max < min (for some dimension) to indicate that an interval is empty.
The motivation for this is that it "works naturally" for intersection of intervals. The intersection of two intervals has the min at the maximum of the mins of the intersected intervals, and the max at the minimum of the maxs of the intersected intervals. When two non-overlapping intervals are intersected, or one ore both of the intersected intervals are empty, the result is automatically an empty interval by the above condition.
However, for union of intervals we have to be careful. Naturally, the union of two intervals has the min at the minimum of the mins of the unioned intervals, and the max at the maximum of the maxs of the unioned intervals.
However, if one or both of the intervals is empty (by the above condition), this may lead to incorrect results (i.e., the union of two empty intervals can become non-empty). Therefore we need additional isEmpty() checks. These may become costly, in particular if the unioned intervals need to do additional work to compute their respective min and max. See imglib/imglib2-roi#60.
Therefore, we should consider, adding a default boolean isIntervalEmpty() method to the Interval interface. The default implementation could check the max < min condition, but subclasses could implement the check for example by pre-computing a boolean isEmpty flag. The Intervals methods (e.g. Intervals.union()) would then use this method to implement the checks.
The default method should be called isIntervalEmpty instead of just isEmpty because it will be inherited for example by RandomAccessibleInterval, where the meaning of isEmpty would not be immediately clear.
I fully support adding default boolean isIntervalEmpty(), in fact when trying to fix imglib/imglib2-roi#60 I played around adding such a method and I agree that it will probably help.
Currently, to indicate empty Intervals we use the condition that
max < min
(for some dimension) to indicate that an interval is empty.The motivation for this is that it "works naturally" for intersection of intervals. The intersection of two intervals has the
min
at the maximum of themin
s of the intersected intervals, and themax
at the minimum of themax
s of the intersected intervals. When two non-overlapping intervals are intersected, or one ore both of the intersected intervals are empty, the result is automatically an empty interval by the above condition.However, for union of intervals we have to be careful. Naturally, the union of two intervals has the
min
at the minimum of themin
s of the unioned intervals, and themax
at the maximum of themax
s of the unioned intervals.However, if one or both of the intervals is empty (by the above condition), this may lead to incorrect results (i.e., the union of two empty intervals can become non-empty). Therefore we need additional
isEmpty()
checks. These may become costly, in particular if the unioned intervals need to do additional work to compute their respectivemin
andmax
. See imglib/imglib2-roi#60.Therefore, we should consider, adding a
default boolean isIntervalEmpty()
method to theInterval
interface. The default implementation could check themax < min
condition, but subclasses could implement the check for example by pre-computing a boolean isEmpty flag. TheIntervals
methods (e.g.Intervals.union()
) would then use this method to implement the checks.The default method should be called
isIntervalEmpty
instead of justisEmpty
because it will be inherited for example byRandomAccessibleInterval
, where the meaning ofisEmpty
would not be immediately clear.See #301, #300, imglib/imglib2-roi#60
The text was updated successfully, but these errors were encountered: