I am trying to offset a polyline, so that the offsetted curve is within a predefined boundary.

Curiously, the code only works if the original polyline contains more than one segment (ie. is not a line).

What am I doing wrong here?

Thanks!

```
private void RunScript(Polyline poly, double distance, Polyline Boundary, ref object A)
{
Curve myCrv = new NurbsCurve(poly.ToNurbsCurve());
Vector3d tangent = new Vector3d(myCrv.TangentAt(0.5)); //gets unit tangent
bool rot = tangent.Rotate(1.5708, new Vector3d(0, 0, 1));
Point3d testPt = new Point3d(myCrv.PointAt(0.5) + tangent * 0.05);
if (!(IsInside(testPt, Boundary))) //IsInside tests if a point is within a polyline boundary
tangent = tangent * (-1);
//do offset
Curve[] offsetCrv = myCrv.Offset(testPt, tangent, distance, 0.01, CurveOffsetCornerStyle.Sharp);
A = offsetCrv;
}
```