Beispiel #1
0
 // Returns true if the specified line is inside this rectangle.
 public bool Contains(Line2F line)
 {
     if (IsEmpty || line.IsEmpty)
     {
         return(false);
     }
     return((line.Min < Max) &&
            (line.Max >= Min));
 }
Beispiel #2
0
        // Returns the closest point on the specified line.
        public Vector2F ClosestPointOnLine(Line2F l)
        {
            if (l.IsEmpty)
            {
                return(l.End1);
            }

            float dot2 = l.Size.Dot(l.Size);
            float dotp = l.Size.Dot(this - l.End1);
            float t    = GMath.Clamp(dotp / dot2, 0.0f, 1.0f);

            return(l.End1 + l.Size * t);
        }
Beispiel #3
0
 /** <summary> Returns true if the specified line is colliding with this line. </summary> */
 public bool Colliding(Line2F line)
 {
     if (IsEmpty || line.IsEmpty)
     {
         return(false);
     }
     if (!Bounds.Colliding(line.Bounds) && !IsStraight && !line.IsStraight)
     {
         return(false);
     }
     if (PointOfIntersection(line) != null)
     {
         return(true);
     }
     return(IsLineCollinear(line));
 }
Beispiel #4
0
 /** <summary> Returns true if the line is collinear with the specified line. </summary> */
 public bool IsLineCollinear(Line2F l)
 {
     if (IsParallel(l))
     {
         if (IsEmpty || l.IsEmpty)
         {
             return(false);
         }
         if (End1 != l.End1)
         {
             return(IsParallel(new Line2F(End1, l.End1)));
         }
         else
         {
             return(IsParallel(new Line2F(End2, l.End1)));
         }
     }
     return(false);
 }
Beispiel #5
0
        /** <summary> Gets the point of intersection between the two lines. </summary> */
        public Vector2F?PointOfIntersection(Line2F l)
        {
            Vector2F?point = PointOfIntersectionEndless(l);

            float epsilon = 0.0f;

            if (point != null)
            {
                Vector2F epsilonVector = new Vector2F(epsilon, epsilon);
                if (point.Value + epsilonVector < Min || point.Value + epsilonVector < l.Min)
                {
                    return(null);
                }
                if (point.Value - epsilonVector > Max || point.Value - epsilonVector > l.Max)
                {
                    return(null);
                }
            }
            return(point);
        }
Beispiel #6
0
 // Returns true if the specified line is colliding with this rectangle.
 public bool Colliding(Line2F line)
 {
     if (IsEmpty || line.IsEmpty)
     {
         return(false);
     }
     if (!Colliding(line.Bounds))
     {
         return(false);
     }
     if (Contains(line.End1))
     {
         return(true);
     }
     foreach (Line2F l in Lines)
     {
         if (l.Colliding(line))
         {
             return(true);
         }
     }
     return(false);
 }
Beispiel #7
0
 /** <summary> Returns true if the specified line is parallel. </summary> */
 public bool IsParallel(Line2F l)
 {
     return ((Width * l.Height) - (Height * l.Width) == 0);
 }
Beispiel #8
0
        /** <summary> Gets the point of intersection between the two lines. </summary> */
        public Vector2F? PointOfIntersection(Line2F l)
        {
            Vector2F? point = PointOfIntersectionEndless(l);

            float epsilon = 0.0f;

            if (point != null) {
            Vector2F epsilonVector = new Vector2F(epsilon, epsilon);
            if (point.Value + epsilonVector < Min || point.Value + epsilonVector < l.Min)
                return null;
            if (point.Value - epsilonVector > Max || point.Value - epsilonVector > l.Max)
                return null;
            }
            return point;
        }
Beispiel #9
0
 /** <summary> Returns true if the specified line is inside this line. </summary> */
 public bool Contains(Line2F line)
 {
     return false;
 }
Beispiel #10
0
 /** <summary> Returns true if the line is collinear with the specified line. </summary> */
 public bool IsLineCollinear(Line2F l)
 {
     if (IsParallel(l)) {
     if (IsEmpty || l.IsEmpty)
         return false;
     if (End1 != l.End1)
         return IsParallel(new Line2F(End1, l.End1));
     else
         return IsParallel(new Line2F(End2, l.End1));
     }
     return false;
 }
Beispiel #11
0
 /** <summary> Constructs a copy of the specified line. </summary> */
 public Line2F(Line2F l)
 {
     this.End1	= l.End1;
     this.End2	= l.End2;
 }
Beispiel #12
0
 /** <summary> Returns true if the specified line is colliding with this line. </summary> */
 public bool Colliding(Line2F line)
 {
     if (IsEmpty || line.IsEmpty)
     return false;
     if (!Bounds.Colliding(line.Bounds) && !IsStraight && !line.IsStraight)
     return false;
     if (PointOfIntersection(line) != null)
     return true;
     return IsLineCollinear(line);
 }
Beispiel #13
0
 /** <summary> Returns true if the specified line is parallel. </summary> */
 public bool IsParallel(Line2F l)
 {
     return((Width * l.Height) - (Height * l.Width) == 0);
 }
Beispiel #14
0
 /** <summary> Returns true if the specified line is inside this rectangle. </summary> */
 public bool Contains(Line2F line)
 {
     if (IsEmpty || line.IsEmpty)
     return false;
     return ((line.Min <  Max) &&
         (line.Max >= Min));
 }
Beispiel #15
0
        /** <summary> Returns the closest point on the specified line. </summary> */
        public Vector2F ClosestPointOnLine(Line2F l)
        {
            if (l.IsEmpty)
            return l.End1;

            float dot2 = l.Size.Dot(l.Size);
            float dotp = l.Size.Dot(this - l.End1);
            float t = GMath.Clamp(dotp / dot2, 0.0f, 1.0f);

            return l.End1 + l.Size * t;
        }
Beispiel #16
0
        /** <summary> Gets the point of endless intersection between the two lines. </summary> */
        public Vector2F? PointOfIntersectionEndless(Line2F l)
        {
            if (IsEmpty) {
            if ((l.IsEmpty && End1 == l.End1) ||
                (!l.IsEmpty && l.IsPointOnLine(End1)))
                return End1;
            else
                return null;
            }
            else if (l.IsEmpty) {
            return l.PointOfIntersectionEndless(this);
            }

            if (IsHorizontal) {
            if (l.IsHorizontal)
                return null;
            if (l.IsVertical)
                return new Vector2F(l.X1, this.Y1);

            float xi = l.X2 - ((l.Y2 - this.Y1) * (l.Width / l.Height));
            return new Vector2F(xi, this.Y1);
            }
            else if (IsVertical) {
            if (l.IsVertical)
                return null;
            if (l.IsHorizontal)
                return new Vector2F(this.X1, l.Y1);

            float yi = l.Y2 - ((l.X2 - this.X1) * (l.Height / l.Width));
            return new Vector2F(this.X1, yi);
            }
            else if (l.IsHorizontal || l.IsVertical) {
            return l.PointOfIntersectionEndless(this);
            }

            float det = (this.Width * l.Height) - (this.Height * l.Width);

            if (det == 0)
            return null;

            float d1 = ((this.X1 * this.Y2) - (this.Y1 * this.X2));
            float d2 = ((l.X1 * l.Y2) - (l.Y1 * l.X2));

            return new Vector2F(-((d1 *  l.Width) - (d2 *  this.Width)) / det,
                            -((d1 * l.Height) - (d2 * this.Height)) / det);
        }
Beispiel #17
0
        /** <summary> Gets the point of endless intersection between the two lines. </summary> */
        public Vector2F?PointOfIntersectionEndless(Line2F l)
        {
            if (IsEmpty)
            {
                if ((l.IsEmpty && End1 == l.End1) ||
                    (!l.IsEmpty && l.IsPointOnLine(End1)))
                {
                    return(End1);
                }
                else
                {
                    return(null);
                }
            }
            else if (l.IsEmpty)
            {
                return(l.PointOfIntersectionEndless(this));
            }

            if (IsHorizontal)
            {
                if (l.IsHorizontal)
                {
                    return(null);
                }
                if (l.IsVertical)
                {
                    return(new Vector2F(l.X1, this.Y1));
                }

                float xi = l.X2 - ((l.Y2 - this.Y1) * (l.Width / l.Height));
                return(new Vector2F(xi, this.Y1));
            }
            else if (IsVertical)
            {
                if (l.IsVertical)
                {
                    return(null);
                }
                if (l.IsHorizontal)
                {
                    return(new Vector2F(this.X1, l.Y1));
                }

                float yi = l.Y2 - ((l.X2 - this.X1) * (l.Height / l.Width));
                return(new Vector2F(this.X1, yi));
            }
            else if (l.IsHorizontal || l.IsVertical)
            {
                return(l.PointOfIntersectionEndless(this));
            }

            float det = (this.Width * l.Height) - (this.Height * l.Width);

            if (det == 0)
            {
                return(null);
            }

            float d1 = ((this.X1 * this.Y2) - (this.Y1 * this.X2));
            float d2 = ((l.X1 * l.Y2) - (l.Y1 * l.X2));

            return(new Vector2F(-((d1 * l.Width) - (d2 * this.Width)) / det,
                                -((d1 * l.Height) - (d2 * this.Height)) / det));
        }
Beispiel #18
0
 // Returns the shortest distance from this point to the specified line.
 public float DistanceToLine(Line2F l)
 {
     return(DistanceTo(ClosestPointOnLine(l)));
 }
Beispiel #19
0
 /** <summary> Returns true if the specified line is inside this line. </summary> */
 public bool Contains(Line2F line)
 {
     return(false);
 }
Beispiel #20
0
 //-----------------------------------------------------------------------------
 // Vector graphics
 //-----------------------------------------------------------------------------
 // Draws the specified line.
 public void DrawLine(Line2F line, float thickness, Color color, float depth = 0.0f)
 {
     DrawImage(white1x1, line.Center + new Vector2F(0.5f, 0.5f), new Vector2F(0.5f, 0.5f),
     new Vector2F((line.Length + thickness), thickness),
     line.Direction, color, SpriteEffects.None, depth);
 }
Beispiel #21
0
 /** <summary> Returns true if the specified line is colliding with this rectangle. </summary> */
 public bool Colliding(Line2F line)
 {
     if (IsEmpty || line.IsEmpty)
     return false;
     if (!Colliding(line.Bounds))
     return false;
     if (Contains(line.End1))
     return true;
     foreach (Line2F l in Lines) {
     if (l.Colliding(line))
         return true;
     }
     return false;
 }
Beispiel #22
0
 /** <summary> Returns the shortest distance from this point to the specified line. </summary> */
 public float DistanceToLine(Line2F l)
 {
     return DistanceTo(ClosestPointOnLine(l));
 }
Beispiel #23
0
 /** <summary> Constructs a copy of the specified line. </summary> */
 public Line2F(Line2F l)
 {
     this.End1 = l.End1;
     this.End2 = l.End2;
 }