diff --git a/Geo/GModelIO_GEO.cpp b/Geo/GModelIO_GEO.cpp index cb0a950fb0bd4d76a0eb676df1c27158ff38ff87..78967d1961238958eb17ae7211ebd76994509eef 100644 --- a/Geo/GModelIO_GEO.cpp +++ b/Geo/GModelIO_GEO.cpp @@ -258,6 +258,10 @@ bool GEO_Internals::addBezier(int num, const std::vector<int> &vertexTags) Msg::Error("GEO edge with tag %d already exists", num); return false; } + if(vertexTags.size() < 4){ + Msg::Error("Bezier curve requires at least 4 control points"); + return false; + } List_T *tmp = List_Create(2, 2, sizeof(int)); for(unsigned int i = 0; i < vertexTags.size(); i++){ int t = vertexTags[i]; diff --git a/Geo/GeoInterpolation.cpp b/Geo/GeoInterpolation.cpp index 16f88b4893e0d8840d9c5413abcabab28ce7bf85..598ce2e5638aff2d195c3a81de6820ed7a3a5be0 100644 --- a/Geo/GeoInterpolation.cpp +++ b/Geo/GeoInterpolation.cpp @@ -12,8 +12,6 @@ #define SQU(a) ((a)*(a)) -// Cubic spline : - /* static void InterpolateBezier(Vertex *v[4], double t, Vertex &V) { @@ -181,6 +179,11 @@ SPoint2 InterpolateCubicSpline(Vertex *v[4], double t, double mat[4][4], static Vertex InterpolateBezier(Curve *Curve, double u, int derivee) { int NbCurves = (List_Nbr(Curve->Control_Points) - 1) / 3; + if(NbCurves <= 0){ + Msg::Error("Bezier curve requires at least 4 control points"); + Vertex V; + return V; + } int iCurve = (int)floor(u * (double)NbCurves); if(iCurve >= NbCurves) iCurve = NbCurves - 1; // u = 1 if(iCurve <= 0) iCurve = 0; @@ -240,7 +243,7 @@ static Vertex InterpolateUBS(Curve *Curve, double u, int derivee) return V; } else - // return InterpolateCubicSpline(v, t, Curve->mat, derivee, t1, t2); + // return InterpolateCubicSpline(v, t, Curve->mat, derivee, t1, t2); return InterpolateCubicSpline(v, t); } @@ -557,7 +560,7 @@ static Vertex TransfiniteQua(Vertex c1, Vertex c2, Vertex c3, Vertex c4, s1.Pos.Y, s2.Pos.Y, s3.Pos.Y, s4.Pos.Y, u, v); V.Pos.Z = TRAN_QUA(c1.Pos.Z, c2.Pos.Z, c3.Pos.Z, c4.Pos.Z, s1.Pos.Z, s2.Pos.Z, s3.Pos.Z, s4.Pos.Z, u, v); - return (V); + return V; } // Transfinite interpolation on a triangle :