/// <summary> /// This is the method that actually does the work. /// </summary> /// <param name="da">The DA object can be used to retrieve data from input parameters and /// to store data in output parameters.</param> protected override void GrasshopperBootstrapSolveInstance(IGH_DataAccess da) { // First, we need to retrieve all data from the input parameters. // We'll start by declaring variables and assigning them starting values. Plane plane = Plane.WorldXY; double radius0 = 0.0; double radius1 = 0.0; int turns = 0; // Then we need to access the input parameters individually. // When data cannot be extracted from a parameter, we should abort this method. // GHB note: There is no need to wrap these getters in a return - components will not // execute if non-optional values are not provided by users da.GetData(0, ref plane); da.GetData(1, ref radius0); da.GetData(2, ref radius1); da.GetData(3, ref turns); // We should now validate the data and warn the user if invalid data is supplied. if (radius0 < 0.0) { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Inner radius must be bigger than or equal to zero"); return; } if (radius1 <= radius0) { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Outer radius must be bigger than the inner radius"); return; } if (turns <= 0) { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Spiral turn count must be bigger than or equal to one"); return; } LogTiming("Initial setup"); // Debug Info // GHB note: accessing these shortcuts just to show they exist and to prevent the build warning var aTolerance = DocAngleTolerance; var dTolerance = DocAbsTolerance; // We're set to create the spiral now. To keep the size of the SolveInstance() method small, // the actual functionality will be in a different method: // GHB note: the function here has been shifted to a separate file (GeometryCreation.cs). using (Curve spiral = ModularityDemo.CreateSpiral(plane, radius0, radius1, turns)) { // Finally assign the spiral to the output parameter. da.SetData(0, spiral); } LogTiming("Creating spiral"); // Debug Info LogGeneral(string.Format("Angle tolerance: {0}\nAbsolute tolerance: {1}", aTolerance, dTolerance)); }
public void TestCreateSpiral() { var stubInnerRadius = 10.0; var stubOuterRadius = 100.0; var stubTurns = 5; var stubPlane = new Plane(new Point3d(0, 0, 0), new Vector3d(0, 0, 1)); using (var spiral = ModularityDemo.CreateSpiral(stubPlane, stubInnerRadius, stubOuterRadius, stubTurns)) { var spiralPolyCurve = spiral as PolyCurve; var spiralSegments = spiralPolyCurve.Explode().Length; Assert.AreEqual(spiralSegments, 10); // Should have 10 segments } }