changeset 12597:4b8c66b9876f octave-forge

display error message and return -1 if point is outside knot span in findspan
author cdf
date Wed, 15 Apr 2015 08:54:20 +0000
parents 1bdb7ad5015b
children 866aebba15d0
files extra/nurbs/src/low_level_functions.cc
diffstat 1 files changed, 10 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/extra/nurbs/src/low_level_functions.cc	Wed Apr 15 08:53:35 2015 +0000
+++ b/extra/nurbs/src/low_level_functions.cc	Wed Apr 15 08:54:20 2015 +0000
@@ -21,7 +21,8 @@
 #include "low_level_functions.h"
 #include <iostream>
 
-octave_idx_type findspan(int n, int p, double u, const RowVector& U)
+octave_idx_type
+findspan (int n, int p, double u, const RowVector& U)
 
 // Find the knot span of the parametric point u. 
 //
@@ -70,12 +71,17 @@
 {
   // FIXME : this implementation has linear, rather than log complexity
   int ret = 0;
-  while ((ret++ < n) && (U(ret) <= u)) {
-  };
+  
+  if (u > U.xelem (U.numel () - 1) || u < U.xelem (0))
+    error ("Value %g is outside the knot span", u);
+  else
+    while ((ret++ < n) && (U(ret) <= u)) { };
+
   return (ret-1);
 }
 
-void basisfun(int i, double u, int p, const RowVector& U, RowVector& N)
+void
+basisfun (int i, double u, int p, const RowVector& U, RowVector& N)
 
 // Basis Function. 
 //