Avoid exception on plotting infite data points.
This commit is contained in:
parent
25134617c3
commit
140b56cee2
@ -154,9 +154,9 @@ public class DArray implements DIntDoubleMap{
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* returns the minmal image value
|
* returns the minimal image value
|
||||||
*
|
*
|
||||||
* @return the minmal image value
|
* @return the minimal image value
|
||||||
*/
|
*/
|
||||||
public double getMinImageValue(){
|
public double getMinImageValue(){
|
||||||
if( size == 0 ) throw
|
if( size == 0 ) throw
|
||||||
|
@ -19,6 +19,7 @@ package eva2.tools.chart2d;
|
|||||||
import java.awt.* ;
|
import java.awt.* ;
|
||||||
|
|
||||||
import eva2.tools.IntegerArrayList;
|
import eva2.tools.IntegerArrayList;
|
||||||
|
import eva2.tools.math.Mathematics;
|
||||||
|
|
||||||
/*==========================================================================*
|
/*==========================================================================*
|
||||||
* CLASS DECLARATION
|
* CLASS DECLARATION
|
||||||
@ -312,7 +313,10 @@ public class DPointSet extends DComponent
|
|||||||
max_x = x.getMaxImageValue(),
|
max_x = x.getMaxImageValue(),
|
||||||
min_y = y.getMinImageValue(),
|
min_y = y.getMinImageValue(),
|
||||||
max_y = y.getMaxImageValue();
|
max_y = y.getMaxImageValue();
|
||||||
|
if (Mathematics.areFinite(min_x, max_x, min_y, max_y) == -1)
|
||||||
rectangle = new DRectangle(min_x, min_y, max_x - min_x, max_y - min_y );
|
rectangle = new DRectangle(min_x, min_y, max_x - min_x, max_y - min_y );
|
||||||
|
// else
|
||||||
|
// System.err.println("Warning, rectangle not restored due to invalid (infinite/NaN) values.");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -18,6 +18,8 @@ package eva2.tools.chart2d;
|
|||||||
|
|
||||||
import java.awt.* ;
|
import java.awt.* ;
|
||||||
|
|
||||||
|
import eva2.tools.EVAERROR;
|
||||||
|
|
||||||
/*==========================================================================*
|
/*==========================================================================*
|
||||||
* CLASS DECLARATION
|
* CLASS DECLARATION
|
||||||
*==========================================================================*/
|
*==========================================================================*/
|
||||||
@ -133,10 +135,9 @@ public class DRectangle extends DComponent
|
|||||||
}
|
}
|
||||||
|
|
||||||
public DRectangle getIntersection( DRectangle r ){
|
public DRectangle getIntersection( DRectangle r ){
|
||||||
|
if( status == EMPTY || (r.status == EMPTY) ) return DRectangle.getEmpty();
|
||||||
if( status == ALL ) return (DRectangle)r.clone();
|
if( status == ALL ) return (DRectangle)r.clone();
|
||||||
if( status == EMPTY ) return DRectangle.getEmpty();
|
|
||||||
if( r.status == ALL ) return (DRectangle)clone();
|
if( r.status == ALL ) return (DRectangle)clone();
|
||||||
if( r.status == EMPTY ) return DRectangle.getEmpty();
|
|
||||||
DRectangle s = (DRectangle)this.clone();
|
DRectangle s = (DRectangle)this.clone();
|
||||||
if( s.x < r.x ){
|
if( s.x < r.x ){
|
||||||
s.x = r.x;
|
s.x = r.x;
|
||||||
@ -162,6 +163,7 @@ public class DRectangle extends DComponent
|
|||||||
*/
|
*/
|
||||||
public boolean insert( DPoint p ){
|
public boolean insert( DPoint p ){
|
||||||
if( p.x == Double.NaN || p.y == Double.NaN || Double.isInfinite(p.x) || Double.isInfinite(p.y)) {
|
if( p.x == Double.NaN || p.y == Double.NaN || Double.isInfinite(p.x) || Double.isInfinite(p.y)) {
|
||||||
|
EVAERROR.errorMsgOnce("Warning, inserted invalid point (NaN/infinity) in " + this.getClass().getSimpleName());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if( isAll() ) return false;
|
if( isAll() ) return false;
|
||||||
|
@ -370,6 +370,29 @@ public class Mathematics {
|
|||||||
return b;
|
return b;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if a number is valid (not NaN) and finite.
|
||||||
|
* @param v
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static boolean isFinite(double v) {
|
||||||
|
return (!Double.isInfinite(v) && !Double.isNaN(v));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if all numbers are valid (not NaN) and finite. Returns
|
||||||
|
* -1 if this is the case or the index of the first invalid number.
|
||||||
|
*
|
||||||
|
* @param v
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static int areFinite(double ... v) {
|
||||||
|
for (int i=0; i<v.length; i++) {
|
||||||
|
if (Double.isInfinite(v[i]) || Double.isNaN(v[i])) return i;
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check whether the given value lies within the interval in every
|
* Check whether the given value lies within the interval in every
|
||||||
* dimension.
|
* dimension.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user