Example #1
0
        //--------------------------------------------------------------------------------------------------

        protected override void CalculateExtents()
        {
            // Update bounding rect
            Bnd_Box2d aabb = new Bnd_Box2d();

            var shapes = _Source?.GetBreps();

            if (shapes != null)
            {
                foreach (var shape in shapes)
                {
                    double xmin = 0;
                    double xmax = 0;
                    double ymin = 0;
                    double ymax = 0;
                    double zmin = 0;
                    double zmax = 0;
                    shape.BoundingBox()?.Get(ref xmin, ref ymin, ref zmin, ref xmax, ref ymax, ref zmax);
                    aabb.Add(new Pnt2d(xmin, ymin));
                    aabb.Add(new Pnt2d(xmax, ymax));
                }
            }

            Extents = aabb;
        }
Example #2
0
            protected override void CalculateExtents()
            {
                var aabb = new Bnd_Box2d();

                aabb.Add(Pnt2d.Origin);
                aabb.Add(DrawingRenderHelper.MeasureText(Text, Style).ToPnt());
                Extents = aabb;
            }
        public void ReferenceValues()
        {
            Bnd_Box2d box = new Bnd_Box2d();

            box.Add(new Pnt2d(1, 2));
            box.Add(new Pnt2d(-1, -2));
            double xmin = 0, ymin = 0, xmax = 0, ymax = 0;

            box.Get(ref xmin, ref ymin, ref xmax, ref ymax);
            Assert.AreEqual(-1, xmin);
            Assert.AreEqual(1, xmax);
            Assert.AreEqual(-2, ymin);
            Assert.AreEqual(2, ymax);
        }
Example #4
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));
            }
        }