[opengtl-commits] [310] fix interpolate1D and interpolatecubic1D not returning the correct value near the extremity

[ Thread Index | Date Index | More lists.tuxfamily.org/opengtl-commits Archives ]


Revision: 310
Author:   cyrille
Date:     2008-08-01 10:41:36 +0200 (Fri, 01 Aug 2008)

Log Message:
-----------
fix interpolate1D and interpolatecubic1D not returning the correct value near the extremity

Modified Paths:
--------------
    trunk/OpenGTL/OpenCTL/OpenCTL/ctlstdlib.ctl
    trunk/OpenGTL/OpenCTL/tests/stdlib/interpolate.ctl


Modified: trunk/OpenGTL/OpenCTL/OpenCTL/ctlstdlib.ctl
===================================================================
--- trunk/OpenGTL/OpenCTL/OpenCTL/ctlstdlib.ctl	2008-07-31 20:05:45 UTC (rev 309)
+++ trunk/OpenGTL/OpenCTL/OpenCTL/ctlstdlib.ctl	2008-08-01 08:41:36 UTC (rev 310)
@@ -126,8 +126,8 @@
 
 float interpolate1D (float table[][2], float p)
 {
-  if( p < table[0][0] ) return table[0][1];
-  if( p > table[table.size-1][0] ) return table[table.size-1][1];
+  if( p <= table[0][0] ) return table[0][1];
+  if( p >= table[table.size-1][0] ) return table[table.size-1][1];
   
   for( int i = 0; i < table.size - 1; ++i )
   {
@@ -142,8 +142,8 @@
 
 float interpolateCubic1D (float table[][2], float p)
 {
-  if( p < table[0][0] ) return table[0][1];
-  if( p > table[table.size-1][0] ) return table[table.size-1][1];
+  if( p <= table[0][0] ) return table[0][1];
+  if( p >= table[table.size-1][0] ) return table[table.size-1][1];
   
   for( int i = 0; i < table.size - 1; ++i )
   {

Modified: trunk/OpenGTL/OpenCTL/tests/stdlib/interpolate.ctl
===================================================================
--- trunk/OpenGTL/OpenCTL/tests/stdlib/interpolate.ctl	2008-07-31 20:05:45 UTC (rev 309)
+++ trunk/OpenGTL/OpenCTL/tests/stdlib/interpolate.ctl	2008-08-01 08:41:36 UTC (rev 310)
@@ -6,13 +6,17 @@
 
   int errorcount = 0;
   Test::checkNearEqual( interpolate1D( table,-1.0  ), 1.0, errorcount);
+  Test::checkNearEqual( interpolate1D( table, 0.0  ), 1.0, errorcount);
   Test::checkNearEqual( interpolate1D( table, 2.0  ), 5.0, errorcount);
   Test::checkNearEqual( interpolate1D( table, 0.5  ), 4.0, errorcount);
   Test::checkNearEqual( interpolate1D( table, 0.75 ), 4.5, errorcount);
+  Test::checkNearEqual( interpolate1D( table, 1.0  ), 5.0, errorcount);
   Test::checkNearEqual( interpolate1D( table, 0.25 ), 2.5, errorcount);
   Test::checkNearEqual( interpolateCubic1D( table,-1.0 ), 1.0, errorcount);
+  Test::checkNearEqual( interpolateCubic1D( table, 0.0  ), 1.0, errorcount);
   Test::checkNearEqual( interpolateCubic1D( table, 2.0 ), 5.0, errorcount);
   Test::checkNearEqual( interpolateCubic1D( table, 0.5 ), 4.0, errorcount);
+  Test::checkNearEqual( interpolateCubic1D( table, 1.0  ), 5.0, errorcount);
   
   
   return errorcount;


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/