google-code-export / monoxna

Automatically exported from code.google.com/p/monoxna
Other
1 stars 1 forks source link

Rectangle.Intersects() does not exitsts #38

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
I will try and do this method. When it's ready, I'll commit it here.

Original issue reported on code.google.com by gse...@gmail.com on 17 Sep 2009 at 10:05

GoogleCodeExporter commented 9 years ago
Here is my code. It should be correct (the game is running ok)

/// <summary>
        /// It cheks if two rectangle intersects. (gsedej)
        /// </summary>
        /// <param name="rect">
        /// A <see cref="Rectangle"/>
        /// </param>
        /// <returns>
        /// A <see cref="System.Boolean"/>
        /// </returns>
        public bool Intersects(Rectangle rect)
        {
            // I need to compare both X and both Y values
            // Firt, check the X aixs, if first X coordinate is grater or 
lesser than other
            //  then check, if the other X in on the first line
            //      do the same for the Y
            if(this.X <= rect.X)//example 1
            {
                if((this.X + this.Width) > rect.X)// I think it is 
more, not "more or equal"
                {
                    if(this.Y < rect.Y) //example 1.1
                    {
                        if((this.Y + this.Height) > rect.Y)
                            return true;
                    }
                    else // example 1.2
                    {
                        if((rect.Y + rect.Height) > this.Y)
                            return true;
                    }
                }
            }
            else //example 2
            {
                if((rect.X + rect.Width) > this.X)
                {
                    if(this.Y < rect.Y) //example 2.1
                    {
                        if((this.Y + this.Height) > rect.Y)
                            return true;
                    }
                    else // example 2.2
                    {
                        if((rect.Y + rect.Height) > this.Y)
                            return true;
                    }
                }
            }
        }

Original comment by gse...@gmail.com on 17 Sep 2009 at 6:43

Attachments:

GoogleCodeExporter commented 9 years ago
I forget to past "return false;" at the end of function

Original comment by gse...@gmail.com on 17 Sep 2009 at 6:46

GoogleCodeExporter commented 9 years ago
You should write a NUnit test for it as well (even though there still are some 
issues
with the test project). The code looks good though ;)

For future reference: create a source patch using: svn diff > patch_name.diff

Original comment by lav...@gmail.com on 18 Sep 2009 at 12:54

GoogleCodeExporter commented 9 years ago
This issue will be closed when the tests have been implemented. 

Original comment by lav...@gmail.com on 1 Dec 2009 at 1:30

GoogleCodeExporter commented 9 years ago
Here is changes.diff for Test Project

Original comment by gse...@gmail.com on 1 Dec 2009 at 10:03

Attachments:

GoogleCodeExporter commented 9 years ago
accepted :) 

Original comment by lav...@gmail.com on 2 Dec 2009 at 8:35