Exemple #1
0
		public IntersectCase Intersect(Rectangle rectangle)
		{
			throw new NotImplementedException();
			//TODO
		}
		public IntersectCase Intersect(Rectangle rectangle)
		{
			// Test if all 4 corners of the rectangle are inside the ellipse
			var ul = new Point2D(rectangle.MinPt.X, rectangle.MaxPt.Y);
			var ur = new Point2D(rectangle.MaxPt.X, rectangle.MaxPt.Y);
			var ll = new Point2D(rectangle.MinPt.X, rectangle.MinPt.Y);
			var lr = new Point2D(rectangle.MaxPt.X, rectangle.MinPt.Y);
			
			if (Contains(ul) && Contains(ur) && Contains(ll) && Contains(lr)) return IntersectCase.CONTAINS;

			// Test if any of the rectangle edges intersect
			Point2D pt0 = new Point2D(), pt1 = new Point2D();

			var bottom = new LineSegment(ll, lr);

			if (Intersect(bottom, pt0, pt1) > 0)
				return IntersectCase.INTERSECTS;

			var top = new LineSegment(ul, ur);
			if (Intersect(top, pt0, pt1) > 0)
				return IntersectCase.INTERSECTS;

			var left = new LineSegment(ll, ul);
			if (Intersect(left, pt0, pt1) > 0)
				return IntersectCase.INTERSECTS;

			var right = new LineSegment(lr, ur);
			if (Intersect(right, pt0, pt1) > 0)
				return IntersectCase.INTERSECTS;

			// Ellipse does not intersect any edge : since the case for the ellipse
			// containing the rectangle was considered above then if the center
			// is inside the ellipse is fully inside and if center is outside
			// the ellipse is fully outside
			return (rectangle.Contains(_center)) ? IntersectCase.WITHIN : IntersectCase.OUTSIDE;
		}