Avoid exception on plotting infite data points.

This commit is contained in:
Marcel Kronfeld 2010-09-22 08:26:27 +00:00
parent 25134617c3
commit 140b56cee2
4 changed files with 34 additions and 5 deletions

View File

@ -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(){
if( size == 0 ) throw

View File

@ -19,6 +19,7 @@ package eva2.tools.chart2d;
import java.awt.* ;
import eva2.tools.IntegerArrayList;
import eva2.tools.math.Mathematics;
/*==========================================================================*
* CLASS DECLARATION
@ -312,7 +313,10 @@ public class DPointSet extends DComponent
max_x = x.getMaxImageValue(),
min_y = y.getMinImageValue(),
max_y = y.getMaxImageValue();
rectangle = new DRectangle(min_x, min_y, max_x - min_x, max_y - min_y );
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 );
// else
// System.err.println("Warning, rectangle not restored due to invalid (infinite/NaN) values.");
}
/**

View File

@ -18,6 +18,8 @@ package eva2.tools.chart2d;
import java.awt.* ;
import eva2.tools.EVAERROR;
/*==========================================================================*
* CLASS DECLARATION
*==========================================================================*/
@ -133,10 +135,9 @@ public class DRectangle extends DComponent
}
public DRectangle getIntersection( DRectangle r ){
if( status == EMPTY || (r.status == EMPTY) ) return DRectangle.getEmpty();
if( status == ALL ) return (DRectangle)r.clone();
if( status == EMPTY ) return DRectangle.getEmpty();
if( r.status == ALL ) return (DRectangle)clone();
if( r.status == EMPTY ) return DRectangle.getEmpty();
DRectangle s = (DRectangle)this.clone();
if( s.x < r.x ){
s.x = r.x;
@ -162,6 +163,7 @@ public class DRectangle extends DComponent
*/
public boolean insert( DPoint p ){
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;
}
if( isAll() ) return false;

View File

@ -370,6 +370,29 @@ public class Mathematics {
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
* dimension.