diff --git a/ExampleFiles/Components/Elem2dFromBrep.gh b/ExampleFiles/Components/Elem2dFromBrep.gh new file mode 100644 index 000000000..618397e2b Binary files /dev/null and b/ExampleFiles/Components/Elem2dFromBrep.gh differ diff --git a/GsaGH/Helpers/GH/RhinoConversions.cs b/GsaGH/Helpers/GH/RhinoConversions.cs index 4c8d414ab..19c98abdd 100644 --- a/GsaGH/Helpers/GH/RhinoConversions.cs +++ b/GsaGH/Helpers/GH/RhinoConversions.cs @@ -625,81 +625,6 @@ public static Mesh ConvertMeshToTriMeshSolid(Mesh mesh) { return m; } - /// - /// Method to convert a NURBS Brep into a planar trimmed surface with PolyCurve - /// internal and external edges of lines and arcs - /// BRep conversion to planar routine first converts the external edge to a PolyCurve - /// of lines and arcs and uses these controlpoints to fit a plane through points. - /// Will output a Tuple containing: - /// - PolyCurve - /// - TopologyList of control points - /// - TopoTypeList (" " or "a") corrosponding to control points - /// - List of PolyCurves for internal (void) curves - /// - Corrosponding list of topology points - /// - Corrosponding list of topologytypes - /// - /// - /// - /// - public static - Tuple, List, List, List>, - List>> ConvertPolyBrep(Brep brep, double tolerance = -1) { - var voidCrvs = new List(); - var voidTopo = new List>(); - var voidTopoType = new List>(); - - Curve outer = null; - var inner = new List(); - foreach (BrepLoop brepLoop in brep.Loops) { - if (brepLoop.LoopType == BrepLoopType.Outer) { - outer = brepLoop.To3dCurve(); - } else { - inner.Add(brepLoop.To3dCurve()); - } - } - - var edges = new List { - outer, - }; - edges.AddRange(inner); - - for (int i = 0; i < edges.Count; i++) { - if (edges[i].IsPlanar()) { - continue; - } - - List ctrlPts; - if (edges[0].TryGetPolyline(out Polyline polyline)) { - ctrlPts = polyline.ToList(); - } else { - Tuple, List> convertBadSrf - = ConvertMem2dCrv(edges[0], tolerance); - ctrlPts = convertBadSrf.Item2; - } - - Plane.FitPlaneToPoints(ctrlPts, out Plane plane); - for (int j = 0; j < edges.Count; j++) { - edges[j] = Curve.ProjectToPlane(edges[j], plane); - } - } - - Tuple, List> convert = ConvertMem2dCrv(edges[0], tolerance); - PolyCurve edgeCrv = convert.Item1; - List point3ds = convert.Item2; - List topoType = convert.Item3; - - for (int i = 1; i < edges.Count; i++) { - convert = ConvertMem2dCrv(edges[i], tolerance); - voidCrvs.Add(convert.Item1); - voidTopo.Add(convert.Item2); - voidTopoType.Add(convert.Item3); - } - - return new - Tuple, List, List, List>, - List>>(edgeCrv, point3ds, topoType, voidCrvs, voidTopo, voidTopoType); - } - /// /// Method to convert a NURBS Brep into a planar trimmed surface with PolyCurve /// internal and external edges of lines and arcs. diff --git a/GsaGHTests/Helpers/GH/RhinoConversionsTests.cs b/GsaGHTests/Helpers/GH/RhinoConversionsTests.cs new file mode 100644 index 000000000..89ec2c983 --- /dev/null +++ b/GsaGHTests/Helpers/GH/RhinoConversionsTests.cs @@ -0,0 +1,61 @@ +using System; +using System.Collections.Generic; +using GsaGH.Components; +using GsaGH.Helpers.GH; +using GsaGH.Helpers.Import; +using GsaGHTests.Helpers; +using OasysGH.Components; +using Rhino.Geometry; +using Xunit; + +namespace GsaGHTests.Helpers.Export.GH { + [Collection("GrasshopperFixture collection")] + public class RhinoConversionsTests { + [Fact] + public void BuildArcLineCurveFromPtsAndTopoTypeTestArc1d() { + var topolist = new List() { + new Point3d(0, 0, 0), + new Point3d(2, 2, 0), + new Point3d(4, 0, 0) + }; + var topotype = new List() { + string.Empty, + "A", + string.Empty, + }; + + PolyCurve crv = RhinoConversions.BuildArcLineCurveFromPtsAndTopoType(topolist, topotype); + Assert.True(crv != null); + Assert.True(crv.IsArc()); + } + + [Fact] + public void ConvertMem1dCrvTest() { + var topolist = new List() { + new Point3d(0, 0, 0), + new Point3d(2, 2, 0), + new Point3d(4, 0, 0) + }; + var crvs = new PolyCurve(); + crvs.Append(new Arc(topolist[0], topolist[1], topolist[2])); + + Tuple, List> mem1d = RhinoConversions.ConvertMem1dCrv( + crvs); + + Assert.True(mem1d.Item1.IsArc()); + Assert.Equal(3, mem1d.Item2.Count); + TestPoint(topolist[0], mem1d.Item2[0]); + TestPoint(topolist[1], mem1d.Item2[1]); + TestPoint(topolist[2], mem1d.Item2[2]); + Assert.Equal(string.Empty, mem1d.Item3[0]); + Assert.Equal("A", mem1d.Item3[1]); + Assert.Equal(string.Empty, mem1d.Item3[2]); + } + + private void TestPoint(Point3d expected, Point3d actual) { + Assert.Equal(expected.X, actual.X, 10); + Assert.Equal(expected.Y, actual.Y, 10); + Assert.Equal(expected.Z, actual.Z, 10); + } + } +} diff --git a/GsaGHTests/Helpers/GsaAPI/ValueHelpersTests.cs b/GsaGHTests/Helpers/GsaAPI/ValueHelpersTests.cs new file mode 100644 index 000000000..002d0c325 --- /dev/null +++ b/GsaGHTests/Helpers/GsaAPI/ValueHelpersTests.cs @@ -0,0 +1,32 @@ +using GsaGH.Helpers.GsaApi; +using System.Collections.Generic; +using System.Linq; +using Xunit; + +namespace GsaGHTests.Helpers.GsaApi { + public class ValueHelpersTests { + [Theory] + [InlineData(1.23456789, 4, "1.235")] + [InlineData(123456, 4, "123500")] + [InlineData(0.000123456, 4, "0.0001235")] + [InlineData(-1.23456789, 4, "-1.235")] + [InlineData(-123456, 4, "-123500")] + [InlineData(-0.000123456, 4, "-0.0001235")] + public void RoundToSignificantDigitsTest(double value, int digits, string expected) { + double d = ResultHelper.RoundToSignificantDigits(value, digits); + Assert.Equal(expected, d.ToString()); + } + + [Theory] + [InlineData(0, 0, 0, 0)] + [InlineData(74, 26, 75, 25)] + [InlineData(7499, 26, 8000, 0)] + [InlineData(24, 15, 25, 15)] + [InlineData(0, -24, 0, -25)] + public void SmartRounderTests(double max, double min, double expectedMax, double expectedMin) { + List vals = ResultHelper.SmartRounder(max, min); + Assert.Equal(expectedMax, vals[0]); + Assert.Equal(expectedMin, vals[1]); + } + } +} diff --git a/IntegrationTests/3_Components/Elem2dFromBrepTests.cs b/IntegrationTests/3_Components/Elem2dFromBrepTests.cs new file mode 100644 index 000000000..09f17bcf1 --- /dev/null +++ b/IntegrationTests/3_Components/Elem2dFromBrepTests.cs @@ -0,0 +1,62 @@ +using System; +using System.IO; +using System.Reflection; +using Grasshopper.Kernel; +using Xunit; + +namespace IntegrationTests.Components { + [Collection("GrasshopperFixture collection")] + public class Elem2dFromBrepTests { + public static GH_Document Document { + get { + if (document == null) { + document = OpenDocument(); + } + + return document; + } + } + private static GH_Document document = null; + + [Fact] + public void NoRuntimeErrorTest() { + Helper.TestNoRuntimeMessagesInDocument(Document, GH_RuntimeMessageLevel.Error); + Helper.TestNoRuntimeMessagesInDocument(Document, GH_RuntimeMessageLevel.Warning); + } + + [Theory] + [InlineData("Types", new string[] { + "QUAD8", + "TRI6" + })] + [InlineData("TriQuadCounts", new int[] { + 0, + 100, + 540, + })] + [InlineData("Inclusions", new int[] { + 1, + 14, + })] + public void Test(string groupIdentifier, object expected) { + IGH_Param param = Helper.FindParameter(Document, groupIdentifier); + Helper.TestGhPrimitives(param, expected); + } + + private static GH_Document OpenDocument() { + Type thisClass = MethodBase.GetCurrentMethod().DeclaringType; + string fileName = thisClass.Name + ".gh"; + fileName = fileName.Replace(thisClass.Namespace, string.Empty).Replace("Tests", string.Empty); + + string solutiondir = Directory.GetParent(Directory.GetCurrentDirectory()).Parent.Parent.Parent + .Parent.FullName; + string path = Path.Combine(new string[] { + solutiondir, + "ExampleFiles", + "Components", + }); + + return Helper.CreateDocument(Path.Combine(path, fileName)); + } + } +}