Beispiel #1
0
        /// <summary>
        /// Returns the untransformed axis aligned bounding rectangle of the line cap defined by the given styles.
        /// </summary>
        public static Rectangle GetCapBounds(ICapStyle capStyle, ILineStyle lineStyle, float angleDeg)
        {
            if (capStyle == null)
            {
                throw new ArgumentNullException("capStyle");
            }
            if (lineStyle == null)
            {
                throw new ArgumentNullException("lineStyle");
            }
            Rectangle result = Geometry.InvalidRectangle;

            PointF[] buffer = null;
            GetCapPoints(capStyle, lineStyle, ref buffer);

            // Transform cap points
            _matrix.Reset();
            _matrix.RotateAt(angleDeg + 90, Point.Empty);
            // Scale GraphicsPath up for correcting the automatic scaling that is applied to
            // LineCaps by GDI+ when altering the LineWidth of the pen
            _matrix.Scale(lineStyle.LineWidth, lineStyle.LineWidth);
            _matrix.TransformPoints(buffer);

            Geometry.CalcBoundingRectangle(buffer, out result);
            ShapeUtils.InflateBoundingRectangle(ref result, lineStyle);

            return(result);
        }
Beispiel #2
0
        /// <override></override>
        protected override Rectangle CalculateBoundingRectangle(bool tight)
        {
            Rectangle result;

            Array.Copy(shapePoints, pointBuffer, pointBuffer.Length);
            Matrix.Reset();
            Matrix.RotateAt(Geometry.TenthsOfDegreeToDegrees(Angle), Point.Empty);
            Matrix.TransformPoints(pointBuffer);

            Geometry.CalcBoundingRectangle(pointBuffer, out result);
            result.Offset(X, Y);
            ShapeUtils.InflateBoundingRectangle(ref result, LineStyle);

            return(result);
        }
Beispiel #3
0
        /// <override></override>
        protected override Rectangle CalculateBoundingRectangle(bool tight)
        {
            Rectangle result = Geometry.InvalidRectangle;

            if (Size >= 0)
            {
                result.X     = X - (int)Math.Round(Size / 2f);
                result.Y     = Y - (int)Math.Round(Size / 2f);
                result.Width = result.Height = Size;
                if (Angle % 900 != 0)
                {
                    Point tl, tr, bl, br;
                    Geometry.RotateRectangle(result, Center, Geometry.TenthsOfDegreeToDegrees(Angle), out tl, out tr, out br, out bl);
                    Geometry.CalcBoundingRectangle(tl, tr, bl, br, out result);
                }
                ShapeUtils.InflateBoundingRectangle(ref result, LineStyle);
            }
            return(result);
        }
Beispiel #4
0
        /// <override></override>
        protected override Rectangle CalculateBoundingRectangle(bool tight)
        {
            Rectangle result = Geometry.InvalidRectangle;

            if (tight)
            {
                if (DiameterInternal >= 0)
                {
                    // No need to rotate the tight bounding rectangle of a circle
                    result.X     = X - (int)Math.Round(Diameter / 2f);
                    result.Y     = Y - (int)Math.Round(Diameter / 2f);
                    result.Width = result.Height = Diameter;
                }
            }
            else
            {
                result = base.CalculateBoundingRectangle(tight);
            }
            if (Geometry.IsValid(result))
            {
                ShapeUtils.InflateBoundingRectangle(ref result, LineStyle);
            }
            return(result);
        }
Beispiel #5
0
 /// <summary>
 /// Retuirns the BoundingRectangle of the shape.
 /// This default implementation uses the GetBounds() method provided by the GraphicsPath class.
 /// It is recommended to override this method with more shape specific versions that do not call base.
 /// </summary>
 /// <param name="tight">
 /// If true, a thight fitting x axis aligned bounding rectangle will be returned.
 /// If false, a x axis aligned bounding rectangle also containing all control points will be returned.
 /// </param>
 protected override Rectangle CalculateBoundingRectangle(bool tight)
 {
     if (tight)
     {
         Rectangle result = Rectangle.Empty;
         if (drawCacheIsInvalid)
         {
             CalculatePath();
             result = Rectangle.Ceiling(Path.GetBounds());
             if (Angle != 0)
             {
                 Point tl, tr, bl, br;
                 Geometry.RotateRectangle(result, Point.Empty, Geometry.TenthsOfDegreeToDegrees(Angle), out tl, out tr, out bl, out br);
                 Geometry.CalcBoundingRectangle(tl, tr, bl, br, out result);
             }
             result.Offset(X, Y);
         }
         else
         {
             result = Rectangle.Ceiling(Path.GetBounds());
         }
         ShapeUtils.InflateBoundingRectangle(ref result, LineStyle);
         return(result);
     }
     else
     {
         Rectangle result = Rectangle.Empty;
         if (drawCacheIsInvalid)
         {
             CalcControlPoints();
             Point tl = Point.Empty, tr = Point.Empty, bl = Point.Empty, br = Point.Empty;
             for (int i = ControlPoints.Length - 1; i >= 0; --i)
             {
                 Point pt = ControlPoints[i];
                 if (pt.X <= tl.X && pt.Y <= tl.Y)
                 {
                     tl = pt;
                 }
                 if (pt.X >= tr.X && pt.Y <= tr.Y)
                 {
                     tr = pt;
                 }
                 if (pt.X <= bl.X && pt.Y >= bl.Y)
                 {
                     bl = pt;
                 }
                 if (pt.X >= br.X && pt.Y >= br.Y)
                 {
                     br = pt;
                 }
             }
             if (Angle != 0)
             {
                 tl = Geometry.RotatePoint(Point.Empty, Geometry.TenthsOfDegreeToDegrees(Angle), tl);
                 tr = Geometry.RotatePoint(Point.Empty, Geometry.TenthsOfDegreeToDegrees(Angle), tr);
                 bl = Geometry.RotatePoint(Point.Empty, Geometry.TenthsOfDegreeToDegrees(Angle), bl);
                 br = Geometry.RotatePoint(Point.Empty, Geometry.TenthsOfDegreeToDegrees(Angle), br);
             }
             Geometry.CalcBoundingRectangle(tl, tr, bl, br, out result);
             result.Offset(X, Y);
         }
         else
         {
             Geometry.CalcBoundingRectangle(ControlPoints, out result);
         }
         return(result);
     }
 }