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


C# Rect.IntersectsWith方法代码示例

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


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

示例1: Collision

  int Collision(Rect b) {
    var playerRect = new Rect((int)ballX - ballSize, (int)ballY - ballSize, ballSize*2, ballSize*2);

    var leftRect = new Rect(b.X - 1, b.Y, 1, b.Height);
    var rightRect = new Rect(b.X + b.Width - 1, b.Y, 1, b.Height);
    var topRect = new Rect(b.X, b.Y - 1, b.Width, 1);
    var bottomRect = new Rect(b.X, b.Y + b.Height - 1, b.Width, 1);

    bool left = playerRect.IntersectsWith(leftRect);
    bool right = playerRect.IntersectsWith(rightRect);
    bool top = playerRect.IntersectsWith(topRect);
    bool bottom = playerRect.IntersectsWith(bottomRect);

    if (left && !right && !top && !bottom) return 1;
    if (!left && right && !top && !bottom) return 2;
    if (!left && !right && top && !bottom) return 3;
    if (!left && !right && !top && bottom) return 4;

    if (left && top) {
      var r1 = Rect.Intersect(playerRect, leftRect);
      var r2 = Rect.Intersect(playerRect, topRect);
      return r1.Height > r2.Width ? 1 : 3;
    }
    if (left && bottom) {
      var r1 = Rect.Intersect(playerRect, leftRect);
      var r2 = Rect.Intersect(playerRect, bottomRect);
      return r1.Height > r2.Width ? 1 : 4;
    }
    if (right && top) {
      var r1 = Rect.Intersect(playerRect, rightRect);
      var r2 = Rect.Intersect(playerRect, topRect);
      return r1.Height > r2.Width ? 2 : 3;
    }
    if (right && bottom) {
      var r1 = Rect.Intersect(playerRect, rightRect);
      var r2 = Rect.Intersect(playerRect, bottomRect);
      return r1.Height > r2.Width ? 2 : 4;
    }
    return 0;
  }
开发者ID:iamnp,项目名称:CSharpLiveCodingEnvironment,代码行数:40,代码来源:SimplePlatformer.cs

示例2: _IsSpatiallyCombinable

        private bool _IsSpatiallyCombinable(Rect rect1, Rect rect2, double inflateH, double inflateV)
        { 
            //Do these rects intersect? If so, we can combine
            if (rect1.IntersectsWith(rect2)) 
            { 
                return true;
            } 

            //Try inflating
            rect1.Inflate(inflateH, inflateV);
            if (rect1.IntersectsWith(rect2)) 
            {
                return true; 
            } 
            return false;
        } 
开发者ID:sjyanxin,项目名称:WPFSource,代码行数:16,代码来源:FixedSOMPageConstructor.cs

示例3: HandleInput

        private void HandleInput(RoutedEventArgs e)
        {
            if (mouseDown)
            {
                if (Mouse.LeftButton == MouseButtonState.Released)
                {
                    mouseDown = false;
                    if (border != null)
                    {
                        border.Visibility = Visibility.Collapsed;
                        border.Dispose();
                    }

                    return;
                }

                if (startPoint == GetMousePositionRelativeToContent()) return;

                List<object> itemsToSelect = new List<object>();
                List<object> itemsToUnSelect = new List<object>();

                // if the mouse position or the start point is outside the window, we trim it inside
                Point currentPoint = TrimPointToVisibleArea(GetMousePositionRelativeToContent());
                Point trimmedStartPoint = TrimPointToVisibleArea(startPoint);

                if (isFirstMove)
                {
                    isFirstMove = false;
                    border = new BorderSelectionAdorner(TreeView);
                }

                Rect selectionRect = new Rect(currentPoint, trimmedStartPoint);
                border.UpdatePosition(selectionRect);


                if (isFirstMove)
                {
                    if (!SelectionMultiple.IsControlKeyDown)
                    {
                        foreach (var item in TreeView.SelectedItems)
                        {
                            var treeViewItem = TreeView.GetTreeViewItemFor(item);
                            Rect itemRect = GetPositionOf(treeViewItem);

                            if (!selectionRect.IntersectsWith(itemRect))
                            {
                                itemsToUnSelect.Add(item);
                            }
                        }
                    }
                }

                foreach (var item in items)
                {
                    if (!item.IsVisible || item.IsEditing)
                    {
                        continue;
                    }

                    Rect itemRect = GetPositionOf(item);

                    if (selectionRect.IntersectsWith(itemRect))
                    {
                        if (isFirstMove)
                        {
                            itemsToSelect.Add(item.DataContext);
                        }
                        else
                        {
                            if (!TreeView.SelectedItems.Contains(item.DataContext))
                            {
                                itemsToSelect.Add(item.DataContext);
                            }
                        }
                    }
                    else
                    {
                        if (!SelectionMultiple.IsControlKeyDown && TreeView.SelectedItems.Contains(item.DataContext))
                        {
                            itemsToUnSelect.Add(item.DataContext);
                        }
                    }
                }

                ((SelectionMultiple)TreeView.Selection).SelectByRectangle(itemsToSelect, itemsToUnSelect);
                e.Handled = true;
            }
        }
开发者ID:YoshihiroIto,项目名称:TreeViewEx,代码行数:88,代码来源:BorderSelectionLogic.cs


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