Sample Code
List ExtractBreakCurvesByGaps(
Curve curve, // Input base curve
List centers, // Sequence of brick centers
double threshold_L, // Minimum allowed length
bool closedcrv_or_not, // Whether the curve is closed
tolerance_0, tolerance_1, tolerance_2 // Different tolerance strategies
)
{
List breakCurves = new List();
// Basic condition check
if (centers == null || centers.Count < 2 || curve == null || !curve.IsValid)
return breakCurves;
int count = centers.Count;
// Iterate through sub-curves between adjacent brick centers
for (int i = 0; i < count - 1; i++)
{
Point3d pt1 = centers[i];
Point3d pt2 = centers[i + 1];
double t1, t2;
bool succ1 = curve.ClosestPoint(pt1, out t1);
bool succ2 = curve.ClosestPoint(pt2, out t2);
if (succ1 && succ2 && Math.Abs(t1 - t2) > 1e-6)
{
Curve subcurve = curve.Trim(t1, t2);
if (subcurve != null && subcurve.IsValid &&
subcurve.GetLength() > tolerance_2 * threshold_L)
{ breakCurves.Add(subcurve); }
}
}
// Handle connection between end and start
Point3d pt_last = centers[count - 1];
Point3d pt_other = closedcrv_or_not ? centers[0] : curve.PointAtEnd;
double tA, tB;
bool sA = curve.ClosestPoint(pt_last, out tA);
bool sB = curve.ClosestPoint(pt_other, out tB);
if (sA && sB && Math.Abs(tA - tB) > 1e-6)
{
Curve subcurve = curve.Trim(tA, tB);
if (subcurve != null && subcurve.IsValid &&
subcurve.GetLength() > tolerance_1 * threshold_L)
{ breakCurves.Add(subcurve); }
}
// Handle start condition for open curves
if (!closedcrv_or_not)
{
pt_last = centers[0];
pt_other = curve.PointAtStart;
sA = curve.ClosestPoint(pt_last, out tA);
sB = curve.ClosestPoint(pt_other, out tB);
if (sA && sB && Math.Abs(tA - tB) > 1e-6)
{
Curve subcurve = curve.Trim(tB, tA);
if (subcurve != null && subcurve.IsValid &&
subcurve.GetLength() > tolerance_0 * threshold_L)
{ breakCurves.Add(subcurve); }
}
}
return breakCurves;
}