/// <summary> /// DS Circle to SpeckleCircle. /// </summary> /// <param name="circ"></param> /// <returns></returns> public Circle CircleToSpeckle(DS.Circle circ) { using (DS.Vector xAxis = DS.Vector.ByTwoPoints(circ.CenterPoint, circ.StartPoint)) using (DS.Plane plane = DS.Plane.ByOriginNormalXAxis(circ.CenterPoint, circ.Normal, xAxis)) { var myCircle = new Circle(PlaneToSpeckle(plane), circ.Radius, ModelUnits); CopyProperties(myCircle, circ); return(myCircle); } }
/// <summary> /// SpeckleCircle to DS Circle. Rotating the circle is due to a bug in ProtoGeometry /// that will be solved on Dynamo 2.1. /// </summary> /// <param name="circ"></param> /// <returns></returns> public DS.Circle CircleToNative(Circle circ) { using (DS.Plane basePlane = PlaneToNative(circ.plane)) using (DS.Circle preCircle = DS.Circle.ByPlaneRadius(basePlane, ScaleToNative(circ.radius.Value, circ.units))) using (DS.Vector preXvector = DS.Vector.ByTwoPoints(preCircle.CenterPoint, preCircle.StartPoint)) { double angle = preXvector.AngleAboutAxis(basePlane.XAxis, basePlane.Normal); var circle = (DS.Circle)preCircle.Rotate(basePlane, angle); return(circle.SetDynamoProperties <DS.Circle>(GetDynamicMembersFromBase(circ))); } }
/// <summary> /// DS Circle to SpeckleCircle. /// </summary> /// <param name="circ"></param> /// <returns></returns> public Circle CircleToSpeckle(DS.Circle circ, string units = null) { var u = units ?? ModelUnits; using (DS.Vector xAxis = DS.Vector.ByTwoPoints(circ.CenterPoint, circ.StartPoint)) using (DS.Plane plane = DS.Plane.ByOriginNormalXAxis(circ.CenterPoint, circ.Normal, xAxis)) { var myCircle = new Circle(PlaneToSpeckle(plane, u), circ.Radius, u); CopyProperties(myCircle, circ); myCircle.length = circ.Length; myCircle.bbox = BoxToSpeckle(circ.BoundingBox.ToCuboid(), u); return(myCircle); } }
public Base CurveToSpeckle(DS.Curve curve, string units = null) { var u = units ?? ModelUnits; Base speckleCurve; if (curve.IsLinear()) { using (DS.Line line = curve.GetAsLine()) { speckleCurve = LineToSpeckle(line, u); } } else if (curve.IsArc()) { using (DS.Arc arc = curve.GetAsArc()) { speckleCurve = ArcToSpeckle(arc, u); } } else if (curve.IsCircle()) { using (DS.Circle circle = curve.GetAsCircle()) { speckleCurve = CircleToSpeckle(circle, u); } } else if (curve.IsEllipse()) { using (DS.Ellipse ellipse = curve.GetAsEllipse()) { speckleCurve = EllipseToSpeckle(ellipse, u); } } else { speckleCurve = CurveToSpeckle(curve.ToNurbsCurve(), u); } CopyProperties(speckleCurve, curve); return(speckleCurve); }
public Base CurveToSpeckle(DS.Curve curve) { Base speckleCurve; if (curve.IsLinear()) { using (DS.Line line = curve.GetAsLine()) { speckleCurve = LineToSpeckle(line); } } else if (curve.IsArc()) { using (DS.Arc arc = curve.GetAsArc()) { speckleCurve = ArcToSpeckle(arc); } } else if (curve.IsCircle()) { using (DS.Circle circle = curve.GetAsCircle()) { speckleCurve = CircleToSpeckle(circle); } } else if (curve.IsEllipse()) { using (DS.Ellipse ellipse = curve.GetAsEllipse()) { speckleCurve = EllipseToSpeckle(ellipse); } } else { speckleCurve = CurveToSpeckle(curve.ToNurbsCurve()); } CopyProperties(speckleCurve, curve); return(speckleCurve); }
public Base CurveToSpeckle(NurbsCurve curve, string units = null) { var u = units ?? ModelUnits; Base speckleCurve; if (curve.IsLinear()) { using (DS.Line line = curve.GetAsLine()) { speckleCurve = LineToSpeckle(line, u); } } else if (curve.IsArc()) { using (DS.Arc arc = curve.GetAsArc()) { speckleCurve = ArcToSpeckle(arc, u); } } else if (curve.IsCircle()) { using (DS.Circle circle = curve.GetAsCircle()) { speckleCurve = CircleToSpeckle(circle, u); } } else if (curve.IsEllipse()) { using (DS.Ellipse ellipse = curve.GetAsEllipse()) { speckleCurve = EllipseToSpeckle(ellipse, u); } } else { // SpeckleCurve DisplayValue DS.Curve[] curves = curve.ApproximateWithArcAndLineSegments(); List <double> polylineCoordinates = curves.SelectMany(c => PointListToFlatArray(new DS.Point[2] { c.StartPoint, c.EndPoint })).ToList(); polylineCoordinates.AddRange(PointToArray(curves.Last().EndPoint)); curves.ForEach(c => c.Dispose()); Polyline displayValue = new Polyline(polylineCoordinates, u); List <double> dsKnots = curve.Knots().ToList(); dsKnots.RemoveAt(dsKnots.Count - 1); dsKnots.RemoveAt(0); Curve spkCurve = new Curve(displayValue, u); spkCurve.weights = curve.Weights().ToList(); spkCurve.points = PointListToFlatArray(curve.ControlPoints()).ToList(); spkCurve.knots = dsKnots; spkCurve.degree = curve.Degree; spkCurve.periodic = curve.IsPeriodic; spkCurve.rational = curve.IsRational; spkCurve.closed = curve.IsClosed; spkCurve.domain = new Interval(curve.StartParameter(), curve.EndParameter()); //spkCurve.Properties //spkCurve.GenerateHash(); spkCurve.length = curve.Length; spkCurve.bbox = BoxToSpeckle(curve.BoundingBox.ToCuboid(), u); speckleCurve = spkCurve; } CopyProperties(speckleCurve, curve); return(speckleCurve); }