예제 #1
0
 public void ContainsCircle()
 {
     Assert.AreEqual(ContainmentType.Contains, rect2.Contains(circle3), "1");
     Assert.AreEqual(ContainmentType.Intersects, rect1.Contains(circle3), "2");
     Assert.AreEqual(ContainmentType.Intersects, rect1.Contains(circle2), "3");
     Assert.AreEqual(ContainmentType.Disjoint, rect0.Contains(circle1), "4");
 }
        public void ContainsTest()
        {
            Assert.AreEqual(true, _boundingA.Contains(_boundingA.Center));
            Assert.AreEqual(true, _boundingA.Contains(new Point2D(5, 10)));

            Assert.AreEqual(false, _boundingA.Contains(new Point2D(-5, -5)));
        }
        public void ContainsPolygon()
        {
            var exactlyOverlappingPolygon = new BoundingPolygon(_testAabb.Corners());
            var closelyContainedPolygon   = new BoundingPolygon(
                new BoundingRectangle(0.001f, 0.001f, 19.999f, 19.999f).Corners());
            var closelyNonIntersectingPolygon = new BoundingPolygon(
                new BoundingRectangle(-1, -1, -0.001f, -0.001f).Corners());
            var closelyIntersectingPolygon = new BoundingPolygon(
                new BoundingRectangle(-1, -1, 0.001f, 0.001f).Corners());

            Assert.That(_testAabb.Contains(exactlyOverlappingPolygon), Is.EqualTo(Containment.Contains));
            Assert.That(_testAabb.Contains(closelyContainedPolygon), Is.EqualTo(Containment.Contains));
            Assert.That(_testAabb.Contains(closelyNonIntersectingPolygon), Is.EqualTo(Containment.Disjoint));
            Assert.That(_testAabb.Contains(closelyIntersectingPolygon), Is.EqualTo(Containment.Intersects));
        }
        public void AssertThat_ContainsRect_ContainsEdgeRect()
        {
            var outer = new BoundingRectangle(new Vector2(0, 0), new Vector2(10, 10));
            var inner = new BoundingRectangle(new Vector2(0, 0), new Vector2(2, 2));

            Assert.IsTrue(outer.Contains(inner));
        }
        public void AssertThat_ContainsRect_DoesNotContainDisjointRect()
        {
            var outer = new BoundingRectangle(new Vector2(0, 0), new Vector2(10, 10));
            var inner = new BoundingRectangle(new Vector2(20, 20), new Vector2(30, 30));

            Assert.IsFalse(outer.Contains(inner));
        }
        public void AssertThat_ContainsRect_DoesNotContainOverhangingRect()
        {
            var outer = new BoundingRectangle(new Vector2(0, 0), new Vector2(10, 10));
            var inner = new BoundingRectangle(new Vector2(-1, -1), new Vector2(2, 2));

            Assert.IsFalse(outer.Contains(inner));
        }
예제 #7
0
 public void ContainsPoint()
 {
     BoundingRectangle rect = new BoundingRectangle(0, 0, 2, 2);
     Assert.AreEqual(ContainmentType.Contains, rect.Contains(new Vector2D(1, 1)), "1");
     Assert.AreEqual(ContainmentType.Contains, rect.Contains(new Vector2D(2, 2)), "2");
     Assert.AreEqual(ContainmentType.Contains, rect.Contains(new Vector2D(0, 2)), "3");
     Assert.AreEqual(ContainmentType.Contains, rect.Contains(new Vector2D(0, 0)), "4");
     Assert.AreEqual(ContainmentType.Disjoint, rect.Contains(new Vector2D(2, 3)), "5");
     Assert.AreEqual(ContainmentType.Disjoint, rect.Contains(new Vector2D(-1, 0)), "6");
     Assert.AreEqual(ContainmentType.Disjoint, rect.Contains(new Vector2D(-.0001f, 0)), "7");
     Assert.AreEqual(ContainmentType.Disjoint, rect.Contains(new Vector2D(3, 1)), "8");
     Assert.AreEqual(ContainmentType.Disjoint, rect.Contains(new Vector2D(1, -1)), "9");
 }
예제 #8
0
        public void ContainsPoint()
        {
            BoundingRectangle rect = new BoundingRectangle(0, 0, 2, 2);

            Assert.AreEqual(ContainmentType.Contains, rect.Contains(new Vector2D(1, 1)), "1");
            Assert.AreEqual(ContainmentType.Contains, rect.Contains(new Vector2D(2, 2)), "2");
            Assert.AreEqual(ContainmentType.Contains, rect.Contains(new Vector2D(0, 2)), "3");
            Assert.AreEqual(ContainmentType.Contains, rect.Contains(new Vector2D(0, 0)), "4");
            Assert.AreEqual(ContainmentType.Disjoint, rect.Contains(new Vector2D(2, 3)), "5");
            Assert.AreEqual(ContainmentType.Disjoint, rect.Contains(new Vector2D(-1, 0)), "6");
            Assert.AreEqual(ContainmentType.Disjoint, rect.Contains(new Vector2D(-.0001f, 0)), "7");
            Assert.AreEqual(ContainmentType.Disjoint, rect.Contains(new Vector2D(3, 1)), "8");
            Assert.AreEqual(ContainmentType.Disjoint, rect.Contains(new Vector2D(1, -1)), "9");
        }
예제 #9
0
        public virtual IRawElementProviderFragment ElementProviderFromPoint(double x, double y)
        {
            if (!BoundingRectangle.Contains(x, y))
            {
                return(null);
            }

            return(this);
        }
예제 #10
0
        public override bool OnPointerUp(IGuiContext context, GuiPointerEventArgs args)
        {
            if (IsFocused && BoundingRectangle.Contains(args.Position))
            {
                IsChecked = !IsChecked;
            }

            return(base.OnPointerUp(context, args));
        }
예제 #11
0
파일: XNA_Shape.cs 프로젝트: vb0067/LGame
 public virtual bool Contains(Vector2 point)
 {
     if (BoundingRectangle.Contains((int)point.X, (int)point.Y))
     {
         point = new Vector2(point.X - BoundingRectangle.X, point.Y - BoundingRectangle.Y);
         return(pfillTextureData[(int)point.X + ((int)point.Y * pfillTexture.Width)].A > 0);
     }
     return(false);
 }
예제 #12
0
        public override void OnPointerUp(GuiPointerEventArgs args)
        {
            base.OnPointerUp(args);

            if (IsFocused && BoundingRectangle.Contains(args.Position))
            {
                IsChecked = !IsChecked;
            }
        }
예제 #13
0
        /// <summary>
        /// Find the closest vertex to the given point
        /// </summary>
        /// <param name="v"></param>
        /// <returns></returns>
        //public Vertex<TVTag, TETag, TFTag> FindClosestVertex(Vector2 v)
        //{
        //    var shortest = float.MaxValue;
        //    Vertex<TVTag, TETag, TFTag> closest = null;

        //    //Search for the best vertex, initially starting with a small bounds query and progressively expanding it
        //    var size = 10;
        //    var queried = new HashSet<Vertex<TVTag, TETag, TFTag>>();
        //    while (closest == null && queried.Count < _vertices.Count)
        //    {
        //        var bounds = new BoundingRectangle(v - new Vector2(size), v + new Vector2(size));

        //        var vertices = _vertices.Intersects(bounds);

        //        foreach (var vertex in vertices)
        //        {
        //            //Skip this vertex, we've already tried it
        //            if (queried.Contains(vertex))
        //                continue;

        //            //Check all found vertices and pick the closest
        //            var d = (v - vertex.Position).LengthSquared();
        //            if (d < shortest)
        //            {
        //                shortest = d;
        //                closest = vertex;
        //            }
        //        }

        //        if (closest != null)
        //        {
        //            queried.UnionWith(vertices);
        //            size *= 2;
        //        }
        //    }

        //    return closest;
        //}

        /// <summary>
        /// Find all vertices in the given rectangle
        /// </summary>
        /// <param name="rectangle"></param>
        /// <returns></returns>
        public IEnumerable <Vertex <TVTag, TETag, TFTag> > FindVertices(BoundingRectangle rectangle)
        {
            Contract.Ensures(Contract.Result <IEnumerable <Vertex <TVTag, TETag, TFTag> > >() != null);
            Contract.Ensures(Contract.ForAll(Contract.Result <IEnumerable <Vertex <TVTag, TETag, TFTag> > >(), a => a != null && !a.IsDeleted));

            //We need to do intersection then containment because the bounding box for a vertex is slightly larger than the vertex!
            return(_vertices
                   .Intersects(rectangle)
                   .Where(a => rectangle.Contains(a.Position)));
        }
예제 #14
0
파일: Game.cs 프로젝트: SillyLossy/tanks
        public void Update()
        {
            foreach (var action in PendingActions)
            {
                InputHandlers[action].Invoke();
            }
            PendingActions.Clear();

            CurrentLevel.Projectiles.ForEach(p => p.Update());
            CurrentLevel.Projectiles.RemoveAll(p => !BoundingRectangle.Contains(p.X, p.Y));
        }
        public virtual IRawElementProviderFragment ElementProviderFromPoint(double x, double y)
        {
            if (!BoundingRectangle.Contains(x, y))
            {
                return(null);
            }

            // TODO: Check for child fragments.  Can this logic be generalized?

            return(this);
        }
예제 #16
0
        public void Update(GameTime gameTime)
        {
            // Bounce along a sine curve over time.
            // Include the X coordinate so that neighboring items bounce in a nice wave pattern.
            double t       = gameTime.TotalGameTime.TotalSeconds * BounceRate + (Position.X * 3) * BounceSync;
            float  elapsed = (float)(gameTime.ElapsedGameTime.TotalSeconds);

            if (Collected)
            {
                Scale = (Vector2.Distance(collector.OriginPosition, position) / initialDistance) * .75f;
            }
            Scale = MathHelper.Clamp(Scale, 0, .75f);

            if (Collected)
            {
                Distance = new Vector2(level.Player.Position.X - position.X, level.Player.OriginPosition.Y - position.Y);
                //Start going towards the player
                position += Distance * speed * elapsed;
                speed    += 8f * elapsed;
            }
            else
            {
                //If not collected, apply standard physics
                base.ApplyPhysics(gameTime, true);
                if (Velocity == Vector2.Zero)
                {
                    bounce = (float)Math.Sin(t) * BounceHeight * Tile.Width;
                }
            }

            foreach (PlayerCharacter pl in level.Players)
            {
                if (BoundingRectangle.Contains(pl.OriginPosition.ToPoint()) || Scale < .075f) //If we touch it
                {
                    if (pl.FitsInInventory(slot))
                    {
                        Level.Collectables.Remove(this);
                    }
                    else
                    {
                        Collected = false;
                    }
                }
                //If we are within XXX blocks of it
                else if (Collected == false && Vector2.Distance(Position, pl.OriginPosition) <= Tile.Width * PickupRadius)
                {
                    if (pl.FitsInInventory(slot))
                    {
                        OnCollected(pl);
                    }
                }
            }
        }
예제 #17
0
        public bool TryGetIntersection(Vector2D point, out IntersectionInfo result)
        {
            ContainmentType contains;

            rect.Contains(ref point, out contains);
            if (contains == ContainmentType.Contains)
            {
                int x = (int)Math.Floor((point.X - rect.Min.X) * gridSpacingInv);
                int y = (int)Math.Floor((point.Y - rect.Min.Y) * gridSpacingInv);

                Scalar bottomLeft  = nodes[x][y];
                Scalar bottomRight = nodes[x + 1][y];
                Scalar topLeft     = nodes[x][y + 1];
                Scalar topRight    = nodes[x + 1][y + 1];

                if (bottomLeft <= 0 ||
                    bottomRight <= 0 ||
                    topLeft <= 0 ||
                    topRight <= 0)
                {
                    Scalar xPercent = (point.X - (gridSpacing * x + rect.Min.X)) * gridSpacingInv;
                    Scalar yPercent = (point.Y - (gridSpacing * y + rect.Min.Y)) * gridSpacingInv;

                    Scalar top, bottom, distance;

                    MathHelper.Lerp(ref topLeft, ref topRight, ref xPercent, out top);
                    MathHelper.Lerp(ref bottomLeft, ref bottomRight, ref xPercent, out bottom);
                    MathHelper.Lerp(ref bottom, ref top, ref yPercent, out distance);

                    if (distance <= 0)
                    {
                        Scalar right, left;

                        MathHelper.Lerp(ref bottomRight, ref topRight, ref yPercent, out right);
                        MathHelper.Lerp(ref bottomLeft, ref topLeft, ref yPercent, out left);

                        Vector2D normal;
                        normal.X = right - left;
                        normal.Y = top - bottom;
                        //Vector2D.Normalize(ref normal, out result.Normal);
                        result.rawNormal  = normal;
                        result.normalized = false;
                        result.Position   = point;
                        result.Distance   = distance;
                        return(true);
                    }
                }
            }
            result = IntersectionInfo.Zero;
            return(false);
        }
예제 #18
0
        // Have an update and a draw method! Handle logic in the game 1!

        public void Update(GameTime gameTime)
        {
            // Declare variable to keep track of mouse state.
            var mouseState = Mouse.GetState();

            var mousePosition = new Point(mouseState.X, mouseState.Y);

            // If the user clicks on the colour...
            if (mouseState.LeftButton == ButtonState.Pressed && BoundingRectangle.Contains(mousePosition))
            {
                // ...This colour has been selected by the player.
                Clicked = true;
            }
        }
예제 #19
0
        public override bool OnPointerUp(IGuiContext context, GuiPointerEventArgs args)
        {
            _isPointerDown = false;

            if (IsPressed)
            {
                IsPressed = false;

                if (BoundingRectangle.Contains(args.Position) && IsEnabled)
                {
                    TriggerClicked();
                }
            }
            return(base.OnPointerUp(context, args));
        }
예제 #20
0
        public override void OnPointerUp(GuiPointerEventArgs args)
        {
            base.OnPointerUp(args);

            _isPointerDown = false;

            if (IsPressed)
            {
                IsPressed = false;

                if (BoundingRectangle.Contains(args.Position) && IsEnabled)
                {
                    Clicked?.Invoke(this, EventArgs.Empty);
                }
            }
        }
        public void UnrotatedRectangleContainsPointWorks()
        {
            var rect = new BoundingRectangle(new Vector2d(3, 2), new Size2d(6, 4));

            Assert.True(rect.Contains(rect.Position));

            foreach (var vertex in rect.Corners())
            {
                Assert.True(rect.Contains(vertex));
            }

            Assert.False(rect.Contains(new Vector2d(-1, 0)));
            Assert.False(rect.Contains(rect.TopRight + 1));
            Assert.False(rect.Contains(rect.BotRight + 1));
            Assert.False(rect.Contains(rect.TopLeft - 1));
            Assert.False(rect.Contains(rect.BotLeft - 1));
        }
        public override bool OnPointerUp(IGuiContext context, PointerEventArgs args)
        {
            base.OnPointerUp(context, args);

            if (BoundingRectangle.Contains(args.Position))
            {
                HoverStyle?.Revert(this);
                CheckedHoverStyle?.Revert(this);

                IsChecked = !IsChecked;

                if (IsChecked)
                {
                    CheckedHoverStyle?.Apply(this);
                }
                else
                {
                    HoverStyle?.Apply(this);
                }
            }

            return(true);
        }
예제 #23
0
        public override bool Contains(float x, float y)
        {
            if (!BoundingRectangle.Contains(x, y))
            {
                return(false);
            }

            int numPoints = points.Length;

            bool contains = false;

            for (int i = 0; i < numPoints; i++)
            {
                Vector2 p  = points[i];
                Vector2 p1 = points[(i + 1) % numPoints];

                if ((p.y <= y && y < p1.y || p1.y <= y && y < p.y) && x < (p1.x - p.x) / (p1.y - p.y) * (y - p.y) + p.x)
                {
                    contains = !contains;
                }
            }

            return(contains);
        }
예제 #24
0
 public override bool Contains(Vector2 cursorLocation)
 {
     return(BoundingRectangle.Contains(cursorLocation));
 }
        public void RotatedRectangleContainsPointWorks()
        {
            var rect = new BoundingRectangle(new Vector2d(2.5, 2.5), new Size2d(4.24, 2.83))
            {
                Rotation = Math.PI / 4
            };

            Assert.True(rect.Contains(rect.Position));

            foreach (var vertex in rect.Corners())
            {
                Assert.True(rect.Contains(vertex));
            }

            Assert.False(rect.Contains(new Vector2d(-1, 0)));
            Assert.False(rect.Contains(rect.TopRight + 1));
            Assert.False(rect.Contains(rect.BotRight + 1));
            Assert.False(rect.Contains(rect.TopLeft - 1));
            Assert.False(rect.Contains(rect.BotLeft - 1));

            Assert.True(rect.Contains(rect.TopRight - 1));
            Assert.True(rect.Contains(rect.BotRight - 1));
            Assert.True(rect.Contains(rect.TopLeft + 1));
            Assert.True(rect.Contains(rect.BotLeft + 1));
        }
예제 #26
0
            void Collide(ref LinkedListNode <ContactPoint> node, Body b1, Body b2, bool inverse, ref BoundingRectangle targetArea)
            {
                Vector2D[] vertexes = b2.Shape.Vertexes;
                Vector2D[] normals  = b2.Shape.VertexNormals;


                Matrix2x3 b2ToWorld       = b2.Matrices.ToWorld;
                Matrix2x3 b1ToBody        = b1.Matrices.ToBody;
                Matrix2x2 b1ToWorldNormal = b1.Matrices.ToWorldNormal;

                Matrix2x2 normalM;

                Matrix2x2.Multiply(ref b1.Matrices.ToBodyNormal, ref b2.Matrices.ToWorldNormal, out normalM);

                IntersectionInfo info = IntersectionInfo.Zero;
                ContainmentType  contains;
                ContactPoint     contact;

                for (int index = 0; index < vertexes.Length; ++index)
                {
                    Vector2D worldVertex;
                    Vector2D.Transform(ref b2ToWorld, ref vertexes[index], out worldVertex);
                    targetArea.Contains(ref worldVertex, out contains);
                    bool isBad = (contains != ContainmentType.Contains);
                    if (!isBad)
                    {
                        Vector2D bodyVertex;
                        Vector2D.Transform(ref b1ToBody, ref worldVertex, out bodyVertex);
                        isBad = !b1.Shape.TryGetIntersection(bodyVertex, out info);
                        if (!isBad && normals != null &&
                            !body1.IgnoresCollisionResponse &&
                            !body2.IgnoresCollisionResponse)
                        {
                            Vector2D normal;
                            Vector2D.Transform(ref normalM, ref normals[index], out normal);
                            Scalar temp;
                            temp  = Vector2D.Dot(info.Normal, normal);
                            isBad = temp >= 0;
                        }
                    }

                    int Id = (inverse) ? (index) : ((-vertexes.Length + index));
                    while (node != null && node.Value.id < Id)
                    {
                        node = node.Next;
                    }

                    if (isBad)
                    {
                        if (node != null && node.Value.id == Id)
                        {
                            LinkedListNode <ContactPoint> nextNode = node.Next;
                            contacts.Remove(node);
                            node = nextNode;
                        }
                    }
                    else
                    {
                        if (node == null)
                        {
                            contact    = new ContactPoint();
                            contact.id = Id;
                            contacts.AddLast(contact);
                        }
                        else if (node.Value.id == Id)
                        {
                            contact = node.Value;
                            node    = node.Next;
                            if (!parent.warmStarting)
                            {
                                contact.Pn  = 0;
                                contact.Pt  = 0;
                                contact.Pnb = 0;
                            }
                        }
                        else
                        {
                            contact    = new ContactPoint();
                            contact.id = Id;
                            contacts.AddBefore(node, contact);
                        }
                        contact.normal   = Vector2D.Transform(b1ToWorldNormal, info.Normal);
                        contact.distance = info.Distance;
                        contact.position = worldVertex;
                        if (inverse)
                        {
                            Vector2D.Negate(ref contact.normal, out contact.normal);
                        }
                        Vector2D.Normalize(ref contact.normal, out contact.normal);
                    }
                }
            }
예제 #27
0
            void Collide(ref LinkedListNode<ContactPoint> node, Body b1, Body b2, bool inverse, ref BoundingRectangle targetArea)
            {
                Vector2D[] vertexes = b2.Shape.Vertexes;
                Vector2D[] normals = b2.Shape.VertexNormals;


                Matrix2x3 b2ToWorld = b2.Matrices.ToWorld;
                Matrix2x3 b1ToBody = b1.Matrices.ToBody;
                Matrix2x2 b1ToWorldNormal = b1.Matrices.ToWorldNormal;

                Matrix2x2 normalM;
                Matrix2x2.Multiply(ref b1.Matrices.ToBodyNormal, ref b2.Matrices.ToWorldNormal, out normalM);

                IntersectionInfo info = IntersectionInfo.Zero;
                ContainmentType contains;
                ContactPoint contact;

                for (int index = 0; index < vertexes.Length; ++index)
                {
                    Vector2D worldVertex;
                    Vector2D.Transform(ref b2ToWorld, ref vertexes[index], out worldVertex);
                    targetArea.Contains(ref worldVertex, out contains);
                    bool isBad = (contains != ContainmentType.Contains);
                    if (!isBad)
                    {
                        Vector2D bodyVertex;
                        Vector2D.Transform(ref b1ToBody, ref worldVertex, out bodyVertex);
                        isBad = !b1.Shape.TryGetIntersection(bodyVertex, out info);
                        if (!isBad && normals != null &&
                            !body1.IgnoresCollisionResponse &&
                            !body2.IgnoresCollisionResponse)
                        {
                            Vector2D normal;
                            Vector2D.Transform(ref normalM, ref  normals[index], out normal);
                            Scalar temp;
                            Vector2D.Dot(ref info.Normal, ref normal, out temp);
                            isBad = temp >= 0;
                        }
                    }

                    int Id = (inverse) ? (index) : ((-vertexes.Length + index));
                    while (node != null && node.Value.id < Id) { node = node.Next; }

                    if (isBad)
                    {
                        if (node != null && node.Value.id == Id)
                        {
                            LinkedListNode<ContactPoint> nextNode = node.Next;
                            contacts.Remove(node);
                            node = nextNode;
                        }
                    }
                    else
                    {
                        if (node == null)
                        {
                            contact = new ContactPoint();
                            contact.id = Id;
                            contacts.AddLast(contact);
                        }
                        else if (node.Value.id == Id)
                        {
                            contact = node.Value;
                            node = node.Next;
                            if (!parent.warmStarting)
                            {
                                contact.Pn = 0;
                                contact.Pt = 0;
                                contact.Pnb = 0;
                            }
                        }
                        else
                        {
                            contact = new ContactPoint();
                            contact.id = Id;
                            contacts.AddBefore(node, contact);
                        }
                        Vector2D.Transform(ref b1ToWorldNormal, ref info.Normal, out contact.normal);
                        contact.distance = info.Distance;
                        contact.position = worldVertex;
                        if (inverse)
                        {
                            Vector2D.Negate(ref contact.normal, out contact.normal);
                        }
                        Vector2D.Normalize(ref contact.normal, out contact.normal);
                    }
                }
            }
예제 #28
0
 /// <summary>
 /// Computes the intersection between the cursor location and this control. It is called
 /// each time an event is fired on every control in the <see cref="Odyssey.UserInterface.Controls.Overlay"/> to determine
 /// if the UI needs to react.
 /// </summary>
 /// <param name="cursorLocation">The location of the mouse cursor</param>
 /// <returns><b>True</b> if the cursor is inside the control's boundaries. <b>False</b>,
 /// otherwise.</returns>
 public virtual bool Contains(Vector2 cursorLocation)
 {
     return(BoundingRectangle.Contains(cursorLocation));
 }
예제 #29
0
        private void resizeCanResize(float x, float y)
        {
            // this is just an idea for now!

            // Drag
            var rect = windowBorder.GetBorder(Direction.Top);

            rect.X      += windowBorder.AbsoluteRenderTransform.X;
            rect.Y      += windowBorder.AbsoluteRenderTransform.Y + 8;
            rect.Width  -= windowBorder.BorderThickness.Right;
            rect.Height -= 8;
            if (rect.Contains(x, y) == ContainmentType.Contains)
            {
                mouseOffset = new Vector2(rect.X, rect.Y) - new Vector2(x, y);
                state       = DialogWindowState.Drag;
                return;
            }

            // Resize
            var resizeRectBottom = windowBorder.GetBorder(Direction.Bottom);

            resizeRectBottom.X += windowBorder.AbsoluteRenderTransform.X;
            resizeRectBottom.Y += windowBorder.AbsoluteRenderTransform.Y;
            if (resizeRectBottom.Contains(x, y) == ContainmentType.Contains)
            {
#if WINDOWS
                System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.SizeNS;
#endif
                mouseOffset = new Vector2(resizeRectBottom.X, resizeRectBottom.Y) - new Vector2(x, y);
                state       = DialogWindowState.ResizeY1;
                return;
            }

            var recttop = windowBorder.GetBorder(Direction.Top);
            recttop.X      += windowBorder.AbsoluteRenderTransform.X;
            recttop.Y      += windowBorder.AbsoluteRenderTransform.Y;
            recttop.Width  -= windowBorder.BorderThickness.Right;
            recttop.Height -= 24;
            if (recttop.Contains(x, y) == ContainmentType.Contains)
            {
#if WINDOWS
                System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.SizeNS;
#endif
                mouseOffset = new Vector2(recttop.X, recttop.Y) - new Vector2(x, y);
                state       = DialogWindowState.ResizeY2;
                return;
            }

            var resizeRectRight = windowBorder.GetBorder(Direction.Right);
            resizeRectRight.X      += windowBorder.AbsoluteRenderTransform.X;
            resizeRectRight.Y      += windowBorder.AbsoluteRenderTransform.Y;
            resizeRectRight.Height -= windowBorder.BorderThickness.Bottom;
            if (resizeRectRight.Contains(x, y) == ContainmentType.Contains)
            {
#if WINDOWS
                System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.SizeWE;
#endif
                mouseOffset = new Vector2(resizeRectRight.X, resizeRectRight.Y) - new Vector2(x, y);
                state       = DialogWindowState.ResizeX1;
                return;
            }

            var resizeRectLeft = windowBorder.GetBorder(Direction.Left);
            resizeRectLeft.X      += windowBorder.AbsoluteRenderTransform.X;
            resizeRectLeft.Y      += windowBorder.AbsoluteRenderTransform.Y + windowBorder.BorderThickness.Top;
            resizeRectLeft.Height -= windowBorder.BorderThickness.Bottom + windowBorder.BorderThickness.Top;
            if (resizeRectLeft.Contains(x, y) == ContainmentType.Contains)
            {
#if WINDOWS
                System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.SizeWE;
#endif
                mouseOffset = Vector2.Zero;
                state       = DialogWindowState.ResizeX2;
                return;
            }

            // resize corners
            var rectx1 = new BoundingRectangle()
            {
                X      = windowBorder.AbsoluteRenderTransform.X + windowBorder.RenderSize.X - windowBorder.BorderThickness.Right,
                Y      = windowBorder.AbsoluteRenderTransform.Y + windowBorder.RenderSize.Y - windowBorder.BorderThickness.Bottom,
                Width  = windowBorder.BorderThickness.Right,
                Height = windowBorder.BorderThickness.Bottom,
            };
            if (rectx1.Contains(x, y) == ContainmentType.Contains)
            {
#if WINDOWS
                System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.SizeNWSE;
#endif
                mouseOffset = Vector2.Zero;
                state       = DialogWindowState.Resize;
                return;
            }

            var rectx2 = new BoundingRectangle()
            {
                X      = windowBorder.AbsoluteRenderTransform.X,
                Y      = windowBorder.AbsoluteRenderTransform.Y + windowBorder.RenderSize.Y - windowBorder.BorderThickness.Bottom,
                Width  = windowBorder.BorderThickness.Left,
                Height = windowBorder.BorderThickness.Bottom,
            };
            if (rectx2.Contains(x, y) == ContainmentType.Contains)
            {
#if WINDOWS
                System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.SizeNESW;
#endif
                mouseOffset = Vector2.Zero;
                state       = DialogWindowState.Resize;
                return;
            }

            var rectx3 = new BoundingRectangle()
            {
                X      = windowBorder.AbsoluteRenderTransform.X,
                Y      = windowBorder.AbsoluteRenderTransform.Y,
                Width  = windowBorder.BorderThickness.Left,
                Height = windowBorder.BorderThickness.Top,
            };
            if (rectx3.Contains(x, y) == ContainmentType.Contains)
            {
#if WINDOWS
                System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.SizeNWSE;
#endif
                mouseOffset = Vector2.Zero;
                state       = DialogWindowState.Resize;
                return;
            }

            var rectx4 = new BoundingRectangle()
            {
                X      = windowBorder.AbsoluteRenderTransform.X + windowBorder.RenderSize.X - windowBorder.BorderThickness.Right,
                Y      = windowBorder.AbsoluteRenderTransform.Y,
                Width  = windowBorder.BorderThickness.Left,
                Height = windowBorder.BorderThickness.Top,
            };
            if (rectx4.Contains(x, y) == ContainmentType.Contains)
            {
#if WINDOWS
                System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.SizeNESW;
#endif
                mouseOffset = Vector2.Zero;
                state       = DialogWindowState.Resize;
                return;
            }
        }
예제 #30
0
파일: Demo.cs 프로젝트: bsvercl/physics2d
        static void FillRect(int[,] has, BoundingRectangle clip, BoundingRectangle other)
        {
            ContainmentType inter = clip.Contains(other);
            if (inter == ContainmentType.Contains)
            {
                has[Non, Non]++;
            }
            else
            {
                has[Non, Non]++;
                bool hasMin = false;
                bool hasMax = false;
                if (other.Min.X < clip.Min.X)
                {
                    hasMin = true;
                    has[Min, Non]++;
                }
                else if (other.Max.X > clip.Max.X)
                {
                    hasMax = true;
                    has[Max, Non]++;
                }

                if (other.Min.Y < clip.Min.Y)
                {
                    has[Non, Min]++;
                    if (hasMax)
                    {
                        has[Max, Min]++;
                    }
                    else if (hasMin)
                    {
                        has[Min, Min]++;
                    }
                }
                else if (other.Max.Y > clip.Max.Y)
                {
                    has[Non, Max]++;
                    if (hasMax)
                    {
                        has[Max, Max]++;
                    }
                    else if (hasMin)
                    {
                        has[Min, Max]++;
                    }
                }
            }
        }
예제 #31
0
 public void ContainsPoint(BoundingRectangle boundingRectangle, Point2 point, bool expectedToContainPoint)
 {
     Assert.AreEqual(expectedToContainPoint, boundingRectangle.Contains(point));
     Assert.AreEqual(expectedToContainPoint, BoundingRectangle.Contains(boundingRectangle, point));
 }
예제 #32
0
 protected sealed override bool BoundaryContains(BoundingRectangle boundary, BoundingRectangle other)
 {
     return(boundary.Contains(other));
 }
예제 #33
0
 public virtual bool Contains(IGuiContext context, Point point)
 {
     return(BoundingRectangle.Contains(point));
 }