System.util.RectangleJ.Intersection C# (CSharp) Méthode

Intersection() public méthode

public Intersection ( RectangleJ r ) : RectangleJ
r RectangleJ
Résultat RectangleJ
        public RectangleJ Intersection(RectangleJ r) {
            float x1 = Math.Max(x, r.x);
            float y1 = Math.Max(y, r.y);
            float x2 = Math.Min(x + width, r.x + r.width);
            float y2 = Math.Min(y + height, r.y + r.height);
            return new RectangleJ(x1, y1, x2 - x1, y2 - y1);
        }

Usage Example

        /**
         * Returns the intersection between the crop, trim art or bleed box and the parameter intersectingRectangle.
         * This method returns null when
         * - there is no intersection
         * - any of the above boxes are not defined
         * - the parameter intersectingRectangle is null
         *
         * @param boxName crop, trim, art, bleed
         * @param intersectingRectangle the rectangle that intersects the rectangle associated to the boxName
         * @return the intersection of the two rectangles
         */
        public Rectangle GetBoxSize(String boxName, Rectangle intersectingRectangle) {
            Rectangle pdfRectangle = pdf.GetBoxSize(boxName);

            if ( pdfRectangle == null || intersectingRectangle == null ) { // no intersection
                return null;
            }
            //com.itextpdf.awt.geom.Rectangle
            RectangleJ boxRect = new RectangleJ(pdfRectangle);
            RectangleJ intRect = new RectangleJ(intersectingRectangle);
            RectangleJ outRect = boxRect.Intersection(intRect);

            if (outRect.IsEmpty()) { // no intersection
                return null;
            }

            Rectangle output = new Rectangle(outRect.X, outRect.Y, outRect.X + outRect.Width, outRect.Y + outRect.Height);
            output.Normalize();
            return output;
        }
All Usage Examples Of System.util.RectangleJ::Intersection