//-------------------------------------------------------------------------------------------------- void _ImportArcSegment(SvgPathSegArc svgSegment, ref int startPoint) { var radiusX = svgSegment.RadiusX; var radiusY = svgSegment.RadiusY; var rotation = -svgSegment.Angle.ToRad(); var startPnt2d = svgSegment.Start; var endPnt2d = svgSegment.End; var centerPnt2d = Geom2dUtils.FindEllipseCenterFromEndpoints( startPnt2d, endPnt2d, radiusX, radiusY, rotation, (int)svgSegment.Size != (int)svgSegment.Sweep); // Do we have a circle arc? if (Math.Abs(radiusX - radiusY) < 0.0001) { var axis = Ax2d.OX.Rotated(Pnt2d.Origin, rotation).Translated(centerPnt2d.ToVec()); var circ = new gp_Circ2d(axis, radiusX, svgSegment.Sweep != SvgArcSweep.Positive); //Debug.WriteLine("StartParam: {0} - EndParam: {1}", ElCLib.Parameter(circ, startPnt2d), ElCLib.Parameter(circ, endPnt2d)); var startParam = ElCLib.Parameter(circ, startPnt2d); var endParam = ElCLib.Parameter(circ, endPnt2d); if (endParam < startParam) { endParam += 2 * Math.PI; } var rimPnt2d = ElCLib.Value(startParam + (endParam - startParam) / 2, circ); var endPoint = _AddPoint(endPnt2d); _Segments.Add(new SketchSegmentArc(startPoint, endPoint, _AddPoint(rimPnt2d))); startPoint = endPoint; } else { // No, we have a elliptical arc // Construct ellipse, convert to bezier var axis = Ax2d.OX.Rotated(Pnt2d.Origin, rotation).Translated(centerPnt2d.ToVec()); var ellipse = new gp_Elips2d(axis, radiusX, radiusY, svgSegment.Sweep != SvgArcSweep.Positive); var startParam = ElCLib.Parameter(ellipse, startPnt2d); var endParam = ElCLib.Parameter(ellipse, endPnt2d); if (double.IsNaN(startParam) || double.IsNaN(endParam)) { Messages.Warning("Invalid elliptical arc found in SVG file."); return; } var bezierPointArray = Geom2dUtils.EllipticalArcToBezier(ellipse, startParam, endParam); foreach (var bezierPoints in bezierPointArray) { var endPoint = _AddPoint(bezierPoints.p2); _Segments.Add(new SketchSegmentBezier(startPoint, _AddPoint(bezierPoints.c1), _AddPoint(bezierPoints.c2), endPoint)); startPoint = endPoint; } } }
//-------------------------------------------------------------------------------------------------- void _ImportEllipticalArc(DxfDomEllipse dxfEllipse) { var centerPoint = dxfEllipse.CenterPoint; var majorRimPoint = centerPoint.Translated(dxfEllipse.MajorAxisPointOffset.ToVec()); var minorRimPoint = centerPoint.Translated(dxfEllipse.MajorAxisPointOffset.ToVec().Rotated(90.0.ToRad()).Scaled(dxfEllipse.Ratio)); var ellipse = Geom2dUtils.MakeEllipse(centerPoint, majorRimPoint, minorRimPoint); var bezierPointArray = Geom2dUtils.EllipticalArcToBezier(ellipse, dxfEllipse.StartParameter, dxfEllipse.EndParameter); foreach (var bezierPoints in bezierPointArray) { var startPoint = _AddPoint(bezierPoints.p1); var endPoint = _AddPoint(bezierPoints.p2); _Segments.Add(new SketchSegmentBezier(startPoint, _AddPoint(bezierPoints.c1, false), _AddPoint(bezierPoints.c2, false), endPoint)); } }