Esempio n. 1
0
        //--------------------------------------------------------------------------------------------------

        public static bool RenderEllipse(IDrawingRenderer renderer, Geom2d_Ellipse ellipse, double first, double last, bool reverse)
        {
            if (renderer.Capabilities.EllipseAsCurve)
            {
                var bsplineCurve = ShapeConstruct.ConvertCurveToBSpline(ellipse, first, last, 0.001, GeomAbs_Shape.GeomAbs_C1, 100, 3);
                if (bsplineCurve != null)
                {
                    return(RenderBSplineCurve(renderer, bsplineCurve, first, last, reverse));
                }
                return(false);
            }

            var    center      = ellipse.Location();
            var    majorRadius = ellipse.MajorRadius();
            var    minorRadius = ellipse.MinorRadius();
            double rotation    = ellipse.XAxis().Direction.Angle(Dir2d.DX);

            if (ellipse.Position().Sense() > 0)
            {
                first = Maths.DoublePI - first;
                last  = Maths.DoublePI - last;
            }

            if (reverse)
            {
                first.Swap(ref last);
            }

            renderer.Ellipse(center, majorRadius, minorRadius, rotation, first, last);

            return(false);
        }
Esempio n. 2
0
        //--------------------------------------------------------------------------------------------------

        protected void AddEllipse(Geom2d_Ellipse geom2DEllipse, double first, double last, bool reverse)
        {
            if (Math.Abs(last - first) < geom2DEllipse.Period())
            {
                // Ellipse arc
                var start = geom2DEllipse.Value(reverse ? last : first);
                var end   = geom2DEllipse.Value(reverse ? first : last);

                // Add the midpoint seems to be the simplest way to improve the BB
                BoundingBox?.Add(geom2DEllipse.Value(first + (last - first) / 2));

                // Get parameters of ellipse
                double radiusX       = geom2DEllipse.MajorRadius();
                double radiusY       = geom2DEllipse.MinorRadius();
                double angleX        = Maths.NormalizeAngleDegree(geom2DEllipse.XAxis().Angle(Ax2d.OX).ToDeg());
                double length        = last - first;
                double halfParameter = (geom2DEllipse.LastParameter() - geom2DEllipse.FirstParameter()) / 2.0;
                var    size          = (length < halfParameter) ? SvgArcSize.Small : SvgArcSize.Large;
                var    sweep         = geom2DEllipse.Position().Sense() > 0
                    ? (reverse ? SvgArcSweep.Negative : SvgArcSweep.Positive)
                    : (reverse ? SvgArcSweep.Positive : SvgArcSweep.Negative);

                AddToPath(new SvgPathSegArc(start, radiusX, radiusY, angleX, size, sweep, end));
            }
            else
            {
                // Complete ellipse
                if (reverse)
                {
                    geom2DEllipse = geom2DEllipse.Reversed() as Geom2d_Ellipse;
                }

                double rotationAngle = geom2DEllipse.XAxis().Angle(Ax2d.OX);

                var segment = new SvgEllipseElement(geom2DEllipse.Location(), geom2DEllipse.MajorRadius(), geom2DEllipse.MinorRadius());
                segment.Transforms.Add(new SvgRotateTransform(Maths.NormalizeAngleDegree(rotationAngle.ToDeg())));
                CurrentGroup.Children.Add(segment);

                // Enlarge BB
                var f = geom2DEllipse.FirstParameter();
                var q = (geom2DEllipse.LastParameter() - f) / 4;
                BoundingBox?.Add(geom2DEllipse.Value(f));
                BoundingBox?.Add(geom2DEllipse.Value(f + q));
                BoundingBox?.Add(geom2DEllipse.Value(f + q * 2));
                BoundingBox?.Add(geom2DEllipse.Value(f + q * 3));
            }
        }
Esempio n. 3
0
        //--------------------------------------------------------------------------------------------------

        void _AddEllipse(Geom2d_Ellipse ellipse, double first, double last)
        {
            if (_Document.Flags.HasFlag(DxfFlags.ExportEllipseAsPolygon))
            {
                if (Math.Abs(last - first) < ellipse.Period())
                {
                    // Elliptical arc
                    var trimmedCurve = new Geom2d_TrimmedCurve(ellipse, first, last);
                    _AddPolygonCurve(trimmedCurve);
                }
                else
                {
                    // Full ellipse
                    _AddPolygonCurve(ellipse);
                }
                return;
            }

            var center = ellipse.Location();
            var majorAxisPointOffset = ellipse.XAxis().Direction.ToVec().Multiplied(ellipse.MajorRadius());
            var ratio = ellipse.MinorRadius() / ellipse.MajorRadius();

            if (Math.Abs(last - first) < ellipse.Period())
            {
                // Elliptical arc
                if (ellipse.Position().Sense() > 0)
                {
                    var temp = first;
                    first = ellipse.Period() - last;
                    last  = ellipse.Period() - temp;
                }

                var entity = new DxfDomEllipse(_CurrentLayer, center, majorAxisPointOffset.ToPnt(), ratio, first, last);
                _Document.Entities.Add(entity);
            }
            else
            {
                // Full ellipse
                var entity = new DxfDomEllipse(_CurrentLayer, center, majorAxisPointOffset.ToPnt(), ratio);
                _Document.Entities.Add(entity);
            }
        }