Ejemplo n.º 1
0
        /// <summary>
        /// { Returns the triangle neighbouring aTriangle which is nearer to
        /// aPoint than aTriangle.If aPoint is in aTriangle then aTriangle is
        /// returned, and found set to true. If aPoint is outside the model,
        /// returns Nil - requires model to be convex. }
        /// </summary>
        /// <param name="aPoint"></param>
        /// <param name="aTriangle"></param>
        /// <param name="lastTri"></param>
        /// <param name="found"></param>
        /// <returns></returns>
        protected Triangle GetBestTri(TriVertex aPoint, Triangle aTriangle, Triangle lastTri, out bool found)
        {
            Triangle Result;

            found = false;

            TriVertex firstPoint  = aTriangle.Vertices[0];
            TriVertex secondPoint = aTriangle.Vertices[1];

            if (aTriangle.Neighbours[0] != lastTri && TinningUtils.DefinitelyLeftOfBaseLine(aPoint, firstPoint, secondPoint))
            {
                Result = aTriangle.Neighbours[0];
            }
            else
            {
                TriVertex thirdPoint = aTriangle.Vertices[2];
                if (aTriangle.Neighbours[1] != lastTri && TinningUtils.DefinitelyLeftOfBaseLine(aPoint, secondPoint, thirdPoint))
                {
                    Result = aTriangle.Neighbours[1];
                }
                else if (aTriangle.Neighbours[2] != lastTri && TinningUtils.DefinitelyLeftOfBaseLine(aPoint, thirdPoint, firstPoint))
                {
                    Result = aTriangle.Neighbours[2];
                }
                else // to the right of each line -must be inside aTriangle
                {
                    Result = aTriangle;
                    found  = true;
                }
            }

            return(Result);
        }