From 5a36496701348b9c7f651b5b9646b1e88cd44b9b Mon Sep 17 00:00:00 2001 From: Jonathan Lambrechts <jonathan.lambrechts@uclouvain.be> Date: Wed, 2 May 2012 08:22:29 +0000 Subject: [PATCH] GeoInterpolation : fix old bug affecting periodic NURBS --- Geo/GeoInterpolation.cpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/Geo/GeoInterpolation.cpp b/Geo/GeoInterpolation.cpp index f5c06d0c49..c80e72785a 100644 --- a/Geo/GeoInterpolation.cpp +++ b/Geo/GeoInterpolation.cpp @@ -149,9 +149,15 @@ static Vertex InterpolateUBS(Curve *Curve, double u, int derivee) double t = (u - t1) / (t2 - t1); Vertex *v[4]; for(int i = 0; i < 4; i++) { - int k = iCurve - (periodic ? 1 : 2) + i; - if(k < 0) k = periodic ? k + NbControlPoints - 1 : 0; - if(k >= NbControlPoints) k = periodic ? k - NbControlPoints + 1: NbControlPoints - 1; + int k; + if (periodic) { + k = (iCurve - 1 + i) % (NbControlPoints - 1); + if (k < 0) + k += NbControlPoints - 1; + } + else { + k = std::max(0, std::min(iCurve - 2 + i, NbControlPoints -1)); + } List_Read(Curve->Control_Points, k , &v[i]); } -- GitLab