コード例 #1
0
ファイル: ILine2DExtensions.cs プロジェクト: lanicon/Styx
        /// <summary>
        /// Checks if the given lines intersect.
        /// </summary>
        /// <param name="Line1">A line.</param>
        /// <param name="Line2">A line.</param>
        /// <param name="InfiniteLines">Whether the lines should be treated as infinite or not.</param>
        /// <returns>True if the lines intersect; False otherwise.</returns>
        public static Boolean IntersectsWith <T>(this ILine2D <T> Line1, ILine2D <T> Line2, Boolean InfiniteLines = false)
            where T : IEquatable <T>, IComparable <T>, IComparable
        {
            IPixel <T> Intersection;

            return(Line1.IntersectsWith(Line2, out Intersection, InfiniteLines));
        }
コード例 #2
0
ファイル: Voronoi.cs プロジェクト: alrehamy/Illias
 public AdjacencyInfo(ITriangle <T> Neighbor1, ITriangle <T> Neighbor2, ITriangle <T> Neighbor3,
                      ILine2D <T> FreeEdge1, ILine2D <T> FreeEdge2, ILine2D <T> FreeEdge3)
 {
     this.Neighbor1 = Neighbor1;
     this.Neighbor2 = Neighbor2;
     this.Neighbor3 = Neighbor3;
     this.FreeEdge1 = FreeEdge1;
     this.FreeEdge2 = FreeEdge2;
     this.FreeEdge3 = FreeEdge3;
 }
コード例 #3
0
        /// <summary>
        /// Compares two lines for equality.
        /// </summary>
        /// <param name="ILine">A line to compare with.</param>
        /// <returns>True if both match; False otherwise.</returns>
        public Boolean Equals(ILine2D <T> ILine)
        {
            if ((Object)ILine == null)
            {
                return(false);
            }

            // Normal direction
            return((this.X1.Equals(ILine.X1) &&
                    this.Y1.Equals(ILine.Y1) &&
                    this.X2.Equals(ILine.X2) &&
                    this.Y2.Equals(ILine.Y2))
                   ||
                   // Opposite direction
                   (this.X1.Equals(ILine.X2) &&
                    this.Y1.Equals(ILine.Y2) &&
                    this.X2.Equals(ILine.X1) &&
                    this.Y2.Equals(ILine.Y1)));
        }
コード例 #4
0
        /// <summary>
        /// Checks if and where the given lines intersect.
        /// </summary>
        /// <param name="Line">A line.</param>
        /// <param name="Pixel">The intersection of both lines.</param>
        /// <param name="InfiniteLines">Whether the lines should be treated as infinite or not.</param>
        /// <returns>True if the lines intersect; False otherwise.</returns>
        public Boolean IntersectsWith(ILine2D <T> Line, out IPixel <T> Pixel, Boolean InfiniteLines = false)
        {
            #region Initial Checks

            if (Line == null)
            {
                Pixel = null;
                return(false);
            }

            #endregion

            // Assume both lines are infinite in order to get their intersection...

            #region This line is just a pixel

            if (this.IsJustAPixel())
            {
                var p = new Pixel <T>(this.X1, this.Y1);

                if (Line.Contains(p))
                {
                    Pixel = p;
                    return(true);
                }

                Pixel = null;
                return(false);
            }

            #endregion

            #region The given line is just a pixel

            else if (Line.IsJustAPixel())
            {
                var p = new Pixel <T>(Line.X1, Line.Y1);

                if (this.Contains(p))
                {
                    Pixel = p;
                    return(true);
                }

                Pixel = null;
                return(false);
            }

            #endregion

            #region Both lines are parallel or antiparallel

            else if (this.Normale.IsParallelTo(Line.Normale))
            {
                Pixel = null;
                return(false);
            }

            #endregion

            #region This line is parallel to the y-axis

            else if (this.Normale.Y.Equals(Math.Zero))
            {
                Pixel = new Pixel <T>(this.Pixel1.X,
                                      Math.Add(Math.Mul(Line.Gradient, this.Pixel1.X), Line.YIntercept));
            }

            #endregion

            #region The given line is parallel to the y-axis

            else if (Line.Normale.Y.Equals(Math.Zero))
            {
                Pixel = new Pixel <T>(Line.X1,
                                      Math.Add(Math.Mul(this.Gradient, Line.X1), this.YIntercept));
            }

            #endregion

            #region There is a real intersection

            else
            {
                Pixel = new Pixel <T>(Math.Div(Math.Sub(Line.YIntercept, this.YIntercept),
                                               Math.Sub(this.Gradient, Line.Gradient)),

                                      Math.Div(Math.Sub(Math.Mul(this.YIntercept, Line.Gradient),
                                                        Math.Mul(Line.YIntercept, this.Gradient)),
                                               Math.Sub(Line.Gradient, this.Gradient)));
            }

            #endregion

            if (InfiniteLines)
            {
                return(true);
            }
            else
            {
                return(this.Contains(Pixel));
            }
        }
コード例 #5
0
ファイル: ILine2DExtensions.cs プロジェクト: lanicon/Styx
 /// <summary>
 /// Checks if the given line is "just a pixel".
 /// </summary>
 /// <param name="Line">A line.</param>
 public static Boolean IsJustAPixel <T>(this ILine2D <T> Line)
     where T : IEquatable <T>, IComparable <T>, IComparable
 {
     return(Line.X1.Equals(Line.X2) &&
            Line.Y1.Equals(Line.Y2));
 }