示例#1
0
        private static Edge BuildMinimaBounds(LocalMinima localMinima, Edge edge)
        {
            var leftIsForward = edge.Dx > edge.Next.Dx;

            // Assign left and right bounds
            localMinima.LeftBound  = leftIsForward ? edge.Next : edge;
            localMinima.RightBound = leftIsForward ? edge : edge.Next;

            // Build left and right bounds
            var nextLeft  = BuildBound(localMinima.LeftBound, leftIsForward);
            var nextRight = BuildBound(localMinima.RightBound, !leftIsForward);

            // Return the next edge to continue search
            return(leftIsForward ? nextLeft : nextRight);
        }
示例#2
0
        public static IList <LocalMinima> BuildLml(Edge boundaryStart)
        {
            var localMinimaList = new List <LocalMinima>();

            Edge firstLocalMinimaEdge = null;
            var  edge = boundaryStart;

            while (true)
            {
                if (!edge.EndIsLocalMinima)
                {
                    edge = edge.Next;
                    continue;
                }

                if (edge == firstLocalMinimaEdge)
                {
                    break;
                }

                if (firstLocalMinimaEdge == null)
                {
                    firstLocalMinimaEdge = edge;
                }

                // Local minima found
                var localMinima = new LocalMinima
                {
                    // This is a local minima, so the bottom of this edge
                    // (the start vertex of the next edge) is the minima vertex.
                    Y = edge.Bottom.Y
                };

                // Add to the LML list
                localMinimaList.Add(localMinima);

                // Build left and right bounds, returns next edge after
                // the forward bound.
                var nextForwardEdge = BuildMinimaBounds(localMinima, edge);

                // Move to the edge after right maxima
                edge = nextForwardEdge;
            }

            return(localMinimaList);
        }