public static BHX.Polyloop ToGBXML(this BHG.Polyline pLine, GBXMLSettings settings, double tolerance = BHG.Tolerance.Distance) { BHX.Polyloop polyloop = new BHX.Polyloop(); pLine = pLine.CleanPolyline(minimumSegmentLength: tolerance); List <BHG.Point> pts = pLine.DiscontinuityPoints(); if (pts.Count == 0) { return(polyloop); } int count = ((pts.First().SquareDistance(pts.Last()) < (tolerance * tolerance)) ? pts.Count - 1 : pts.Count); List <BHX.CartesianPoint> cartpoint = new List <BHX.CartesianPoint>(); for (int i = 0; i < count; i++) { BHX.CartesianPoint cpt = pts[i].ToGBXML(settings); List <string> coord = new List <string>(); cartpoint.Add(cpt); } polyloop.CartesianPoint = cartpoint.ToArray(); return(polyloop); }
public static BHG.Point FromGBXML(this BHX.CartesianPoint pt) { BHG.Point bhomPt = new BHG.Point(); try { bhomPt.X = (pt.Coordinate.Length >= 1 ? System.Convert.ToDouble(pt.Coordinate[0]) : 0); bhomPt.Y = (pt.Coordinate.Length >= 2 ? System.Convert.ToDouble(pt.Coordinate[1]) : 0); bhomPt.Z = (pt.Coordinate.Length >= 3 ? System.Convert.ToDouble(pt.Coordinate[2]) : 0); } catch { } return(bhomPt); }
public static BHX.CartesianPoint ToGBXML(this BHG.Point pt, GBXMLSettings settings) { BHX.CartesianPoint cartPoint = new BHX.CartesianPoint(); List <string> coord = new List <string>(); coord.Add(Math.Round(pt.X, settings.RoundingSettings.GeometricPoints).ToString()); coord.Add(Math.Round(pt.Y, settings.RoundingSettings.GeometricPoints).ToString()); coord.Add(Math.Round(pt.Z, settings.RoundingSettings.GeometricPoints).ToString()); cartPoint.Coordinate = coord.ToArray(); return(cartPoint); }