forked from imglib/imglib2-roi
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Apply patch for Bounds (issue imglib#60) and improve test
- Loading branch information
Showing
3 changed files
with
119 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
diff --git a/src/main/java/net/imglib2/roi/Bounds.java b/src/main/java/net/imglib2/roi/Bounds.java | ||
index 3f9e1ab..7c5145b 100644 | ||
--- a/src/main/java/net/imglib2/roi/Bounds.java | ||
+++ b/src/main/java/net/imglib2/roi/Bounds.java | ||
@@ -535,40 +535,60 @@ public abstract class Bounds< I extends RealInterval, B extends Bounds< I, B > > | ||
|
||
private final RealInterval i2; | ||
|
||
+ private final double[] min; | ||
+ | ||
+ private final double[] max; | ||
+ | ||
public UnionRealInterval( final RealInterval i1, final RealInterval i2 ) | ||
{ | ||
super( i1.numDimensions() ); | ||
this.i1 = i1; | ||
this.i2 = i2; | ||
assert ( i1.numDimensions() == i2.numDimensions() ); | ||
+ min = new double[ i1.numDimensions() ]; | ||
+ max = new double[ i1.numDimensions() ]; | ||
+ Arrays.fill( min, Double.NaN ); | ||
+ Arrays.fill( max, Double.NaN ); | ||
} | ||
|
||
@Override | ||
public double realMin( final int d ) | ||
{ | ||
- if ( Intervals.isEmpty( i1 ) ) | ||
+ if ( Double.isNaN( min[ d ] ) ) | ||
{ | ||
- if ( Intervals.isEmpty( i2 ) ) | ||
- return Double.POSITIVE_INFINITY; | ||
- return i2.realMin( d ); | ||
+ if ( Intervals.isEmpty( i1 ) ) | ||
+ { | ||
+ if ( Intervals.isEmpty( i2 ) ) | ||
+ min[ d ] = Double.POSITIVE_INFINITY; | ||
+ else | ||
+ min[ d ] = i2.realMin( d ); | ||
+ } | ||
+ else if ( Intervals.isEmpty( i2 ) ) | ||
+ min[ d] = i1.realMin( d ); | ||
+ else | ||
+ min[ d ] = Math.min( i1.realMin( d ), i2.realMin( d ) ); | ||
} | ||
- if ( Intervals.isEmpty( i2 ) ) | ||
- return i1.realMin( d ); | ||
- return Math.min( i1.realMin( d ), i2.realMin( d ) ); | ||
+ return min[ d ]; | ||
} | ||
|
||
@Override | ||
public double realMax( final int d ) | ||
{ | ||
- if ( Intervals.isEmpty( i1 ) ) | ||
+ if ( Double.isNaN( max[d] ) | ||
{ | ||
- if ( Intervals.isEmpty( i2 ) ) | ||
- return Double.NEGATIVE_INFINITY; | ||
- return i2.realMax( d ); | ||
+ if ( Intervals.isEmpty( i1 ) ) | ||
+ { | ||
+ if ( Intervals.isEmpty( i2 ) ) | ||
+ max[ d ] = Double.NEGATIVE_INFINITY; | ||
+ else | ||
+ max[ d ] = i2.realMax( d ); | ||
+ } | ||
+ else if ( Intervals.isEmpty( i2 ) ) | ||
+ max[ d ] = i1.realMax( d ); | ||
+ else | ||
+ max[ d ] = Math.max( i1.realMax( d ), i2.realMax( d ) ); | ||
} | ||
- if ( Intervals.isEmpty( i2 ) ) | ||
- return i1.realMax( d ); | ||
- return Math.max( i1.realMax( d ), i2.realMax( d ) ); | ||
+ return max[ d ]; | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters