コード例 #1
0
        /// <summary>
        /// Given triangle notation returns vertex coordinates
        /// </summary>
        /// <param name="triangleName">Row-column notation</param>
        /// <returns>List of 2 points, representing vertex coordinates</returns>
        public static List <Point> GetCoordinatesFromName(string triangleName)
        {
            var parsedTriangleName = NameNumberConverter.ParseTriangleName(triangleName);
            var triangleNameLetter = parsedTriangleName.Item1;
            var triangleNameNumber = parsedTriangleName.Item2;

            //2 triangles per column; it's integer division, so even if the number is odd, it will
            //return the whole number result rounded up to smaller number
            var columnNumber = triangleNameNumber / 2;
            //10 pixel/points per column
            int rightX            = columnNumber * PixelsPerRowOrColumn;
            var letterOrderNumber = NameNumberConverter.ConvertLetterToNumber(triangleNameLetter);
            //The grid is "upside down" as related to Y axis - the lowest order letter has the highest
            //point is the closest to 0, thus we do this
            var rowNumber = TotalNumberOfRows - letterOrderNumber;
            //this reflects the location of triangles inside the cell - the even numbered ones
            //have the higher Y point than odd ones
            bool  isOddTriangle         = triangleNameNumber % 2 > 0;
            int   rightY                = isOddTriangle ? rowNumber * PixelsPerRowOrColumn : (rowNumber + 1) * PixelsPerRowOrColumn;
            Point rightAngleCoordinates = new Point(rightX, rightY);
            Point point2                = isOddTriangle ?
                                          new Point(rightAngleCoordinates.X + PixelsPerRowOrColumn, rightAngleCoordinates.Y) :
                                          new Point(rightAngleCoordinates.X - PixelsPerRowOrColumn, rightAngleCoordinates.Y);
            Point point3 = isOddTriangle ?
                           new Point(rightAngleCoordinates.X, rightAngleCoordinates.Y + PixelsPerRowOrColumn) :
                           new Point(rightAngleCoordinates.X, rightAngleCoordinates.Y - PixelsPerRowOrColumn);

            return(new List <Point>()
            {
                rightAngleCoordinates, point2, point3
            });
        }
コード例 #2
0
        /// <summary>
        /// Given vertex coordinates returns row-column letter-number notation
        /// </summary>
        /// <param name="point1">Triangle point 1</param>
        /// <param name="point2">Triangle point 2 </param>
        /// <param name="point3">Triangle point 3</param>
        /// <returns></returns>
        public static string GetNameFromCoordinates(Point point1, Point point2, Point point3)
        {
            Point rightAngleCoordinates = new Point(ReturnDuplicate(point1.X, point2.X, point3.X),
                                                    ReturnDuplicate(point1.Y, point2.Y, point3.Y));
            //reversing the original calculations
            bool isOddTriangleNumber = IsOdd(rightAngleCoordinates.Y, new List <int> {
                point1.Y, point2.Y, point3.Y
            });
            //2 triangles per column
            var adjustedColumnNumber = PixelsPerRowOrColumn / 2;
            //have to add one to the odd number triangle as we rounded it up with the interger division above
            int triangleNameNumber = isOddTriangleNumber ? rightAngleCoordinates.X / adjustedColumnNumber + 1
                : rightAngleCoordinates.X / adjustedColumnNumber;

            int triangleNameLetterOrder = isOddTriangleNumber ? (TotalNumberOfRows - rightAngleCoordinates.Y / PixelsPerRowOrColumn) :
                                          (TotalNumberOfRows + 1 - rightAngleCoordinates.Y / PixelsPerRowOrColumn);
            char triangleNameLetter = NameNumberConverter.ConvertNumberToLetter(triangleNameLetterOrder);

            return(NameNumberConverter.ConvertToTriangleName(triangleNameLetter, triangleNameNumber));
        }