Code Red > .NET

Mystery Exception

(1/1)

sinc:
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:


--- Code: ---        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);
        }

--- End code ---
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:

--- Code: ---        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);
        }

--- End code ---

It's got me stumped.

sinc:
Upon further testing, it looks as though that "minor revision" I mentioned above actually does NOT work.  It no longer throws an exception, but neither does it return the correct results.

This seems to be the only thing that actually works:


--- Code: ---        public static Vector2d Vector2dAfterParam(Curve oCurve, double param)
        {
            double dist = oCurve.GetDistanceAtParameter(param) + Epsilon;
            double p = oCurve.GetParameterAtPoint(oCurve.GetPointAtDist(dist));
            if (p - param < Epsilon)
            {
                p = param + Epsilon;
            }
            Vector3d vec = oCurve.GetFirstDerivative(p);
            return vec.Convert2d(PlaneXY);
        }

--- End code ---

Basically, instead of using GetParameterAtDistance, I use GetPointAtDist to get a point, then use GetParameterAtPoint.

sinc:
OK, from what I've been able to determine, this issue only affects Civil-3D elements such as parcels and feature lines (aka ImpCurve entities).  It does not affect polylines.

Apparently, if the Curve is a C3D element, then Curve.GetParameterAtDistance() is returning the distance, not the parameter.

The strange thing is it returns the parameter the first time I call the method after loading the .DLL, however every successive call returns the distance.  Why would it return the correct value the first time it is called, and then return incorrect values from then on?

Navigation

[0] Message Index

Go to full version