本文整理汇总了C#中Rectangle2D.Intersects方法的典型用法代码示例。如果您正苦于以下问题:C# Rectangle2D.Intersects方法的具体用法?C# Rectangle2D.Intersects怎么用?C# Rectangle2D.Intersects使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Rectangle2D
的用法示例。
在下文中一共展示了Rectangle2D.Intersects方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SimpleCollisionTest
/// <summary>
/// Test whether label collides.
/// </summary>
/// <param name="newLabel"></param>
/// <returns>true if label collided with another (more important or earlier) label</returns>
public Boolean SimpleCollisionTest(Label2D newLabel)
{
if (labelList.Contains(newLabel))
{
return false;
}
Size2D newSize = TextRenderer.MeasureString(newLabel.Text, newLabel.Font);
newSize = new Size2D(newSize.Width + 2 * newLabel.CollisionBuffer.Width, newSize.Height + 2 * newLabel.CollisionBuffer.Height);
Rectangle2D newRect = new Rectangle2D(new Point2D(newLabel.Location.X - newLabel.CollisionBuffer.Width, newLabel.Location.Y - newLabel.CollisionBuffer.Height), newSize);
foreach (Label2D label in labelList)
{
Size2D size = TextRenderer.MeasureString(label.Text, label.Font);
size = new Size2D(size.Width + 2*label.CollisionBuffer.Width, size.Height + 2*label.CollisionBuffer.Height);
Rectangle2D rect =
new Rectangle2D(
new Point2D(label.Location.X - newLabel.CollisionBuffer.Width, label.Location.Y - label.CollisionBuffer.Height),
size);
if (newRect.Intersects(rect))
{
return true;
}
}
labelList.Add(newLabel);
return false;
}
示例2: IntersectsTest
public void IntersectsTest()
{
Rectangle2D r1 = Rectangle2D.Empty;
Rectangle2D r2 = Rectangle2D.Zero;
Rectangle2D r3 = new Rectangle2D(0, 0, 10, 10);
Rectangle2D r4 = new Rectangle2D(new Point2D(5, 5), new Size2D(10, 10));
Assert.False(r1.Intersects(Rectangle2D.Empty));
Assert.False(r1.Intersects(r2));
Assert.False(r2.Intersects(r1));
Assert.True(r2.Intersects(r3));
Assert.True(r3.Intersects(r4));
Assert.True(r4.Intersects(r4));
}
示例3: AdvancedCollisionTest
private Boolean AdvancedCollisionTest(Label2D newLabel, Int32 depth)
{
//newLabel.Style.Halo = new StylePen(newLabel.Style.Foreground, 1);
Size2D newSize = TextRenderer.MeasureString(newLabel.Text, newLabel.Font);
newSize = new Size2D(newSize.Width + 2 * newLabel.CollisionBuffer.Width, newSize.Height + 2 * newLabel.CollisionBuffer.Height);
Rectangle2D newRect = new Rectangle2D(new Point2D(newLabel.Location.X - newLabel.CollisionBuffer.Width, newLabel.Location.Y - newLabel.CollisionBuffer.Height), newSize);
foreach (Label2D label in labelList)
{
Size2D size = TextRenderer.MeasureString(label.Text, label.Font);
size = new Size2D(size.Width + 2 * label.CollisionBuffer.Width, size.Height + 2 * label.CollisionBuffer.Height);
Rectangle2D rect = new Rectangle2D(new Point2D(label.Location.X - newLabel.CollisionBuffer.Width, label.Location.Y - label.CollisionBuffer.Height), size);
if(newRect.Intersects(rect))
{
if (label.Text == newLabel.Text)
return true;
if (depth == 5)
{
/* *
StyleFont font = newLabel.Font;
newLabel.Style.Foreground = new SolidStyleBrush(StyleColor.Yellow);
newLabel.Style.Halo = new StylePen(newLabel.Style.Foreground, 1);
newLabel.Font = new StyleFont(font.FontFamily, new Size2D(font.Size.Width / 3.0, font.Size.Height / 3.0), font.Style);
newLabel.Text = newLabel.Text + ":" + label.Text;
labelList.Add(newLabel);
/*/
// give up on this label after 5 tries at moving it
return true;
/* */
}
else
{
if(newRect.Location.Y > (rect.Location.Y + rect.Height/2.0))
{
newLabel.Location = new Point2D(newLabel.Location.X, rect.Location.Y + rect.Height + 3);
}
else
{
newLabel.Location = new Point2D(newLabel.Location.X, rect.Location.Y - newRect.Height - 3);
}
//newLabel.Style.Foreground = new SolidStyleBrush(StyleColor.Blue);
////StyleFont font = newLabel.Font;
////newLabel.Font = new StyleFont(font.FontFamily, new Size2D(font.Size.Width / depth, font.Size.Height / depth), font.Style);
//newLabel.Style.Halo = new StylePen(newLabel.Style.Foreground, 1);
return AdvancedCollisionTest(newLabel, depth + 1);
}
}
//else
//{
// newLabel.Style.Halo = new StylePen(new SolidStyleBrush(StyleColor.Purple), 1);
//}
}
labelList.Add(newLabel);
return false;
}