예제 #1
0
        /// <summary>
        /// Perform a trace at 90 degree angles from the provided point to see if the ray touches
        /// one of the vertices of this rectangle
        /// <para>If it touches all 4 of the vertices the point is inside the rectangle</para>
        /// </summary>
        /// <param name="point">The origin point for the ray</param>
        /// <returns>true if the ray intercepts a vertice</returns>
        private bool RayTrace(Point2D <T> point)
        {
            // Get the maximum length between any vertices
            T d1        = Points[0].DistanceTo(Points[1]);
            T d2        = Points[0].DistanceTo(Points[2]);
            T d3        = Points[0].DistanceTo(Points[3]);
            T d4        = Points[1].DistanceTo(Points[2]);
            T d5        = Points[1].DistanceTo(Points[3]);
            T d6        = Points[2].DistanceTo(Points[3]);
            T rayLength = Math.Max(Math.Max(Math.Max((dynamic)d1, (dynamic)d2), Math.Max((dynamic)d3, (dynamic)d4)), Math.Max((dynamic)d5, (dynamic)d6));

            int cnt = 0;

            for (int i = 0; i < 360; i += 90)
            {
                Point2D <T> p2   = point.LocatePointAtDistance(i, rayLength);
                Line2D <T>  line = new Line2D <T>(point, p2);
                foreach (Line2D <T> vector in Vertices)
                {
                    if (line.Intersects(vector))
                    {
                        ++cnt;
                        break;
                    }
                }
            }
            return(cnt > 0 && cnt % 4 == 0);
        }
예제 #2
0
 /// <summary>
 /// Determine if a line intersects this rectangle
 /// <para>This does not include lines contained wholly
 /// within the rectangle</para>
 /// </summary>
 /// <param name="line">The line to check</param>
 /// <returns>True if the line intersects a vertice of this rectangle</returns>
 public bool Intersects(Line2D <T> line)
 {
     foreach (Line2D <T> vertice in Vertices)
     {
         if (line.Intersects(vertice))
         {
             return(true);
         }
     }
     return(false);
 }
예제 #3
0
 public void IntersectingTest(Line2D <Int32> lhs, Line2D <Int32> rhs, bool result)
 {
     Assert.AreEqual(result, lhs.Intersects(rhs));
 }