当前位置: 首页>>代码示例>>C#>>正文


C# Rect.GetCorners方法代码示例

本文整理汇总了C#中System.Windows.Rect.GetCorners方法的典型用法代码示例。如果您正苦于以下问题:C# Rect.GetCorners方法的具体用法?C# Rect.GetCorners怎么用?C# Rect.GetCorners使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Windows.Rect的用法示例。


在下文中一共展示了Rect.GetCorners方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Subtract

		/// <summary> Returns the parts of a not overlapping with b. </summary>
		public static Rect[] Subtract(Rect a, ref Rect b)
		{
			var legs = a.GetCorners().Count(b.Contains);
			if (legs == 0)
			{
				return a.Substract0Legged(ref b);
			}
			else if (legs == 1)
			{
				return a.Substract1Legged(b);
			}
			else if (legs == 2)
			{
				return a.Substract2Legged(b);
			}
			else
			{
				Contract.Assert(legs == 4);
				return EmptyCollection<Rect>.Array; //rect is already contained in r
			}
		}
开发者ID:JeroenBos,项目名称:ASDE,代码行数:22,代码来源:RectangleExtensions.cs

示例2: Substract0Legged

		/// <summary> Returns parts of a that are not contained in b, assuming that no corner of a is in b. </summary>
		public static Rect[] Substract0Legged(this Rect a, ref Rect b)
		{
			bool rightQ = b.Left <= a.Right && a.Right < b.Right; //a.right is in b
			bool leftQ = b.Left <= a.Left && a.Left < b.Right; //a.left is in b
			bool topQ = b.Top <= a.Top && a.Top < b.Bottom; //a.top is in b
			bool bottomQ = b.Top <= a.Bottom && a.Bottom < b.Bottom; //a.bottom is in b

			//no corner of a may be in b
			Contract.Assert(!(leftQ && topQ));
			Contract.Assert(!(rightQ && topQ));
			Contract.Assert(!(rightQ && bottomQ));
			Contract.Assert(!(leftQ && bottomQ));

			int invCornerCount = b.GetCorners().Count(a.Contains);
			if (invCornerCount == 2)
			{
				Rect[] result = Substract2Legged(b, a);
				b = a; //must be set after calling Substract2Legged
				return result;
			}
			else if (invCornerCount == 4)
			{
				b = default(Rect);
				return new[] { a };
			}
			if (leftQ && rightQ)
			{
				//b is horizontal
				if (b.Bottom <= a.Top || b.Top >= a.Bottom)
				{
					//no intersection
				}
				else
				{
					//top part of a:
					Rect result1 = FromExplicitCoordinates(a.Left, a.Right, a.Top, b.Top);
					//bottom part of a:
					Rect result2 = FromExplicitCoordinates(a.Left, a.Right, b.Bottom, a.Bottom);
					return new[] { result1, result2 };
				}
			}
			else if (topQ && bottomQ)
			{
				//b is vertical
				if (b.Left >= a.Right || b.Right <= a.Left)
				{
					//no intersection
				}
				else
				{
					//left part of a:
					Rect result1 = FromExplicitCoordinates(a.Left, b.Left, a.Top, a.Bottom);
					//right part of b:
					Rect result2 = FromExplicitCoordinates(b.Right, a.Right, a.Top, a.Bottom);
					return new[] { result1, result2 };
				}
			}

			//no intersection
			return new[] { a };
		}
开发者ID:JeroenBos,项目名称:ASDE,代码行数:62,代码来源:RectangleExtensions.cs


注:本文中的System.Windows.Rect.GetCorners方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。