+ // Calculate the tangents.
+ TColgp_Array1OfVec aTangents(1, aPointCount);
+ Handle(TColStd_HArray1OfBoolean) aTangentFlags =
+ new TColStd_HArray1OfBoolean(1, aPointCount);
+ GeomAPI_Interpolate aInterpolator(thePoints, theIsClosed, 0);
+ if (aPointCount == 2)
+ {
+ aTangentFlags->SetValue(1, Standard_False);
+ aTangentFlags->SetValue(2, Standard_False);
+ }
+ else
+ {
+ for (Standard_Integer aPN = 1; aPN <= aPointCount; ++aPN)
+ {
+ gp_Vec aTangent;
+ if (aPN != 1 || theIsClosed)
+ {
+ const Standard_Integer aPN1 = (aPN != 1) ? (aPN - 1) : aPointCount;
+ aTangent = gp_Vec(thePoints->Value(aPN1),
+ thePoints->Value(aPN)).Normalized();
+ }
+ if (aPN < aPointCount || theIsClosed)
+ {
+ const Standard_Integer aPN2 = (aPN != aPointCount) ? (aPN + 1) : 1;
+ const gp_Vec aTangent2 = aTangent +
+ gp_Vec(thePoints->Value(aPN), thePoints->Value(aPN2)).Normalized();
+ if (aTangent2.SquareMagnitude() >= Precision::SquareConfusion())
+ {
+ aTangent = aTangent2.Normalized();
+ }
+ else
+ {
+ aTangent = -aTangent;
+ }
+ }
+ aTangents.SetValue(aPN, aTangent);
+ aTangentFlags->SetValue(aPN, Standard_True);
+ }
+ }
+
+ // Interpolate.
+ aInterpolator.Load(aTangents, aTangentFlags, Standard_False);
+ aInterpolator.Perform();
+ const bool aResult = (aInterpolator.IsDone() == Standard_True);
+ if (aResult)
+ {
+ theBSpline = aInterpolator.Curve();
+ }
+ return aResult;
+}