Exemple #1
0
        public bool IntersectsWith(RotatedRectangleF rect)
        {
            var thisRect  = Clone();
            var otherRect = rect.Clone();

            if (Angle != 0)
            {
                var angle = thisRect.Angle;
                thisRect.Angle = 0;

                var center = otherRect.Center;
                center.RotateAt(-angle, thisRect.Center);
                otherRect.Center = center;
                otherRect.Angle -= angle;
            }

            var thisEdges  = new PointF[] { thisRect.GetLeftTopEdge(), thisRect.GetRigthTopEdge(), thisRect.GetRightBottomEdge(), thisRect.GetLeftBottomEdge() };
            var otherEdges = new PointF[] { otherRect.GetLeftTopEdge(), otherRect.GetRigthTopEdge(), otherRect.GetRightBottomEdge(), otherRect.GetLeftBottomEdge() };

            var firstProjectionIntersection = CheckProjectionIntersection(thisEdges, otherEdges);

            var secondProjectionIntersection = true;

            if (firstProjectionIntersection && Angle != rect.Angle)
            {
                thisRect  = Clone();
                otherRect = rect.Clone();

                var angle = otherRect.Angle;
                otherRect.Angle = 0;

                var center = thisRect.Center;
                center.RotateAt(-angle, otherRect.Center);
                thisRect.Center = center;
                thisRect.Angle -= angle;

                thisEdges  = new PointF[] { thisRect.GetLeftTopEdge(), thisRect.GetRigthTopEdge(), thisRect.GetRightBottomEdge(), thisRect.GetLeftBottomEdge() };
                otherEdges = new PointF[] { otherRect.GetLeftTopEdge(), otherRect.GetRigthTopEdge(), otherRect.GetRightBottomEdge(), otherRect.GetLeftBottomEdge() };

                secondProjectionIntersection = CheckProjectionIntersection(thisEdges, otherEdges);
            }

            return(firstProjectionIntersection && secondProjectionIntersection);
        }