예제 #1
0
        public void Draw(Texture2D texture, Vector2 position, DoubleRectangle? sourceRectangle, Color color, float rotation, Vector2 origin, Vector2 scale, SpriteEffects effects, float layerDepth)
        {
            DrawCommand cmd = GetRenderer().GetAvailableCommand();
            cmd.CommandType = DrawCommand.DrawCommandType.Texture;
            cmd.Texture = texture;
            cmd.Position = position;
            cmd.Color = color;

            // Vic says - make sure this stays in, or else previously-drawn Sprites can make later-drawn Sprites have the wrong effect
            cmd.ShaderEffect = null;

            cmd.Rotation = rotation;
            cmd.Origin = origin;
            if (sourceRectangle != null)
            {
                cmd.SourceRectangle = sourceRectangle.Value;
            }
            else
            {
                cmd.SourceRectangle = DoubleRectangle.Empty;
            }
            cmd.Scale = scale;
            cmd.Effects = effects;
            cmd.LayerDepth = layerDepth;
            cmd.CalculateDestinationRectangle(texture);
        }
예제 #2
0
 /// <summary>
 /// Used to construct a rectangle using the canvas coordinate system
 /// </summary>
 /// <param name="startX">Origin point of the click on the X axis</param>
 /// <param name="startY">Origin point of the click on the Y axis</param>
 /// <param name="drawWidth">The width of the object in the web layer (may be negative)</param>
 /// <param name="drawHeight">The height of the object in the web layer (may be negative)</param>
 public DoubleRectangle CreateDoubleRectangleFromWebCoordinates(int startX, int startY, int drawWidth, int drawHeight)
 {
     var x = drawWidth > 0 ? startX : startX + drawWidth;
     var y = drawHeight > 0 ? startY : startY + drawHeight;
     var width = Math.Abs(drawWidth);
     var height = Math.Abs(drawHeight);
     var doubleRectangle = new DoubleRectangle(x, y, width, height);
     return doubleRectangle;
 }
예제 #3
0
 void RenderText()
 {
     Vector2 size = Font.InternalMeasureString(_text);
     renderedText = new WriteableBitmap((int)size.X, (int)size.Y);
     pixelWidth = renderedText.PixelWidth;
     pixelHeight = renderedText.PixelHeight;
     SourceRectangle = new DoubleRectangle(0, 0, pixelWidth, pixelHeight);
     Font.Draw(this, _text);
     brush.ImageSource = renderedText;
 }
예제 #4
0
        /// <summary>
        /// True if small rectangle is entirely contained within the larger rectangle
        /// </summary>
        /// <param name="largerRectangle">The larger rectangle</param>
        /// <param name="smallerRectangle">The smaller rectangle</param>
        /// <returns>True if small rectangle is entirely contained within the larger rectangle, false otherwise</returns>
        private bool ContainedWithin(DoubleRectangle largerRectangle, DoubleRectangle smallerRectangle)
        {
            bool lowerLeftCheck = largerRectangle.LowerLeft.X <= smallerRectangle.LowerLeft.X && largerRectangle.LowerLeft.Y <= smallerRectangle.LowerLeft.Y;
            bool upperLeftCheck = largerRectangle.UpperLeft.X <= smallerRectangle.UpperLeft.X && largerRectangle.UpperLeft.Y >= smallerRectangle.UpperLeft.Y;

            bool lowerRightCheck = largerRectangle.LowerRight.X >= smallerRectangle.LowerRight.X && largerRectangle.LowerRight.Y <= smallerRectangle.LowerRight.Y;
            bool upperRightCheck = largerRectangle.UpperRight.X >= smallerRectangle.UpperRight.X && largerRectangle.UpperRight.Y >= smallerRectangle.UpperRight.Y;

            return lowerLeftCheck && upperLeftCheck && lowerRightCheck && upperRightCheck;
        }
예제 #5
0
        /// <summary>
        /// True if small rectangle is entirely contained within the larger rectangle
        /// </summary>
        /// <param name="largerRectangle">The larger rectangle</param>
        /// <param name="smallerRectangle">The smaller rectangle</param>
        /// <returns>True if small rectangle is entirely contained within the larger rectangle, false otherwise</returns>
        private bool ContainedWithin(DoubleRectangle largerRectangle, DoubleRectangle smallerRectangle)
        {
            bool lowerLeftCheck = largerRectangle.LowerLeft.X <= smallerRectangle.LowerLeft.X && largerRectangle.LowerLeft.Y <= smallerRectangle.LowerLeft.Y;
            bool upperLeftCheck = largerRectangle.UpperLeft.X <= smallerRectangle.UpperLeft.X && largerRectangle.UpperLeft.Y >= smallerRectangle.UpperLeft.Y;

            bool lowerRightCheck = largerRectangle.LowerRight.X >= smallerRectangle.LowerRight.X && largerRectangle.LowerRight.Y <= smallerRectangle.LowerRight.Y;
            bool upperRightCheck = largerRectangle.UpperRight.X >= smallerRectangle.UpperRight.X && largerRectangle.UpperRight.Y >= smallerRectangle.UpperRight.Y;

            return(lowerLeftCheck && upperLeftCheck && lowerRightCheck && upperRightCheck);
        }
예제 #6
0
        /// <summary>
        /// Used to construct a rectangle using the canvas coordinate system
        /// </summary>
        /// <param name="startX">Origin point of the click on the X axis</param>
        /// <param name="startY">Origin point of the click on the Y axis</param>
        /// <param name="drawWidth">The width of the object in the web layer (may be negative)</param>
        /// <param name="drawHeight">The height of the object in the web layer (may be negative)</param>
        public DoubleRectangle CreateDoubleRectangleFromWebCoordinates(int startX, int startY, int drawWidth, int drawHeight)
        {
            var x               = drawWidth > 0 ? startX : startX + drawWidth;
            var y               = drawHeight > 0 ? startY : startY + drawHeight;
            var width           = Math.Abs(drawWidth);
            var height          = Math.Abs(drawHeight);
            var doubleRectangle = new DoubleRectangle(x, y, width, height);

            return(doubleRectangle);
        }
		void GetDestinationRect(ref Rectangle rect, Vector2 position, ref DoubleRectangle sourceRectangle, Vector2 scale, Vector2 origin)
		{
			position -= origin * scale;
			Vector2 pos = Vector2.Transform(position, _transformMatrix);
			Vector2 pos2 = position;
			pos2.X += (float)(sourceRectangle.Width * scale.X);
			pos2.Y += (float)(sourceRectangle.Height * scale.Y);
			pos2 = Vector2.Transform(pos2, _transformMatrix);
			rect.X = (int)(pos.X + .5);
			rect.Y = (int)(pos.Y + .5);
			int right = (int)(pos2.X + .5);
			int bottom = (int)(pos2.Y + .5);
			rect.Width = right - rect.X;
			rect.Height = bottom - rect.Y;
		}
예제 #8
0
        /// <summary>
        /// Check that two double precision rectangles overlap with each other
        /// </summary>
        /// <param name="rect1">The first rectangle</param>
        /// <param name="rect2">The second rectangle</param>
        /// <returns>The rectangles overlap</returns>
        public bool DoesEitherRectangleOverlapTheOther(DoubleRectangle rect1, DoubleRectangle rect2)
        {
            if (IsEitherRectangleAdjacentToTheOther(rect1, rect2))
                return true;

            bool leftOfRect1InsideRect2Width = ValuesOverlap(rect1.X, rect2.X, rect2.X + rect2.Width);
            bool leftOfRect2InsideRect1Width = ValuesOverlap(rect2.X, rect1.X, rect1.X + rect1.Width);
            bool xOverlap = leftOfRect1InsideRect2Width || leftOfRect2InsideRect1Width;

            bool topOfRect1InsideRect2Height = ValuesOverlap(rect1.Y, rect2.Y, rect2.Y + rect2.Height);
            bool topOfRect2InsideRect1Height = ValuesOverlap(rect2.Y, rect1.Y, rect1.Y + rect1.Height);
            bool yOverlap = topOfRect1InsideRect2Height || topOfRect2InsideRect1Height;

            bool rectanglesIntersect = xOverlap && yOverlap && !DoesEitherRectangleContainTheOther(rect1, rect2);

            return rectanglesIntersect;
        }
예제 #9
0
        /// <summary>
        /// Check that two double precision rectangles overlap with each other
        /// </summary>
        /// <param name="rect1">The first rectangle</param>
        /// <param name="rect2">The second rectangle</param>
        /// <returns>The rectangles overlap</returns>
        public bool DoesEitherRectangleOverlapTheOther(DoubleRectangle rect1, DoubleRectangle rect2)
        {
            if (IsEitherRectangleAdjacentToTheOther(rect1, rect2))
            {
                return(true);
            }

            bool leftOfRect1InsideRect2Width = ValuesOverlap(rect1.X, rect2.X, rect2.X + rect2.Width);
            bool leftOfRect2InsideRect1Width = ValuesOverlap(rect2.X, rect1.X, rect1.X + rect1.Width);
            bool xOverlap = leftOfRect1InsideRect2Width || leftOfRect2InsideRect1Width;

            bool topOfRect1InsideRect2Height = ValuesOverlap(rect1.Y, rect2.Y, rect2.Y + rect2.Height);
            bool topOfRect2InsideRect1Height = ValuesOverlap(rect2.Y, rect1.Y, rect1.Y + rect1.Height);
            bool yOverlap = topOfRect1InsideRect2Height || topOfRect2InsideRect1Height;

            bool rectanglesIntersect = xOverlap && yOverlap && !DoesEitherRectangleContainTheOther(rect1, rect2);

            return(rectanglesIntersect);
        }
예제 #10
0
        public void DoesEitherRectangleContainTheOther_LeftSideRect1ExtendsPast_ReturnsFalse()
        {
            /*Picture of rectangle location
            0000
            1110
            1110
            0000
            */
            DoubleRectangle rectangle1 = new DoubleRectangle(0, 1, 2, 1);

            /*Picture of rectangle location
            0222
            0202
            0202
            0222
            */
            DoubleRectangle rectangle2 = new DoubleRectangle(1, 0, 3, 4);

            var isContained = RectangleMathHelper.DoesEitherRectangleContainTheOther(rectangle1, rectangle2);
            Assert.IsFalse(isContained);
        }
예제 #11
0
        /// <summary>
        /// True if either rectangle is adjacent to the other rectangle
        /// </summary>
        /// <param name="rect1">The first rectangle</param>
        /// <param name="rect2">The second rectangle</param>
        /// <returns>At least one rectangle is adjacent to the other rectangle</returns>
        public bool IsEitherRectangleAdjacentToTheOther(DoubleRectangle rect1, DoubleRectangle rect2)
        {
            bool overlapsWithRect2Left  = rect1.X.Equals(rect2.X) || rect1.RightSideX.Equals(rect2.X);
            bool overlapsWithRect2Right = rect1.X.Equals(rect2.RightSideX) || rect1.RightSideX.Equals(rect2.RightSideX);

            bool overlapsWithRect2Top    = rect1.Y.Equals(rect2.Y) || rect1.BotY.Equals(rect2.Y);
            bool overlapsWithRect2Bottom = rect1.Y.Equals(rect2.BotY) || rect1.BotY.Equals(rect2.BotY);

            if (overlapsWithRect2Left || overlapsWithRect2Right)
            {
                bool isWithinYAxis = ValuesOverlap(rect1.Y, rect2.Y, rect2.BotY) || ValuesOverlap(rect1.BotY, rect2.Y, rect2.BotY);
                return(isWithinYAxis);
            }

            if (overlapsWithRect2Bottom || overlapsWithRect2Top)
            {
                bool isWithinXAxis = ValuesOverlap(rect1.X, rect2.X, rect2.RightSideX) || ValuesOverlap(rect1.RightSideX, rect2.X, rect2.RightSideX);
                return(isWithinXAxis);
            }
            return(false);
        }
예제 #12
0
        /// <summary>
        /// True if either rectangle is adjacent to the other rectangle
        /// </summary>
        /// <param name="rect1">The first rectangle</param>
        /// <param name="rect2">The second rectangle</param>
        /// <returns>At least one rectangle is adjacent to the other rectangle</returns>
        public bool IsEitherRectangleAdjacentToTheOther(DoubleRectangle rect1, DoubleRectangle rect2)
        {
            bool overlapsWithRect2Left = rect1.X.Equals(rect2.X) || rect1.RightSideX.Equals(rect2.X);
            bool overlapsWithRect2Right = rect1.X.Equals(rect2.RightSideX) || rect1.RightSideX.Equals(rect2.RightSideX);

            bool overlapsWithRect2Top = rect1.Y.Equals(rect2.Y) || rect1.BotY.Equals(rect2.Y);
            bool overlapsWithRect2Bottom = rect1.Y.Equals(rect2.BotY) || rect1.BotY.Equals(rect2.BotY);

            if (overlapsWithRect2Left || overlapsWithRect2Right)
            {
                bool isWithinYAxis = ValuesOverlap(rect1.Y, rect2.Y, rect2.BotY) || ValuesOverlap(rect1.BotY, rect2.Y, rect2.BotY);
                return isWithinYAxis;
            }

            if(overlapsWithRect2Bottom || overlapsWithRect2Top)
            {
                bool isWithinXAxis = ValuesOverlap(rect1.X, rect2.X, rect2.RightSideX) || ValuesOverlap(rect1.RightSideX, rect2.X, rect2.RightSideX);
                return isWithinXAxis;
            }
            return false;
        }
예제 #13
0
        public void DoesEitherRectangleContainTheOther_BottomSideRect2ExtendsPast_ReturnsFalse()
        {
            /*Picture of rectangle location
            0000
            0110
            0110
            0110
            */
            DoubleRectangle rectangle1 = new DoubleRectangle(1, 1, 1, 2);

            /*Picture of rectangle location
            2222
            2002
            2222
            0000
            */
            DoubleRectangle rectangle2 = new DoubleRectangle(0, 0, 3, 2);

            var isContained = RectangleMathHelper.DoesEitherRectangleContainTheOther(rectangle2, rectangle1);
            Assert.IsFalse(isContained);
        }
예제 #14
0
 public void Draw(Texture2D texture, Vector2 position, DoubleRectangle? sourceRectangle, ShaderEffect shaderEffect, float rotation, Vector2 origin, Vector2 scale, SpriteEffects effects, float layerDepth)
 {
     DrawCommand cmd = GetRenderer().GetAvailableCommand();
     cmd.CommandType = DrawCommand.DrawCommandType.Texture;
     cmd.Texture = texture;
     cmd.Position = position;
     cmd.ShaderEffect = shaderEffect;
     cmd.Rotation = rotation;
     cmd.Origin = origin;
     if (sourceRectangle != null)
     {
         cmd.SourceRectangle = sourceRectangle.Value;
     }
     else
     {
         cmd.SourceRectangle = DoubleRectangle.FromRectangle(texture.SourceRect);
     }
     cmd.Scale = scale;
     cmd.Effects = effects;
     cmd.LayerDepth = layerDepth;
 }
예제 #15
0
        public void DoesEitherRectangleContainTheOther_BottomSideRect2ExtendsPast_ReturnsFalse()
        {
            /*Picture of rectangle location
             * 0000
             * 0110
             * 0110
             * 0110
             */
            DoubleRectangle rectangle1 = new DoubleRectangle(1, 1, 1, 2);

            /*Picture of rectangle location
             * 2222
             * 2002
             * 2222
             * 0000
             */
            DoubleRectangle rectangle2 = new DoubleRectangle(0, 0, 3, 2);

            var isContained = RectangleMathHelper.DoesEitherRectangleContainTheOther(rectangle2, rectangle1);

            Assert.IsFalse(isContained);
        }
예제 #16
0
        public void DoesEitherRectangleContainTheOther_NoOverlapAtAll_ReturnsFalse()
        {
            /*Picture of rectangle location
             * 1100
             * 1100
             * 0000
             * 0000
             */
            DoubleRectangle rectangle1 = new DoubleRectangle(0, 0, 1, 1);

            /*Picture of rectangle location
             * 0000
             * 0000
             * 0022
             * 0022
             */
            DoubleRectangle rectangle2 = new DoubleRectangle(2, 2, 1, 1);

            var isContained = RectangleMathHelper.DoesEitherRectangleContainTheOther(rectangle1, rectangle2);

            Assert.IsFalse(isContained);
        }
예제 #17
0
        public void IsEitherRectangleAdjacentToTheOther_NoSideAdjacent_ReturnsFalse()
        {
            /*Picture of rectangle location
             * 1100
             * 1100
             * 0000
             * 0000
             */
            DoubleRectangle rectangle1 = new DoubleRectangle(0, 0, 1, 1);

            /*Picture of rectangle location
             * 0000
             * 0000
             * 0022
             * 0022
             */
            DoubleRectangle rectangle2 = new DoubleRectangle(2, 2, 1, 1);

            var isAdjacent = RectangleMathHelper.IsEitherRectangleAdjacentToTheOther(rectangle1, rectangle2);

            Assert.IsFalse(isAdjacent);
        }
예제 #18
0
        public void IsEitherRectangleAdjacentToTheOther_BottomSideRect2Adjacent_ReturnsTrue()
        {
            /*Picture of rectangle location
             * 0000
             * 1100
             * 1100
             * 0000
             */
            DoubleRectangle rectangle1 = new DoubleRectangle(0, 1, 1, 1);

            /*Picture of rectangle location
             * 0220
             * 0220
             * 0220
             * 0000
             */
            DoubleRectangle rectangle2 = new DoubleRectangle(1, 0, 1, 2);

            var isAdjacent = RectangleMathHelper.IsEitherRectangleAdjacentToTheOther(rectangle2, rectangle1);

            Assert.IsTrue(isAdjacent);
        }
예제 #19
0
        public void IsEitherRectangleAdjacentToTheOther_RightSideRect1Adjacent_ReturnsTrue()
        {
            /*Picture of rectangle location
             * 0110
             * 0110
             * 0000
             * 0000
             */
            DoubleRectangle rectangle1 = new DoubleRectangle(1, 0, 1, 1);

            /*Picture of rectangle location
             * 0000
             * 2220
             * 2220
             * 0000
             */
            DoubleRectangle rectangle2 = new DoubleRectangle(0, 0, 2, 1);

            var isAdjacent = RectangleMathHelper.IsEitherRectangleAdjacentToTheOther(rectangle1, rectangle2);

            Assert.IsTrue(isAdjacent);
        }
예제 #20
0
        public void DoesEitherRectangleContainTheOther_LeftSideRect2ExtendsPast_ReturnsFalse()
        {
            /*Picture of rectangle location
             * 0000
             * 1110
             * 1110
             * 0000
             */
            DoubleRectangle rectangle1 = new DoubleRectangle(0, 1, 2, 1);

            /*Picture of rectangle location
             * 0222
             * 0202
             * 0202
             * 0222
             */
            DoubleRectangle rectangle2 = new DoubleRectangle(1, 0, 2, 3);

            var isContained = RectangleMathHelper.DoesEitherRectangleContainTheOther(rectangle2, rectangle1);

            Assert.IsFalse(isContained);
        }
예제 #21
0
        public void DoesEitherRectangleOverlapTheOther_OneContainsTheOther_ReturnsFalse()
        {
            /*Picture of rectangle location
             * 1111
             * 1001
             * 1001
             * 1111
             */
            DoubleRectangle rectangle1 = new DoubleRectangle(0, 0, 4, 4);

            /*Picture of rectangle location
             * 0000
             * 0220
             * 0220
             * 0000
             */
            DoubleRectangle rectangle2 = new DoubleRectangle(1, 1, 1, 1);

            var isOverlapping = RectangleMathHelper.DoesEitherRectangleOverlapTheOther(rectangle1, rectangle2);

            Assert.IsFalse(isOverlapping);
        }
예제 #22
0
        public void DoesEitherRectangleContainTheOther_RightSideRect1ExtendsPast_ReturnsFalse()
        {
            /*Picture of rectangle location
             * 0000
             * 0111
             * 0111
             * 0000
             */
            DoubleRectangle rectangle1 = new DoubleRectangle(1, 1, 2, 1);

            /*Picture of rectangle location
             * 2220
             * 2020
             * 2020
             * 2220
             */
            DoubleRectangle rectangle2 = new DoubleRectangle(0, 0, 2, 3);

            var isContained = RectangleMathHelper.DoesEitherRectangleContainTheOther(rectangle1, rectangle2);

            Assert.IsFalse(isContained);
        }
예제 #23
0
        public void DoesEitherRectangleContainTheOther_RectTwoContainsRectOne_ReturnsTrue()
        {
            /*Picture of rectangle location
             * 0000
             * 0110
             * 0110
             * 0000
             */
            DoubleRectangle rectangle1 = new DoubleRectangle(1, 1, 1, 1);

            /*Picture of rectangle location
             * 2222
             * 2002
             * 2002
             * 2222
             */
            DoubleRectangle rectangle2 = new DoubleRectangle(0, 0, 4, 4);

            var isContained = RectangleMathHelper.DoesEitherRectangleContainTheOther(rectangle1, rectangle2);

            Assert.IsTrue(isContained);
        }
예제 #24
0
        public void TestAll_ValidInput_ReturnsValidJson()
        {
            Rectangle rect1 = new Rectangle()
            {
                StartX = 1,
                StartY = 2,
                Width  = 3,
                Height = 4
            };
            Rectangle rect2 = new Rectangle()
            {
                StartX = 5,
                StartY = 6,
                Width  = 7,
                Height = 8
            };

            DoubleRectangle doubleRect1 = new DoubleRectangle(1, 2, 3, 4);
            DoubleRectangle doubleRect2 = new DoubleRectangle(5, 6, 7, 8);

            _doubleRectangleFactory.Expect(x => x.CreateDoubleRectangleFromWebCoordinates(1, 2, 3, 4)).Return(doubleRect1);
            _doubleRectangleFactory.Expect(x => x.CreateDoubleRectangleFromWebCoordinates(5, 6, 7, 8)).Return(doubleRect1);

            _rectangleMathHelper.Expect(x => x.DoesEitherRectangleContainTheOther(doubleRect1, doubleRect2)).Return(true).IgnoreArguments();
            _rectangleMathHelper.Expect(x => x.DoesEitherRectangleOverlapTheOther(doubleRect1, doubleRect2)).Return(true).IgnoreArguments();
            _rectangleMathHelper.Expect(x => x.IsEitherRectangleAdjacentToTheOther(doubleRect1, doubleRect2)).Return(true).IgnoreArguments();

            var actionReturn = _rectangleProcessorController.TestAll(rect1, rect2);

            Assert.IsInstanceOfType(actionReturn, typeof(JsonResult));

            JsonResult jsonReturn = (JsonResult)actionReturn;

            Assert.AreEqual("{ isOverlap = True, isContain = True, isAdjacent = True }", jsonReturn.Data.ToString());

            _rectangleMathHelper.VerifyAllExpectations();
            _doubleRectangleFactory.VerifyAllExpectations();
        }
예제 #25
0
        public void DoesEitherRectangleOverlapTheOther_BothXOverlapEachOther_BothYOverlapEachOther_ReturnsTrue()
        {
            //1111

            /*Picture of rectangle location
             * 1100
             * 1100
             * 0000
             * 0000
             */
            DoubleRectangle rectangle1 = new DoubleRectangle(0, 0, 1, 1);

            /*Picture of rectangle location
             * 2200
             * 2200
             * 0000
             * 0000
             */
            DoubleRectangle rectangle2 = new DoubleRectangle(0, 0, 1, 1);

            var isOverlapping = RectangleMathHelper.DoesEitherRectangleOverlapTheOther(rectangle1, rectangle2);

            Assert.IsTrue(isOverlapping);
        }
예제 #26
0
        public void DoesEitherRectangleOverlapTheOther_DoesNotOverlapAtAll_ReturnsFalse()
        {
            //0000

            /*Picture of rectangle location
             * 1100
             * 1100
             * 0000
             * 0000
             */
            DoubleRectangle rectangle1 = new DoubleRectangle(0, 0, 1, 1);

            /*Picture of rectangle location
             * 0022
             * 0022
             * 0000
             * 0000
             */
            DoubleRectangle rectangle2 = new DoubleRectangle(2, 2, 1, 1);

            var isOverlapping = RectangleMathHelper.DoesEitherRectangleOverlapTheOther(rectangle1, rectangle2);

            Assert.IsFalse(isOverlapping);
        }
예제 #27
0
        public void DoesEitherRectangleOverlapTheOther_LeftOfRect1WithinRect2XArea_BothYOverlapEachOther_ReturnsTrue()
        {
            //1011

            /*Picture of rectangle location
             * 0110
             * 0110
             * 0000
             * 0000
             */
            DoubleRectangle rectangle1 = new DoubleRectangle(1, 0, 1, 1);

            /*Picture of rectangle location
             * 2220
             * 2220
             * 0000
             * 0000
             */
            DoubleRectangle rectangle2 = new DoubleRectangle(0, 0, 2, 1);

            var isOverlapping = RectangleMathHelper.DoesEitherRectangleOverlapTheOther(rectangle1, rectangle2);

            Assert.IsTrue(isOverlapping);
        }
예제 #28
0
        public void DoesEitherRectangleOverlapTheOther_LeftOfRect2WithinRect1XArea_YDoesntOverlap_ReturnsFalse()
        {
            //0100

            /*Picture of rectangle location
             * 0000
             * 0000
             * 1110
             * 1110
             */
            DoubleRectangle rectangle1 = new DoubleRectangle(0, 2, 2, 1);

            /*Picture of rectangle location
             * 0220
             * 0220
             * 0000
             * 0000
             */
            DoubleRectangle rectangle2 = new DoubleRectangle(1, 0, 1, 1);

            var isOverlapping = RectangleMathHelper.DoesEitherRectangleOverlapTheOther(rectangle1, rectangle2);

            Assert.IsFalse(isOverlapping);
        }
예제 #29
0
        public void DoesEitherRectangleOverlapTheOther_XDoesntOverlap_TopOfRect2YWithinRect1YArea_ReturnsFalse()
        {
            //0010

            /*Picture of rectangle location
             * 0000
             * 1100
             * 1100
             * 1100
             */
            DoubleRectangle rectangle1 = new DoubleRectangle(0, 1, 1, 2);

            /*Picture of rectangle location
             * 0022
             * 0022
             * 0000
             * 0000
             */
            DoubleRectangle rectangle2 = new DoubleRectangle(2, 0, 1, 1);

            var isOverlapping = RectangleMathHelper.DoesEitherRectangleOverlapTheOther(rectangle1, rectangle2);

            Assert.IsFalse(isOverlapping);
        }
예제 #30
0
        public void DoesEitherRectangleOverlapTheOther_LeftOfRect2WithinRect1XArea_TopOfRect2YWithinRect1YArea_ReturnsTrue()
        {
            //0110

            /*Picture of rectangle location
             * 0000
             * 1110
             * 1010
             * 1110
             */
            DoubleRectangle rectangle1 = new DoubleRectangle(0, 1, 2, 2);

            /*Picture of rectangle location
             * 0222
             * 0202
             * 0222
             * 0000
             */
            DoubleRectangle rectangle2 = new DoubleRectangle(1, 0, 2, 2);

            var isOverlapping = RectangleMathHelper.DoesEitherRectangleOverlapTheOther(rectangle1, rectangle2);

            Assert.IsTrue(isOverlapping);
        }
예제 #31
0
        private static void DrawSprites(
            List <VertexPositionColorTexture[]> spriteVertices,
            List <RenderBreak> mSpriteRenderBreaks,
            List <Sprite> spritesToDraw, int startIndex, int numberToDraw, Camera camera)
        {
            //public static void DrawSprites<T>(IList<T> spritesToDraw, int startIndex, int numberToDraw, Camera camera) where T : Sprite
            //{

            DrawSpritesNew(spritesToDraw, startIndex, numberToDraw, camera);
            return;



            if (numberToDraw == 0)
            {
                return;
            }

            // Vic says: I don't think this is needed now that the Renderer is handling mixed drawing
            //mAutomaticallyUpdatedSprites.SortZInsertionAscending();
            SpriteBlendMode lastBlendMode = SpriteBlendMode.AlphaBlend;

            // Vic says: At the time of this writing Additive blend isn't working properly
            if (spritesToDraw[startIndex].BlendOperation == BlendOperation.Add)
            {
                lastBlendMode = SpriteBlendMode.Additive;
            }

            Matrix lookAtMatrix = camera.GetLookAtMatrix();

            GraphicsBatch.Begin(lastBlendMode,
                                SpriteSortMode.Immediate,
                                SaveStateMode.None,
                                lookAtMatrix
                                );

            int endIndex = startIndex + numberToDraw;

            for (int i = startIndex; i < endIndex; i++)
            {
                Sprite s = spritesToDraw[i];

                if (s.BlendOperation == BlendOperation.Add && lastBlendMode == SpriteBlendMode.AlphaBlend)
                {
                    lastBlendMode = SpriteBlendMode.Additive;

                    GraphicsBatch.End();

                    GraphicsBatch.Begin(lastBlendMode,
                                        SpriteSortMode.Immediate,
                                        SaveStateMode.None, lookAtMatrix);
                }
                if (s.BlendOperation == BlendOperation.Regular && lastBlendMode == SpriteBlendMode.Additive)
                {
                    lastBlendMode = SpriteBlendMode.AlphaBlend;

                    GraphicsBatch.End();

                    GraphicsBatch.Begin(lastBlendMode,
                                        SpriteSortMode.Immediate,
                                        SaveStateMode.None, lookAtMatrix);
                }

                // Cache this to speed up calls
                Color whiteColor = Color.White;

                if (camera.IsSpriteInView(s))
                {
                    //SpriteBatch.Draw(s.Texture, new Vector2(0, 0), Color.Black);


                    float x = s.X;
                    float y = s.Y;

                    if (s.Visible && s.Texture != null)
                    {
                        float leftPixel   = 0;
                        float rightPixel  = 32;
                        float topPixel    = 0;
                        float bottomPixel = 32;

                        float textureWidth  = 32;
                        float textureHeight = 32;



                        if (s.Texture != null)
                        {
                            leftPixel   = s.LeftTextureCoordinate * s.Texture.Width;
                            rightPixel  = s.RightTextureCoordinate * s.Texture.Width;
                            topPixel    = s.TopTextureCoordinate * s.Texture.Height;
                            bottomPixel = s.BottomTextureCoordinate * s.Texture.Height;

                            textureWidth  = (float)s.Texture.Width;
                            textureHeight = (float)s.Texture.Height;
                        }

                        DoubleRectangle textureRectangle = new DoubleRectangle(leftPixel, topPixel,
                                                                               rightPixel - leftPixel,
                                                                               bottomPixel - topPixel);

                        float xOffsetForTopLeftDrawing = -s.ScaleX;
                        float yOffsetForTopLeftDrawing = -s.ScaleY;

                        // positive rotation should be counterclockwise, but for some reason
                        // it's clockwise.  Invert for now.  Man, I don't like these hacks.
                        float rotationToUse = -s.RotationZ;


                        FlatRedBall.Math.MathFunctions.RotatePointAroundPoint(
                            0, 0,
                            ref xOffsetForTopLeftDrawing, ref yOffsetForTopLeftDrawing, rotationToUse);



                        Vector2 position = new Vector2(x + xOffsetForTopLeftDrawing,   // - s.ScaleX,
                                                       -y + yOffsetForTopLeftDrawing); // - s.ScaleY);

                        Vector2 origin = new Vector2(0, 0);

                        // this keeps gaps from happening
                        const float extraScale = .05f;

                        Vector2 scale =
                            new Vector2(
                                (extraScale + 2 * s.ScaleX) / (float)textureRectangle.Width,
                                (extraScale + 2 * s.ScaleY) / (float)textureRectangle.Height);

                        ShaderEffect effect = Renderer.GetShaderEffectForColorOperation(s.ColorOperation,
                                                                                        s.Red, s.Green, s.Blue, s.Alpha);

                        SpriteEffects flipValue = SpriteEffects.None;

                        if (s.FlipHorizontal)
                        {
                            flipValue |= SpriteEffects.FlipHorizontally;
                        }
                        if (s.FlipVertical)
                        {
                            flipValue |= SpriteEffects.FlipVertically;
                        }


                        if (effect == null)
                        {
                            whiteColor.A = (byte)(255 * s.Alpha);

                            GraphicsBatch.Draw(s.Texture,
                                               position,
                                               textureRectangle,
                                               whiteColor,
                                               rotationToUse,
                                               origin,
                                               scale, //scale
                                               flipValue, 0);
                        }
                        else
                        {
                            GraphicsBatch.Draw(s.Texture,
                                               position,
                                               textureRectangle,
                                               effect,
                                               rotationToUse,
                                               origin,
                                               scale, //scale
                                               flipValue, 0);
                        }
                    }
                }
            }

            GraphicsBatch.End();
        }
예제 #32
0
        public void IsEitherRectangleAdjacentToTheOther_NoSideAdjacent_ReturnsFalse()
        {
            /*Picture of rectangle location
            1100
            1100
            0000
            0000
            */
            DoubleRectangle rectangle1 = new DoubleRectangle(0, 0, 1, 1);

            /*Picture of rectangle location
            0000
            0000
            0022
            0022
            */
            DoubleRectangle rectangle2 = new DoubleRectangle(2, 2, 1, 1);

            var isAdjacent = RectangleMathHelper.IsEitherRectangleAdjacentToTheOther(rectangle1, rectangle2);
            Assert.IsFalse(isAdjacent);
        }
 public void Draw(Texture2D texture, Vector2 position, ref DoubleRectangle sourceRectangle, Color color, float rotation, Vector2 origin, Vector2 scale, SpriteEffects effects, float layerDepth)
 {
     Blit(texture.ImageSource, position, ref sourceRectangle, color, scale, origin, effects);
 }
		public void DrawString(SpriteFont spriteFont, string text, Vector2 position, Color color, float rotation, Vector2 origin, Vector2 scale, SpriteEffects effects, float layerDepth)
		{
			origin = origin * scale;
			if (color.A == 0 && blendMode == SpriteBlendMode.AlphaBlend) return;
			if (spriteFont is BitmapSpriteFont)
			{
				BitmapSpriteFont font = spriteFont as BitmapSpriteFont;
				Vector2 pos = Vector2.Zero;
				foreach (char c in text)
				{
					if (c == '\n')
					{
						pos.Y += font.LineSpacing;
						pos.X = 0;
						continue;
					}
					if (font.characterData.ContainsKey(c) == false) continue;
					GlyphData g = font.characterData[c];
					DoubleRectangle rect = new DoubleRectangle(g.Glyph.X, g.Glyph.Y, g.Glyph.Width, g.Glyph.Height);
					Blit(font.SourceData, position - origin + pos + new Vector2(g.Cropping.X * scale.X, g.Cropping.Y * scale.Y), ref rect, color, scale, Vector2.Zero, effects);
					pos.X += (g.Kerning.Y + g.Kerning.Z + font.Spacing) * scale.X;
				}
			}
			else
			{
				_text.Text = text;
				_text.FontFamily = spriteFont.FontFamily;
				_text.FontSize = spriteFont.FontSize;
				_text.Foreground = new SWM.SolidColorBrush(color.ToSilverlightColor());
				_textTranslate.X = position.X;
				_textTranslate.Y = position.Y;
				_bmp.Invalidate();
				_bmp.Render(_text, _textTranslate);
				_bmp.Invalidate();
			}
		}
예제 #35
0
        public void DoesEitherRectangleContainTheOther_RectTwoContainsRectOne_ReturnsTrue()
        {
            /*Picture of rectangle location
            0000
            0110
            0110
            0000
            */
            DoubleRectangle rectangle1 = new DoubleRectangle(1, 1, 1, 1);

            /*Picture of rectangle location
            2222
            2002
            2002
            2222
            */
            DoubleRectangle rectangle2 = new DoubleRectangle(0, 0, 4, 4);

            var isContained = RectangleMathHelper.DoesEitherRectangleContainTheOther(rectangle1, rectangle2);
            Assert.IsTrue(isContained);
        }
예제 #36
0
 public void Draw(Texture2D texture, Vector2 position, DoubleRectangle? sourceRectangle, ShaderEffect shaderEffect, float rotation, Vector2 origin, Vector2 scale, SpriteEffects effects, float layerDepth)
 {
     if (sourceRectangle == null || sourceRectangle.Value.IsEmpty)
     {
         SpriteImage d = GetSprite(texture);
         if (d.ZIndex < zIndex)
         {
             d.ZIndex = zIndex;
         }
         else
         {
             zIndex = d.ZIndex;
         }
         zIndex++;
         d.InUse = true;
         d.PositionX = position.X;
         d.PositionY = position.Y;
         d.Scale = new Vector2((float)scale.X, (float)scale.Y);
         d.Rotation = rotation;
         d.Origin = origin;
         d.Effects = effects;
         d.CustomEffect = shaderEffect;
     }
     else
     {
         ClippedSpriteImage d = GetClippedSprite(texture);
         if (d.ZIndex < zIndex)
         {
             d.ZIndex = zIndex;
         }
         else
         {
             zIndex = d.ZIndex;
         }
         zIndex++;
         d.InUse = true;
         d.SourceRectangle = sourceRectangle.Value;
         d.PositionX = position.X;
         d.PositionY = position.Y;
         d.Scale = new Vector2((float)scale.X, (float)scale.Y);
         d.Rotation = rotation;
         d.Origin = origin;
         d.Effects = effects;
         d.CustomEffect = shaderEffect;
     }
 }
예제 #37
0
        public void CreateDoubleRectangleFromWebCoordinates_WidthIsPositive_LeaveAsPositive()
        {
            DoubleRectangle rect = DoubleRectangleFactory.CreateDoubleRectangleFromWebCoordinates(4, 3, 2, 1);

            Assert.AreEqual(2, rect.Width);
        }
예제 #38
0
        public void DoesEitherRectangleOverlapTheOther_BothXOverlapEachOther_TopOfRect1YWithinRect2YArea_ReturnsTrue()
        {
            //1110
            /*Picture of rectangle location
            0000
            1100
            1100
            0000
            */
            DoubleRectangle rectangle1 = new DoubleRectangle(0, 1, 1, 1);

            /*Picture of rectangle location
            2200
            2200
            0000
            0000
            */
            DoubleRectangle rectangle2 = new DoubleRectangle(0, 0, 1, 1);

            var isOverlapping = RectangleMathHelper.DoesEitherRectangleOverlapTheOther(rectangle1, rectangle2);
            Assert.IsTrue(isOverlapping);
        }
예제 #39
0
        public void CreateDoubleRectangleFromWebCoordinates_HeightIsPositive_YIsStartY()
        {
            DoubleRectangle rect = DoubleRectangleFactory.CreateDoubleRectangleFromWebCoordinates(1, 2, 3, 4);

            Assert.AreEqual(2, rect.Y);
        }
예제 #40
0
        public void CreateDoubleRectangleFromWebCoordinates_HeightIsNegative_YIsStartYMinusHeight()
        {
            DoubleRectangle rect = DoubleRectangleFactory.CreateDoubleRectangleFromWebCoordinates(4, 3, 2, -1);

            Assert.AreEqual(2, rect.Y);
        }
예제 #41
0
        public void CreateDoubleRectangleFromWebCoordinates_WidthIsNegative_XIsStartXMinusWidth()
        {
            DoubleRectangle rect = DoubleRectangleFactory.CreateDoubleRectangleFromWebCoordinates(4, 3, -2, 1);

            Assert.AreEqual(2, rect.X);
        }
예제 #42
0
        public void CreateDoubleRectangleFromWebCoordinates_WidthIsPositive_XIsStartX()
        {
            DoubleRectangle rect = DoubleRectangleFactory.CreateDoubleRectangleFromWebCoordinates(1, 2, 3, 4);

            Assert.AreEqual(1, rect.X);
        }
예제 #43
0
        public void IsEitherRectangleAdjacentToTheOther_TopSideRect2Adjacent_ReturnsTrue()
        {
            /*Picture of rectangle location
            1100
            1100
            0000
            0000
            */
            DoubleRectangle rectangle1 = new DoubleRectangle(0, 0, 1, 1);

            /*Picture of rectangle location
            0220
            0220
            0220
            0000
            */
            DoubleRectangle rectangle2 = new DoubleRectangle(1, 0, 1, 2);

            var isAdjacent = RectangleMathHelper.IsEitherRectangleAdjacentToTheOther(rectangle2, rectangle1);
            Assert.IsTrue(isAdjacent);
        }
예제 #44
0
 /// <summary>
 /// True if either rectangle is entirely contained within the other rectangle
 /// </summary>
 /// <param name="rect1">The first rectangle</param>
 /// <param name="rect2">The second rectangle</param>
 /// <returns>At least one rectangle is contained within the other</returns>
 public bool DoesEitherRectangleContainTheOther(DoubleRectangle rect1, DoubleRectangle rect2)
 {
     return(ContainedWithin(rect1, rect2) || ContainedWithin(rect2, rect1));
 }
예제 #45
0
        public void CreateDoubleRectangleFromWebCoordinates_WidthIsNegative_ConvertToPositive()
        {
            DoubleRectangle rect = DoubleRectangleFactory.CreateDoubleRectangleFromWebCoordinates(4, 3, -2, 1);

            Assert.AreEqual(2, rect.Width);
        }
예제 #46
0
        public void DoesEitherRectangleOverlapTheOther_LeftOfRect1WithinRect2XArea_TopOfRect2YWithinRect1YArea_ReturnsTrue()
        {
            //1001
            /*Picture of rectangle location
            0110
            0110
            0000
            0000
            */
            DoubleRectangle rectangle1 = new DoubleRectangle(1, 0, 1, 1);

            /*Picture of rectangle location
            0000
            2220
            2220
            0000
            */
            DoubleRectangle rectangle2 = new DoubleRectangle(0, 1, 2, 1);

            var isOverlapping = RectangleMathHelper.DoesEitherRectangleOverlapTheOther(rectangle1, rectangle2);
            Assert.IsTrue(isOverlapping);
        }
예제 #47
0
        public void CreateDoubleRectangleFromWebCoordinates_HeightIsPositive_LeaveAsPositive()
        {
            DoubleRectangle rect = DoubleRectangleFactory.CreateDoubleRectangleFromWebCoordinates(4, 3, 2, 1);

            Assert.AreEqual(1, rect.Height);
        }
예제 #48
0
 /// <summary>
 /// True if either rectangle is entirely contained within the other rectangle
 /// </summary>
 /// <param name="rect1">The first rectangle</param>
 /// <param name="rect2">The second rectangle</param>
 /// <returns>At least one rectangle is contained within the other</returns>
 public bool DoesEitherRectangleContainTheOther(DoubleRectangle rect1, DoubleRectangle rect2)
 {
     return ContainedWithin(rect1, rect2) || ContainedWithin(rect2, rect1);
 }
예제 #49
0
        public void CreateDoubleRectangleFromWebCoordinates_HeightIsNegative_ConvertToPositive()
        {
            DoubleRectangle rect = DoubleRectangleFactory.CreateDoubleRectangleFromWebCoordinates(4, 3, 2, -1);

            Assert.AreEqual(1, rect.Height);
        }
예제 #50
0
        public void DoesEitherRectangleContainTheOther_NoOverlapAtAll_ReturnsFalse()
        {
            /*Picture of rectangle location
            1100
            1100
            0000
            0000
            */
            DoubleRectangle rectangle1 = new DoubleRectangle(0, 0, 1, 1);

            /*Picture of rectangle location
            0000
            0000
            0022
            0022
            */
            DoubleRectangle rectangle2 = new DoubleRectangle(2, 2, 1, 1);

            var isContained = RectangleMathHelper.DoesEitherRectangleContainTheOther(rectangle1, rectangle2);
            Assert.IsFalse(isContained);
        }
예제 #51
0
 protected virtual void Draw(Texture2D texture, Vector2 position, ref DoubleRectangle sourceRectangle, ShaderEffect shaderEffect, float rotation, Vector2 origin, Vector2 scale, SpriteEffects effects, float layerDepth)
 {
 }
        void Blit(WriteableBitmap source, Vector2 position, ref DoubleRectangle sourceRectangle, Color color, Vector2 scale, Vector2 origin, SpriteEffects effects)
        {
			int sourceWidth = source.PixelWidth;
			int sourceHeight = source.PixelHeight;
			int[] sourcePixels = source.Pixels;
			int[] destPixels = _bmp.Pixels;
			int sourceLength = sourcePixels.Length;
			int destLength = destPixels.Length;
			if (color.A == 0) return;
			Root.Rectangle DestinationRect = new Root.Rectangle();
			GetDestinationRect(ref DestinationRect, position, ref sourceRectangle, scale, origin);
			scale.X = (float)(DestinationRect.Width / sourceRectangle.Width);
			scale.Y = (float)(DestinationRect.Height / sourceRectangle.Height);
			foreach (DirtyQuad q in _quads.GetDirtyQuads(DestinationRect))
			{
				int sourceIdx = -1;
				int px = Math.Max(q.BoundingRect.X, DestinationRect.X);
				int py = Math.Max(q.BoundingRect.Y, DestinationRect.Y);
				int right = Math.Min(q.BoundingRect.Right, DestinationRect.Right);
				int bottom = Math.Min(q.BoundingRect.Bottom, DestinationRect.Bottom);
				int dw = right - px;
				int dh = bottom - py;
				int x;
				int y;
				int idx;
				float ii;
				float jj;
				int sr = 0;
				int sg = 0;
				int sb = 0;
				int dr, dg, db;
				int sourcePixel;
				int sa = 0;
				int da;
				int ca = color.A;
				int cr = color.R;
				int cg = color.G;
				int cb = color.B;
				bool tinted = color.PackedValue != 0xffffffff;
				bool hflip = (effects & SpriteEffects.FlipHorizontally) == SpriteEffects.FlipHorizontally;
				bool vflip = (effects & SpriteEffects.FlipVertically) == SpriteEffects.FlipVertically;
				float sdx = 1 / scale.X;
				float sdy = 1 / scale.Y;
				float sourceStartX = (float)sourceRectangle.Left + ((px - DestinationRect.X) * sdx) + sdx/2;
				float sourceStartY = (float)sourceRectangle.Top + ((py - DestinationRect.Y) * sdy) + sdy/2;
				int lastii, lastjj;
				lastii = -1;
				lastjj = -1;
				if (hflip)
				{
					sourceStartX = (float)sourceRectangle.Right - ((px - DestinationRect.X) / scale.X) - sdx/2;
					sdx = -sdx;
				}
				if (vflip)
				{
					sourceStartY = (float)sourceRectangle.Bottom - ((py - DestinationRect.Y) / scale.Y) - sdy/2;
					sdy = -sdy;
				}
				jj = sourceStartY;
				y = py;
				for (int j = 0; j < dh; j++)
				{
					ii = sourceStartX;
					idx = px + y * _width;
					x = px;
					sourcePixel = sourcePixels[0];

					for (int i = 0; i < dw; i++)
					{
						int ir = (int)(ii);
						int jr = (int)(jj);
						if (ir < sourceWidth && jr < sourceHeight)
						{
							if (ir != lastii || jr != lastjj)
							{
								lastii = ir;
								lastjj = jr;
								sourceIdx = ir + jr * sourceWidth;
								if (sourceIdx >= 0 && sourceIdx < sourceLength)
								{
									sourcePixel = sourcePixels[sourceIdx];
									sa = ((sourcePixel >> 24) & 0xff);
									sr = ((sourcePixel >> 16) & 0xff);
									sg = ((sourcePixel >> 8) & 0xff);
									sb = ((sourcePixel) & 0xff);
									if (tinted && sa != 0)
									{
										sa = (((sa * ca) * 0x8081) >> 23);
										sr = ((((((sr * cr) * 0x8081) >> 23) * ca) * 0x8081) >> 23);
										sg = ((((((sg * cg) * 0x8081) >> 23) * ca) * 0x8081) >> 23);
										sb = ((((((sb * cb) * 0x8081) >> 23) * ca) * 0x8081) >> 23);
										sourcePixel = (sa << 24) | (sr << 16) | (sg << 8) | sb;
									}
								}
								else
								{
									sa = 0;
								}
							}
							if (blendMode == SpriteBlendMode.None)
							{
								destPixels[idx] = sourcePixel;
							}
							else if (sa > 0)
							{
								int destPixel = destPixels[idx];
								da = ((destPixel >> 24) & 0xff);
								if ((sa == 255 || da == 0) && blendMode != SpriteBlendMode.Additive)
								{
									destPixels[idx] = sourcePixel;
								}
								else
								{
									dr = ((destPixel >> 16) & 0xff);
									dg = ((destPixel >> 8) & 0xff);
									db = ((destPixel) & 0xff);
									if (blendMode == SpriteBlendMode.AlphaBlend)
									{
#if false
								destPixel = ((sa + blend(da, (255 - sa))) << 24) |
									((sr + blend(dr, 255-sa)) << 16) |
									((sg + blend(dg, 255-sa)) << 8) |
									((sb + blend(db, 255-sa)));
#endif
										destPixel = ((sa + (((da * (255 - sa)) * 0x8081) >> 23)) << 24) |
											((sr + (((dr * (255 - sa)) * 0x8081) >> 23)) << 16) |
											((sg + (((dg * (255 - sa)) * 0x8081) >> 23)) << 8) |
											((sb + (((db * (255 - sa)) * 0x8081) >> 23)));
									}
									else if (blendMode == SpriteBlendMode.Additive)
									{
										int a = 255 <= sa + da ? 255 : sa + da;
										destPixel = (a << 24) |
											 ((a <= sr + dr ? a : sr + dr) << 16) |
											 ((a <= sg + dg ? a : sg + dg) << 8) |
											 ((a <= sb + db ? a : sb + db));

									}
									destPixels[idx] = destPixel;
								}
							}
						}
						x++;
						idx++;
						ii += sdx;
					}
					jj += sdy;
					y++;
				}
			}
        }
예제 #53
0
        public void DoesEitherRectangleOverlapTheOther_OneContainsTheOther_ReturnsFalse()
        {
            /*Picture of rectangle location
            1111
            1001
            1001
            1111
            */
            DoubleRectangle rectangle1 = new DoubleRectangle(0, 0, 4, 4);

            /*Picture of rectangle location
            0000
            0220
            0220
            0000
            */
            DoubleRectangle rectangle2 = new DoubleRectangle(1, 1, 1, 1);

            var isOverlapping = RectangleMathHelper.DoesEitherRectangleOverlapTheOther(rectangle1, rectangle2);
            Assert.IsFalse(isOverlapping);
        }
        public void Draw(Texture2D texture, Vector2 position, ref DoubleRectangle sourceRectangle, System.Windows.Media.Effects.ShaderEffect shaderEffect, float rotation, Vector2 origin, Vector2 scale, SpriteEffects effects, float layerDepth)
        {
			Blit(texture.ImageSource, position, ref sourceRectangle, Color.White, scale, origin, effects);
        }
예제 #55
0
        public void DoesEitherRectangleOverlapTheOther_LeftOfRect2WithinRect1XArea_YDoesntOverlap_ReturnsFalse()
        {
            //0100
            /*Picture of rectangle location
            0000
            0000
            1110
            1110
            */
            DoubleRectangle rectangle1 = new DoubleRectangle(0, 2, 2, 1);

            /*Picture of rectangle location
            0220
            0220
            0000
            0000
            */
            DoubleRectangle rectangle2 = new DoubleRectangle(1, 0, 1, 1);

            var isOverlapping = RectangleMathHelper.DoesEitherRectangleOverlapTheOther(rectangle1, rectangle2);
            Assert.IsFalse(isOverlapping);
        }
예제 #56
0
 public void Draw(Texture2D texture, Vector2 position, DoubleRectangle? sourceRectangle, G.Color color, float rotation, Vector2 origin, Vector2 scale, SpriteEffects effects, float layerDepth)
 {
     if (sourceRectangle == null || sourceRectangle.Value.IsEmpty)
     {
         SpriteImage d = GetSprite(texture);
         if (d.ZIndex < zIndex)
         {
             d.ZIndex = zIndex;
         }
         else
         {
             zIndex = d.ZIndex;
         }
         zIndex++;
         d.InUse = true;
         if (color != d.color) d.Color = color;
         d.PositionX = position.X;
         d.PositionY = position.Y;
         d.Scale = new Vector2((float)scale.X, (float)scale.Y);
         d.Rotation = rotation;
         d.SetOriginAndEffects(origin, effects);
         d.CustomEffect = null; // this needs to get reset in case it's left-over from another call
     }
     else
     {
         ClippedSpriteImage d = GetClippedSprite(texture);
         if (d.ZIndex < zIndex)
         {
             d.ZIndex = zIndex;
         }
         else
         {
             zIndex = d.ZIndex;
         }
         zIndex++;
         d.InUse = true;
         if (color != d.color) d.Color = color;
         d.SourceRectangle = sourceRectangle.Value;
         d.PositionX = position.X;
         d.PositionY = position.Y;
         d.Scale = new Vector2((float)scale.X, (float)scale.Y);
         d.Rotation = rotation;
         d.SetOriginAndEffects(origin, effects);
         d.CustomEffect = null; // this needs to get reset in case it's left-over from another call
     }
 }
예제 #57
0
        public void DoesEitherRectangleOverlapTheOther_LeftOfRect2WithinRect1XArea_BothYOverlapEachOther_ReturnsTrue()
        {
            //0111
            /*Picture of rectangle location
            1100
            1100
            0000
            0000
            */
            DoubleRectangle rectangle1 = new DoubleRectangle(0, 0, 1, 1);

            /*Picture of rectangle location
            0220
            0220
            0000
            0000
            */
            DoubleRectangle rectangle2 = new DoubleRectangle(1, 0, 1, 1);

            var isOverlapping = RectangleMathHelper.DoesEitherRectangleOverlapTheOther(rectangle1, rectangle2);
            Assert.IsTrue(isOverlapping);
        }
예제 #58
0
        public void DoesEitherRectangleOverlapTheOther_XDoesntOverlap_TopOfRect2YWithinRect1YArea_ReturnsFalse()
        {
            //0010
            /*Picture of rectangle location
            0000
            1100
            1100
            1100
            */
            DoubleRectangle rectangle1 = new DoubleRectangle(0, 1, 1, 2);

            /*Picture of rectangle location
            0022
            0022
            0000
            0000
            */
            DoubleRectangle rectangle2 = new DoubleRectangle(2, 0, 1, 1);

            var isOverlapping = RectangleMathHelper.DoesEitherRectangleOverlapTheOther(rectangle1, rectangle2);
            Assert.IsFalse(isOverlapping);
        }
예제 #59
0
        public void DoesEitherRectangleOverlapTheOther_XDoesntOverlap_BothYOverlapEachOther_ReturnsFalse()
        {
            //0011
            /*Picture of rectangle location
            1100
            1100
            0000
            0000
            */
            DoubleRectangle rectangle1 = new DoubleRectangle(0, 0, 1, 1);

            /*Picture of rectangle location
            0022
            0022
            0000
            0000
            */
            DoubleRectangle rectangle2 = new DoubleRectangle(2, 0, 1, 1);

            var isOverlapping = RectangleMathHelper.DoesEitherRectangleOverlapTheOther(rectangle1, rectangle2);
            Assert.IsFalse(isOverlapping);
        }