Exemple #1
0
        public RowPoints[ , ] SortPointsInToRowsAndColumns(IEnumerable <PointF> points)
        {
            if (points == null)
            {
                throw new ArgumentNullException(nameof(points), @"Points collection cannot be null.");
            }

            var pointFs = points as IList <PointF> ?? points.ToList( );

            // Ensure there is 10 points per row.
            if (pointFs.Count % 10 != 0)
            {
                return(new RowPoints[0, 0]);
            }
            // There are 10 dots per full row
            // on the alignment pattern.
            const int pointsPerFullRow = 10;

            // Split each row in to columns of
            // 5 points (alignment dots).
            const int numberOfColumns = 2;

            // Sort the points based on their Y coordinate
            // to make it eaiser to split the rows apart.
            var sorted = pointFs.OrderBy(p => p.Y).ToList( );

            // Determine the number of rows found in the
            // alignment image.
            var numberOfRows = sorted.Count / pointsPerFullRow;

            // Create the structure which will hold each
            // row and column of dots.
            var splitPoints = new RowPoints[numberOfRows, 2];

            for (int row = 0; row < numberOfRows; row++)
            {
                // Grab the next row of points (alignment dots).
                var nextRow = sorted.GetRange(row * pointsPerFullRow, pointsPerFullRow).OrderBy(p => p.X);

                for (int column = 0; column < numberOfColumns; column++)
                {
                    // Split the row in to columns consisting
                    // of 5 points (alignment dots) per column.
                    var nextColumn = nextRow
                                     .ToList( )
                                     .GetRange(column * 5, 5);

                    splitPoints[row, column] = new RowPoints(row, column, nextColumn);
                }
            }
            return(splitPoints);
        }
Exemple #2
0
        public void SortPointsInToRowsAndColumnsTestNotEnoughPointsToSort( )
        {
            var alignmentDotCoordinates = new List <PointF>
            {
                new PointF(100, 20),
                new PointF(10, 10),
                new PointF(20, 10),
                new PointF(90, 20),
                new PointF(30, 10),
                new PointF(60, 20),
            };

            var expected = new RowPoints[0, 0];
            var analyzer = new Analyzer( );

            var result = analyzer.SortPointsInToRowsAndColumns(alignmentDotCoordinates);

            Assert.AreEqual(expected, result);
        }