/// <summary> /// Get the one and only CurveLoop if it exists and is non-empty, otherwise null. /// </summary> /// <returns>The one and only CurveLoop if it exists and is non-empty.</returns> public CurveLoop GetTheCurveLoop() { if ((CurveLoops?.Count ?? 0) != 1) { return(null); } CurveLoop theCurveLoop = CurveLoops[0]; return(((theCurveLoop?.NumberOfCurves() ?? 0) > 0) ? theCurveLoop : null); }
/// <summary> /// Attempt to create a single curve from a curve loop composed of linear segments. /// </summary> /// <param name="curveLoop">The curve loop.</param> /// <param name="pointXYZs">The original points from which the curve loop was created.</param> /// <returns>The curve, if the curve loop is linear, or null.</returns> /// <remarks>Note that the routine does not actually check that the curveLoop is composed /// of line segments, or that the point array matches the curve loop in any way.</remarks> public static Curve CreateCurveFromPolyCurveLoop(CurveLoop curveLoop, IList <XYZ> pointXYZs) { if (curveLoop == null) { return(null); } int numCurves = curveLoop.NumberOfCurves(); if (numCurves == 0) { return(null); } if (numCurves == 1) { Curve originalCurve = curveLoop.First(); if (originalCurve != null) { return(originalCurve.Clone()); } return(null); } if (pointXYZs == null) { return(null); } int numPoints = pointXYZs.Count; // If we are here, we are sure that the number of points must be at least 3. XYZ firstPoint = pointXYZs[0]; XYZ secondPoint = pointXYZs[1]; XYZ vectorToTest = (secondPoint - firstPoint).Normalize(); bool allAreCollinear = true; for (int ii = 2; ii < numPoints; ii++) { XYZ vectorTmp = (pointXYZs[ii] - firstPoint).Normalize(); if (!vectorTmp.IsAlmostEqualTo(vectorToTest)) { allAreCollinear = false; break; } } if (allAreCollinear) { return(Line.CreateBound(firstPoint, pointXYZs[numPoints - 1])); } return(null); }
/// <summary> /// Set the representation of the curve based on one CurveLoop. /// </summary> /// <param name="curveLoop">The one CurveLoop.</param> public void SetCurveLoop(CurveLoop curveLoop) { Curve = null; CurveLoops = null; if (curveLoop == null) { return; } if (curveLoop.NumberOfCurves() == 1) { Curve = curveLoop.GetCurveLoopIterator().Current; } CurveLoops = new List <CurveLoop>(); CurveLoops.Add(curveLoop); }