protected override void SolveInstance(IGH_DataAccess DA) { Rhino.Geometry.Curve rectangle = null; DA.GetData(0, ref rectangle); bool closedBool = rectangle.IsClosed; int spans = rectangle.SpanCount; int degree = rectangle.Degree; List <Rhino.Geometry.Point2d> originalPoints = new List <Point2d>(); List <double> xVals = new List <double>(); List <double> yVals = new List <double>(); if (closedBool != true || spans != 4 || degree != 1) { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Input curve is not a closed, linear quadrilateral."); return; } for (int i = 0; i < spans; i++) { Rhino.Geometry.Point3d cornerPoint = rectangle.PointAt(rectangle.SpanDomain(i).Min); Rhino.Geometry.Point2d flattenedCornerPoint = new Rhino.Geometry.Point2d(cornerPoint); originalPoints.Add(flattenedCornerPoint); xVals.Add(flattenedCornerPoint.X); yVals.Add(flattenedCornerPoint.Y); } Rhino.Geometry.LineCurve testCurveA = new Rhino.Geometry.LineCurve(originalPoints[0], originalPoints[2]); Rhino.Geometry.LineCurve testCurveB = new Rhino.Geometry.LineCurve(originalPoints[1], originalPoints[3]); if (testCurveA.GetLength() != testCurveB.GetLength()) { AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Input curve is not orthogonal, results are not guaranteed."); } Rhino.Geometry.Point2d topRightPoint = new Rhino.Geometry.Point2d(xVals.Max(), yVals.Max()); DA.SetData(1, topRightPoint); Rhino.Geometry.Point2d topLeftPoint = new Rhino.Geometry.Point2d(xVals.Min(), yVals.Max()); DA.SetData(2, topLeftPoint); Rhino.Geometry.Point2d bottomLeftPoint = new Rhino.Geometry.Point2d(xVals.Min(), yVals.Min()); DA.SetData(3, bottomLeftPoint); Rhino.Geometry.Point2d bottomRightPoint = new Rhino.Geometry.Point2d(xVals.Max(), yVals.Min()); DA.SetData(4, bottomRightPoint); List <Rhino.Geometry.Point2d> orderedPoints = new List <Point2d>(); orderedPoints.Add(topRightPoint); orderedPoints.Add(topLeftPoint); orderedPoints.Add(bottomLeftPoint); orderedPoints.Add(bottomRightPoint); DA.SetDataList(0, orderedPoints); //TODO: Check for rotation. No warnings will be raised if input is orthogonal rotated object, but corners will not be accurate. }