[opengtl-commits] [706] add lengths function

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


Revision: 706
Author:   cyrille
Date:     2009-03-26 19:39:55 +0100 (Thu, 26 Mar 2009)

Log Message:
-----------
add lengths function

Modified Paths:
--------------
    trunk/OpenGTL/OpenShiva/OpenShiva/shivastdlib.shiva
    trunk/OpenGTL/OpenShiva/tests/CMakeLists.txt

Added Paths:
-----------
    trunk/OpenGTL/OpenShiva/tests/stdlib/
    trunk/OpenGTL/OpenShiva/tests/stdlib/CMakeLists.txt
    trunk/OpenGTL/OpenShiva/tests/stdlib/length.shiva


Modified: trunk/OpenGTL/OpenShiva/OpenShiva/shivastdlib.shiva
===================================================================
--- trunk/OpenGTL/OpenShiva/OpenShiva/shivastdlib.shiva	2009-03-26 18:39:08 UTC (rev 705)
+++ trunk/OpenGTL/OpenShiva/OpenShiva/shivastdlib.shiva	2009-03-26 18:39:55 UTC (rev 706)
@@ -56,4 +56,20 @@
     if( a > max ) return max;
     return a;
   }
+  // Lengths functions
+  float length( float2 v )
+  {
+    v *= v;
+    return sqrt(v.x + v.y);
+  }
+  float length( float3 v )
+  {
+    v *= v;
+    return sqrt(v.x + v.y + v.z);
+  }
+  float length( float4 v )
+  {
+    v *= v;
+    return sqrt(v.x + v.y + v.z + v.a);
+  }
 }

Modified: trunk/OpenGTL/OpenShiva/tests/CMakeLists.txt
===================================================================
--- trunk/OpenGTL/OpenShiva/tests/CMakeLists.txt	2009-03-26 18:39:08 UTC (rev 705)
+++ trunk/OpenGTL/OpenShiva/tests/CMakeLists.txt	2009-03-26 18:39:55 UTC (rev 706)
@@ -6,3 +6,4 @@
 add_subdirectory( imagegenerators )
 add_subdirectory( convolution )
 add_subdirectory( raw )
+add_subdirectory( stdlib )

Added: trunk/OpenGTL/OpenShiva/tests/stdlib/CMakeLists.txt
===================================================================
--- trunk/OpenGTL/OpenShiva/tests/stdlib/CMakeLists.txt	                        (rev 0)
+++ trunk/OpenGTL/OpenShiva/tests/stdlib/CMakeLists.txt	2009-03-26 18:39:55 UTC (rev 706)
@@ -0,0 +1,9 @@
+
+set( TESTS_FILES
+  length.shiva
+  )
+
+FOREACH( TEST_FILE ${TESTS_FILES} )
+  ADD_TEST(${TEST_FILE} ${SHIVATESTER} ${CMAKE_CURRENT_SOURCE_DIR}/${TEST_FILE})
+ENDFOREACH( TEST_FILE )
+

Added: trunk/OpenGTL/OpenShiva/tests/stdlib/length.shiva
===================================================================
--- trunk/OpenGTL/OpenShiva/tests/stdlib/length.shiva	                        (rev 0)
+++ trunk/OpenGTL/OpenShiva/tests/stdlib/length.shiva	2009-03-26 18:39:55 UTC (rev 706)
@@ -0,0 +1,21 @@
+kernel LengthTestKernel
+{
+  void evaluatePixel(out pixel result)
+  {
+  }
+  bool nearlyEqual( float v1, float v2)
+  {
+    return fabs(v1 - v2) < 1e-5;
+  }
+  int runTest()
+  {
+    int count = 0;
+    float2 v1 = { 1, 2};
+    if( not nearlyEqual( length(v1), sqrt(5) ) ) ++count;
+    float3 v2 = { 1, 2, 3};
+    if( not nearlyEqual( length(v2), sqrt(14) ) ) ++count;
+    float4 v3 = { 1, 2, 3, 4};
+    if( not nearlyEqual( length(v3), sqrt(30) ) ) ++count;
+    return count;
+  }
+}


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