Beispiel #1
0
        //--------------------------------------------------------------------------------------------------

        public static bool RenderCircle(IDrawingRenderer renderer, Geom2d_Circle circle, double first, double last, bool reverse)
        {
            if (renderer.Capabilities.CircleAsCurve)
            {
                var bsplineCurve = ShapeConstruct.ConvertCurveToBSpline(circle, first, last, 0.001, GeomAbs_Shape.GeomAbs_C2, 100, 3);
                if (bsplineCurve != null)
                {
                    return(RenderBSplineCurve(renderer, bsplineCurve, first, last, reverse));
                }
                return(false);
            }

            var    center   = circle.Location();
            var    radius   = circle.Radius();
            double rotation = circle.XAxis().Direction.Angle(Dir2d.DX);

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

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

            renderer.Circle(center, radius, first - rotation, last - rotation);

            return(true);
        }
Beispiel #2
0
        //--------------------------------------------------------------------------------------------------

        void _AddCircle(Geom2d_Circle circle, double first, double last)
        {
            if (Math.Abs(last - first) < circle.Period())
            {
                // Circle arc
                if (circle.Position().Sense() > 0)
                {
                    var temp = first;
                    first = last;
                    last  = temp;
                }

                var entity = new DxfDomCircle(_CurrentLayer, circle.Location(), circle.Radius(), circle.Value(first), circle.Value(last));
                _Document.Entities.Add(entity);
            }
            else
            {
                // Full circle
                var entity = new DxfDomCircle(_CurrentLayer, circle.Location(), circle.Radius());
                _Document.Entities.Add(entity);
            }
        }
Beispiel #3
0
        //--------------------------------------------------------------------------------------------------

        protected void AddCircle(Geom2d_Circle geom2DCircle, double first, double last, bool reverse)
        {
            if (Math.Abs(last - first) < geom2DCircle.Period())
            {
                // Circle arc
                var start = geom2DCircle.Value(reverse ? last : first);
                var end   = geom2DCircle.Value(reverse ? first : last);

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

                // Get parameters of circle
                double radius        = geom2DCircle.Radius();
                double length        = last - first;
                double halfParameter = (geom2DCircle.LastParameter() - geom2DCircle.FirstParameter()) / 2.0;
                var    size          = (length < halfParameter) ? SvgArcSize.Small : SvgArcSize.Large;
                var    sweep         = geom2DCircle.Position().Sense() > 0
                    ? (reverse ? SvgArcSweep.Negative : SvgArcSweep.Positive)
                    : (reverse ? SvgArcSweep.Positive : SvgArcSweep.Negative);

                AddToPath(new SvgPathSegArc(start, radius, radius, 0.0f, size, sweep, end));
            }
            else
            {
                // Complete circle
                var circleCenter = geom2DCircle.Location();
                var circleRadius = geom2DCircle.Radius();

                if (CombineToPath)
                {
                    if (geom2DCircle.Position().Sense() > 0)
                    {
                        reverse = !reverse;
                    }

                    ClosePath();
                    var rimPoints = new List <Pnt2d>(4)
                    {
                        new Pnt2d(circleCenter.X, circleCenter.Y + circleRadius),
                        new Pnt2d(circleCenter.X - circleRadius, circleCenter.Y),
                        new Pnt2d(circleCenter.X, circleCenter.Y - circleRadius),
                        new Pnt2d(circleCenter.X + circleRadius, circleCenter.Y),
                    };

                    SvgArcSweep sweep;
                    if (reverse)
                    {
                        rimPoints.Reverse();
                        sweep = SvgArcSweep.Positive;
                    }
                    else
                    {
                        sweep = SvgArcSweep.Negative;
                    }

                    AddToPath(new SvgPathSegArc(rimPoints[0], circleRadius, circleRadius, 45.0f, SvgArcSize.Small, sweep, rimPoints[1]));
                    AddToPath(new SvgPathSegArc(rimPoints[1], circleRadius, circleRadius, 45.0f, SvgArcSize.Small, sweep, rimPoints[2]));
                    AddToPath(new SvgPathSegArc(rimPoints[2], circleRadius, circleRadius, 45.0f, SvgArcSize.Small, sweep, rimPoints[3]));
                    AddToPath(new SvgPathSegArc(rimPoints[3], circleRadius, circleRadius, 45.0f, SvgArcSize.Small, sweep, rimPoints[0]));
                    ClosePath();
                }
                else
                {
                    CurrentGroup.Children.Add(new SvgCircleElement(circleCenter, circleRadius));
                }

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