I'm trying to clean up the CurveUtil class in the SincpacC3D, and ran across this issue. Can anyone explain it?
When run normally, the following code throws an exception on the call to GetFirstDerivative:
public static Vector2d Vector2dAfterParam(Curve oCurve, double param)
{
double dist = oCurve.GetDistanceAtParameter(param) + Epsilon;
double p = oCurve.GetParameterAtDistance(dist);
if (p - param < Epsilon)
{
p = param + Epsilon;
}
Vector3d vec = oCurve.GetFirstDerivative(p);
return vec.Convert2d(PlaneXY);
}
However, if I place a breakpoint on the line "double p = oCurve.GetParameterAtDistance(dist);" and simply hit "Resume" when the breakpoint is hit, the code runs with no errors. But without the breakpoint, p somehow ends up being equal to param + dist, which causes the exception in the call to GetFirstDerivative.
If I make this minor revision, the problem disappears:
public static Vector2d Vector2dAfterParam(Curve oCurve, double param)
{
double dist = oCurve.GetDistanceAtParameter(param) + Epsilon;
double p = oCurve.GetParameterAtDistance(dist);
double p2 = (p - param < Epsilon) ? param + Epsilon : param;
Vector3d vec = oCurve.GetFirstDerivative(p2);
return vec.Convert2d(PlaneXY);
}
It's got me stumped.