System.Windows.Rect.Intersect C# (CSharp) Method

Intersect() public method

public Intersect ( Rect rect ) : void
rect Rect
return void
        public void Intersect(Rect rect)
        {
            if (!this.IntersectsWith(rect))
            {
                this = Empty;
            }
            else
            {
                double num2 = Math.Max(this.Left, rect.Left);
                double num = Math.Max(this.Top, rect.Top);
                this._width = Math.Max((double)(Math.Min(this.Right, rect.Right) - num2), (double)0.0);
                this._height = Math.Max((double)(Math.Min(this.Bottom, rect.Bottom) - num), (double)0.0);
                this._x = num2;
                this._y = num;
            }
        }

Same methods

Rect::Intersect ( Rect rect1, Rect rect2 ) : Rect

Usage Example

Example #1
0
		/// <summary>
		/// Applies the specified old data rect.
		/// </summary>
		/// <param name="oldDataRect">The old data rect.</param>
		/// <param name="newDataRect">The new data rect.</param>
		/// <param name="viewport">The viewport.</param>
		/// <returns></returns>
        /// 
		public override Rect Apply(Rect oldDataRect, Rect newDataRect, Viewport2D viewport)
		{
			DataRect res = domain;
			if (domain.IsEmpty)
			{
				res = newDataRect;
			}
			else if (newDataRect.IntersectsWith(domain))
			{
				res = newDataRect;
                if (newDataRect.Size == oldDataRect.Size)
                {
                    if (res.XMin < domain.XMin) res.XMin = domain.XMin;
                    if (res.YMin < domain.YMin) res.YMin = domain.YMin;
                    if (res.XMax > domain.XMax) res.XMin += domain.XMax - res.XMax;
                    if (res.YMax > domain.YMax) res.YMin += domain.YMax - res.YMax;
                }
                else
                {
                    newDataRect.Intersect(domain);
                    res = newDataRect;
                }
			}

			return res;
		}
All Usage Examples Of System.Windows.Rect::Intersect