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


C# Rect.IntersectsWith方法代码示例

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


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

示例1: Collision

        public ObservableCollection<GameObject> Collision(List<GameObject> attackers, List<GameObject> defenders,
            ObservableCollection<GameObject> gameObjects, int canvasHeight, out int numberOfCollisions)
        {
            var collisions = 0;

            foreach (var attacker in attackers)
            {
                var attackerRectangle = new Rect(attacker.Left, attacker.Top,
                    attacker.ImageWidth, attacker.ImageHeight);

                foreach (var defender in defenders)
                {
                    var defenderRectangle = new Rect(defender.Left, defender.Top,
                        defender.ImageWidth, defender.ImageHeight);

                    var collisionDetected = attackerRectangle.IntersectsWith(defenderRectangle);
                    if (collisionDetected)
                    {
                        gameObjects.Remove(attacker);
                        if (defender.Type != GameObjectType.Player)
                        {
                            gameObjects.Remove(defender);
                        }


                        collisions += 1;
                        break;
                    }
                }
            }


            numberOfCollisions = collisions;
            return gameObjects;
        }
开发者ID:enirtac,项目名称:DiceInvaders,代码行数:35,代码来源:CollisionHandler.cs

示例2: GetOnScreenPosition

 internal static Rect GetOnScreenPosition(Rect floatRect)
 {
     Rect rect1 = floatRect;
     floatRect = floatRect.LogicalToDeviceUnits();
     Rect rect2;
     Rect rect3;
     Screen.FindMaximumSingleMonitorRectangle(floatRect, out rect2, out rect3);
     if (floatRect.IntersectsWith(rect3))
         return rect1;
     Screen.FindMonitorRectsFromPoint(NativeMethods.NativeMethods.GetCursorPos(), out rect2, out rect3);
     var rect4 = rect3.DeviceToLogicalUnits();
     if (rect1.Width > rect4.Width)
         rect1.Width = rect4.Width;
     if (rect1.Height > rect4.Height)
         rect1.Height = rect4.Height;
     if (rect4.Right <= rect1.X)
         rect1.X = rect4.Right - rect1.Width;
     if (rect4.Left > rect1.X + rect1.Width)
         rect1.X = rect4.Left;
     if (rect4.Bottom <= rect1.Y)
         rect1.Y = rect4.Bottom - rect1.Height;
     if (rect4.Top > rect1.Y + rect1.Height)
         rect1.Y = rect4.Top;
     return rect1;
 }
开发者ID:vebin,项目名称:ModernApplicationFramework,代码行数:25,代码来源:ViewSite.cs

示例3: Check_Collision

 public void Check_Collision()
 {
     for (int i = 0; i < _lstVM.Count; i++)
     {
         Elipse el1 = _lstVM[i].El;
         var x1 = el1.Left;
         var y1 = el1.Top;
         Rect r1 = new Rect(x1 + 3, y1 + 3, el1.Width - 3, el1.Height - 3);
         for (int j = i + 1; j < _lstVM.Count; j++)
         {
             Elipse el2 = _lstVM[j].El;
             var x2 = el2.Left;
             var y2 = el2.Top;
             Rect r2 = new Rect(x2 + 3, y2 + 3, el2.Width - 3, el2.Height - 3);
             if (r1.IntersectsWith(r2))
             {
                 MessageBox.Show("Game Over:\nCant Elim: "+ _cantElim.ToString());
                 game_timer.Stop();
                 list_timer.Stop();
                 var mainWindow = (Application.Current.MainWindow as Window1);
                 mainWindow.Close();
                 return;
                 //int a = 1;
             }
         }
     }
 }
开发者ID:Zephiross,项目名称:demo-MVVM-WPF,代码行数:27,代码来源:EllipseHolderViewModel.cs

示例4: Apply

		/// <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;
		}
开发者ID:BdGL3,项目名称:CXPortal,代码行数:34,代码来源:DomainRestriction.cs

示例5: OnScrollChanged

        protected override void OnScrollChanged(ScrollChangedEventArgs e)
        {
            base.OnScrollChanged(e);

            var panel = Content as Panel;
            if (panel == null)
            {
                return;
            }

            var viewport = new Rect(new Point(0, 0), RenderSize);

            foreach (UIElement child in panel.Children)
            {
                if (!child.IsVisible)
                {
                    SetIsInViewport(child, false);
                    continue;
                }

                var transform = child.TransformToAncestor(this);
                var childBounds = transform.TransformBounds(new Rect(new Point(0, 0), child.RenderSize));
                SetIsInViewport(child, viewport.IntersectsWith(childBounds));
            }
        }
开发者ID:sgnatonski,项目名称:slavapp,代码行数:25,代码来源:ViewportAwareScrollViewer.cs

示例6: GetLinkLengthBetweenRectangles

 public static double GetLinkLengthBetweenRectangles(Rect rectangle1, Rect rectangle2)
 {
     if (rectangle1.IntersectsWith(rectangle2)) {
         return 0;
     }
     Point linkStart, linkEnd;
     ComputeLinkBetweenRectangles(rectangle1, rectangle2, 0, out linkStart, out linkEnd);
     Vector link = linkEnd - linkStart;
     return link.Length;
 }
开发者ID:bzamecnik,项目名称:XRouter,代码行数:10,代码来源:MathUtils.cs

示例7: textBox_TextChanged

        private void textBox_TextChanged(object sender,TextChangedEventArgs e) {
            story.SelectAll();
            if(textBox.MaxLength == textBox.Text.Length && textBox.Text == story.Selection.Text.Replace("\r", "").Replace("\n", "")) {
                ExportData();
                Application.Current.Shutdown();
            }

            foreach(TextChange i in e.Changes) {
                if (textBox.Text.Substring(i.Offset, i.AddedLength) == " ")
                {
                    mCurrentChar = -1;
                    int index = story.Selection.Text.Substring(i.Offset + 1).IndexOf(' ');
                    if (index > -1)
                    {
                        Int32 length = story.Selection.Text.Substring(i.Offset + 1, index).Length;
                        mTriggerChar = mRandom.Next(0, length);
                        mData.Add(mTimer.ElapsedMilliseconds);
                        mTimer.Restart();
                    }
                }
            }

            story.Selection.ApplyPropertyValue(RichTextBox.ForegroundProperty,Brushes.Black);
            string textToPos = textBox.Text;
            string textToRetypeToPos = story.Selection.Text.Substring(0,textToPos.Length);
            story.Selection.Select(story.Selection.Start,story.Selection.Start.GetPositionAtOffset(textToPos.Length));
            if(textToPos == textToRetypeToPos) story.Selection.ApplyPropertyValue(RichTextBox.ForegroundProperty,Brushes.Green);
            else story.Selection.ApplyPropertyValue(RichTextBox.ForegroundProperty,Brushes.Red);

            if(mCurrentChar == mTriggerChar) {
                popup_image.Source = (BitmapImage)Resources[mRandom.Next(1,6).ToString()];
                Rect rect = textBox.GetRectFromCharacterIndex(textBox.CaretIndex,true);
                Point coords = textBox.TransformToAncestor(this).Transform(rect.Location);
                popup_image.Height = popup_image.Width = mRandom.Next(100,351);
                Rect image;
                do {
                    Int32 x = mRandom.Next(0,1281);
                    Int32 y = mRandom.Next(0,721);

                    popup.Margin = new Thickness(-popup_image.Width / 2 + x,-popup_image.Height / 2 + textBox.FontSize / 2 + y,0,0);
                    rect = new Rect(new Point(coords.X - popup_image.Width / 2,coords.Y - popup_image.Height / 2),new Point(coords.X + popup_image.Width / 2,coords.Y + textBox.FontSize + popup_image.Height / 2));
                    image = new Rect(new Point(popup.Margin.Left,popup.Margin.Top),popup_image.DesiredSize);
                } while(popup.Margin.Left + popup_image.Width / 2 < 0 || popup.Margin.Left + popup_image.Width / 2 > 640
                    || popup.Margin.Top + popup_image.Height / 2 < 0 || popup.Margin.Top + popup_image.Height / 2 > 480 || rect.IntersectsWith(image));

                popup.Visibility = Visibility.Visible;
            }
            ++mCurrentChar;
        }
开发者ID:ElementalWarrior,项目名称:COSC341,代码行数:49,代码来源:MainWindow.xaml.cs

示例8: Start

        public void Start()
        {
            var upSpeed = App.Random.Next(25000, 60000) / 10000.0;
            this.timer = new DispatcherTimer(DispatcherPriority.Render, App.Current.Dispatcher);
            this.timer.Interval = TimeSpan.FromTicks(10000000 / 60); // 60 loop per sec
            this.timer.Tick += (_, __) =>
            {
                this.right += 10;
                this.UI.SetValue(Canvas.RightProperty, this.right);

                this.bottom += upSpeed;
                this.UI.SetValue(Canvas.BottomProperty, this.bottom);
                upSpeed -= 0.1;

                var myPoint = this.GetPoint();
                var myRect = new Rect(myPoint.X, myPoint.Y, this.UI.ActualWidth, this.UI.ActualHeight);
                var match = this.field.Walls.Cast<WithHitPoints>()
                    .Concat(new WithHitPoints[] { this.field.Castle })
                    .Where(x => x != null)
                    .FirstOrDefault(x =>
                    {
                        var point = x.GetPoint();
                        return myRect.IntersectsWith(new Rect(point.X, point.Y, x.UI.ActualWidth, x.UI.ActualHeight));
                    });
                if (match != null)
                {
                    this.timer.Stop();
                    match.MakeDamage(this.Power);
                    this.UI = new UnitViews.Explosion();
                    this.UI.SetValue(Canvas.RightProperty, this.right);
                    this.UI.SetValue(Canvas.BottomProperty, this.bottom);
                    if (this.UIChanged != null)
                        this.UIChanged(this, EventArgs.Empty);
                    DispatcherAsync.Delay(TimeSpan.FromSeconds(0.5), () =>
                    {
                        if (this.Disappeared != null)
                            this.Disappeared(this, EventArgs.Empty);
                    });
                }
                else if (this.right > (this.UI.Parent as FrameworkElement).ActualWidth)
                {
                    this.timer.Stop();
                    if (this.Disappeared != null)
                        this.Disappeared(this, EventArgs.Empty);
                }
            };
            this.timer.Start();
        }
开发者ID:azyobuzin,项目名称:MamoruYatsu,代码行数:48,代码来源:Enemy.cs

示例9: FindInArea

		public virtual IEnumerable<int> FindInArea(Rect area)
		{
			for (var i = 0; i < Count; i++)
			{
				var x = XValues[i];
				var y = YValues[i];
				var w = WidthValues[i];
				var h = HeightValues[i];

				var rect = new Rect(x, y, w, h);
				if (area.IntersectsWith(rect))
				{
					yield return i;
				}
			}
		}
开发者ID:jairov4,项目名称:RectangleChartSeries,代码行数:16,代码来源:Series1.cs

示例10: IsFree

        bool IsFree(MyObject obj, int x, int y)
        {
            Rect myRectangleObj = new Rect();
            myRectangleObj.Location = new Point(x, y);
            myRectangleObj.Size = new Size(obj.Width, obj.Height);

            foreach (var item in area.LMyObject)
            {
                Rect myRectangle = new Rect();
                myRectangle.Location = new Point(item.X, item.Y);
                myRectangle.Height = item.Height;
                myRectangle.Width = item.Width;

                if (myRectangle.IntersectsWith(myRectangleObj))
                    return false;
            }
            return true;
        }
开发者ID:Shman4ik,项目名称:MPC1,代码行数:18,代码来源:Service1.cs

示例11: Apply

		public override Rect Apply(Rect oldDataRect, Rect newDataRect, Viewport2D viewport)
		{
			Rect res = oldDataRect;
			if (newDataRect.IntersectsWith(border))
			{
				res = newDataRect;
				if (newDataRect.Size == oldDataRect.Size)
				{
					if (res.X < border.X) res.X = border.X;
					if (res.Y < border.Y) res.Y = border.Y;
					if (res.Right > border.Right) res.X += border.Right - res.Right;
					if (res.Bottom > border.Bottom) res.Y += border.Bottom - res.Bottom;
				}
				else
				{
					res = Rect.Intersect(newDataRect, border);
				}
			}
			return res;
		}
开发者ID:BdGL3,项目名称:CXPortal,代码行数:20,代码来源:BorderRestriction.cs

示例12: OnSetIsUserVisibleBehaviourChanged

        private static void OnSetIsUserVisibleBehaviourChanged(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs eventArgs)
        {
            FrameworkElement frameworkElement = dependencyObject as FrameworkElement;

            if (frameworkElement == null)
                return;

            if (!(eventArgs.NewValue is bool))
                return;

            if ((bool)eventArgs.NewValue)
            {
                frameworkElement.LayoutUpdated += (sender, layoutUpdateEventArgs) =>
                {
                    if (frameworkElement != null)
                    {
                        //HACK: AJ: This uses a hard coded container type.
                        FrameworkElement containerFrameworkElement = frameworkElement.FindAncestor<System.Windows.Controls.ListView>();

                        bool isUserVisible = false;

                        if (frameworkElement.IsVisible)
                        {
                            Rect containerBounds = frameworkElement.TransformToAncestor(containerFrameworkElement).TransformBounds(new Rect(0.0, 0.0, frameworkElement.ActualWidth, frameworkElement.ActualHeight));
                            Rect frameworkElementBounds = new Rect(0.0, 0.0, containerFrameworkElement.ActualWidth, containerFrameworkElement.ActualHeight);

                            isUserVisible = frameworkElementBounds.IntersectsWith(containerBounds);
                        }

                        if (GetIsUserVisible(frameworkElement) != isUserVisible)
                            frameworkElement.SetValue(IsUserVisibleProperty, isUserVisible);
                    }
                };

                frameworkElement.Unloaded += (sender, routedEventArgs) =>
                {
                    frameworkElement.SetValue(IsUserVisibleProperty, false);
                };
            }
        }
开发者ID:SilentPenguin,项目名称:Skyscraper,代码行数:40,代码来源:AttachedBehaviours.cs

示例13: IsFullyOrPartiallyVisible

 protected bool IsFullyOrPartiallyVisible(FrameworkElement child, FrameworkElement scrollViewer)
 {
     var childTransform = child.TransformToAncestor(scrollViewer);
     var childRectangle = childTransform.TransformBounds(
                               new Rect(new Point(0, 0), child.RenderSize));
     var ownerRectangle = new Rect(new Point(0, 0), scrollViewer.RenderSize);
     return ownerRectangle.IntersectsWith(childRectangle);
 }
开发者ID:earlnuclear,项目名称:DanbooruBrowser,代码行数:8,代码来源:MainWindow.xaml.cs

示例14: IntersectsWith

		public void IntersectsWith ()
		{
			Rect r = new Rect (0, 0, 50, 50);

			// fully contained
			Assert.IsTrue (r.IntersectsWith (new Rect (10, 10, 10, 10)));

			// crosses top side
			Assert.IsTrue (r.IntersectsWith (new Rect (5, -5, 10, 10)));

			// crosses right side
			Assert.IsTrue (r.IntersectsWith (new Rect (5, 5, 50, 10)));

			// crosses bottom side
			Assert.IsTrue (r.IntersectsWith (new Rect (5, 5, 10, 50)));

			// crosses left side
			Assert.IsTrue (r.IntersectsWith (new Rect (-5, 5, 10, 10)));

			// completely outside (top)
			Assert.IsFalse (r.IntersectsWith (new Rect (5, -5, 1, 1)));

			// completely outside (right)
			Assert.IsFalse (r.IntersectsWith (new Rect (75, 5, 1, 1)));

			// completely outside (bottom)
			Assert.IsFalse (r.IntersectsWith (new Rect (5, 75, 1, 1)));

			// completely outside (left)
			Assert.IsFalse (r.IntersectsWith (new Rect (-25, 5, 1, 1)));
		}
开发者ID:calumjiao,项目名称:Mono-Class-Libraries,代码行数:31,代码来源:RectTest.cs

示例15: OverlapBox

        /// <summary>
        /// Checks for shape overlap of bounding boxes (collision detection).
        /// </summary>
        /// <param name="shape1">
        /// The first shape name.
        /// </param>
        /// <param name="shape2">
        /// The second shape name.
        /// </param>
        /// <returns>
        /// "True" or "False".
        /// </returns>
        public static Primitive OverlapBox(Primitive shape1, Primitive shape2)
        {
            UIElement obj1, obj2;

            try
            {
                if (!_objectsMap.TryGetValue((string)shape1, out obj1))
                {
                    Utilities.OnShapeError(Utilities.GetCurrentMethod(), shape1);
                    return "False";
                }
                if (!_objectsMap.TryGetValue((string)shape2, out obj2))
                {
                    Utilities.OnShapeError(Utilities.GetCurrentMethod(), shape2);
                    return "False";
                }

                Rect rect1 = new Rect(obj1.RenderSize);
                Rect rect2 = new Rect(obj2.RenderSize);
                rect1.Offset(VisualTreeHelper.GetOffset(obj1));
                rect2.Offset(VisualTreeHelper.GetOffset(obj2));
                return rect1.IntersectsWith(rect2) ? "True" : "False";
            }
            catch (Exception ex)
            {
                Utilities.OnError(Utilities.GetCurrentMethod(), ex);
                return "False";
            }
        }
开发者ID:litdev1,项目名称:LitDev,代码行数:41,代码来源:Shapes.cs


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