Exemplo n.º 1
0
        public static void PlugOneSideHoles(OptimizedImgParams indices, double allowedHoleHeight, MinXOrMaxXEnum minXOrMaxXEnum)
        {
            //create a new set of points that will be modified using the plug hole logic
            var points            = new List <Point>();
            var xLimitsAtYIndices = indices.XLimitsAtYIndices;

            for (var y = 0; y < xLimitsAtYIndices.Length; y++)
            {
                var xLimits = xLimitsAtYIndices[y];
                if (xLimits.Width <= 0)
                {
                    continue;
                }

                int x;
                switch (minXOrMaxXEnum)
                {
                case MinXOrMaxXEnum.MinX:
                    x = xLimits.Min;
                    break;

                case MinXOrMaxXEnum.MaxX:
                default:
                    x = xLimits.Max;
                    break;
                }
                var point = new Point(x, y);
                points.Add(point);
            }

            PlugHolesRepeatedly(points, allowedHoleHeight, minXOrMaxXEnum);

            ModifyXValuesBasedOnNewPoints(xLimitsAtYIndices, points, minXOrMaxXEnum);
        }
Exemplo n.º 2
0
        public static void ModifyXValuesBasedOnNewPoints(MinAndMaxIndices[] xLimitsAtYIndices, List <Point> points, MinXOrMaxXEnum minXOrMaxXEnum)
        {
            if (points.Count <= 1)
            {
                return;
            }
            var outerPtIndex       = 0;
            var oneLessThanPtCount = points.Count - 1;

            for (var y = 0; y < xLimitsAtYIndices.Length; y++)
            {
                var xLimits = xLimitsAtYIndices[y];
                if (xLimits.Width <= 0)
                {
                    continue;
                }

                //find the first index which has the points.y value greater than or equal to the current y
                var outerY = points[outerPtIndex].GetIntY();

                while (outerPtIndex < oneLessThanPtCount && outerY < y)
                {
                    outerPtIndex++;
                    outerY = points[outerPtIndex].GetIntY();
                }
                var newX = GetNewX(points, y, outerPtIndex, outerY);

                switch (minXOrMaxXEnum)
                {
                case MinXOrMaxXEnum.MaxX:
                    xLimits.Max = newX;
                    break;

                case MinXOrMaxXEnum.MinX:
                    xLimits.Min = newX;
                    break;
                }
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// keeps removing holes till no more holes can be removed
        /// </summary>
        /// <param name="points"></param>
        /// <param name="allowedHoleHeight"></param>
        /// <param name="minXOrMaxXEnum"></param>
        public static void PlugHolesRepeatedly(List <Point> points, double allowedHoleHeight, MinXOrMaxXEnum minXOrMaxXEnum)
        {
            bool holesRemoved;
            IHoleStatusHelper holeStatusHelper;

            switch (minXOrMaxXEnum)
            {
            case MinXOrMaxXEnum.MinX:
                holeStatusHelper = new LeftHoleStatusHelper();
                break;

            case MinXOrMaxXEnum.MaxX:
            default:
                holeStatusHelper = new RightHoleStatusHelper();
                break;
            }
            do
            {
                holesRemoved = PlugSideHoles(points, holeStatusHelper, allowedHoleHeight);
            } while (holesRemoved);
        }