示例#1
0
        public TriangleVertices GetVerticesForCoordinate(TriangleCoordinate coordinate)
        {
            //Check if coordinate is valid:
            if (coordinate == null || CharToNum(coordinate.Row) > RowCount() || coordinate.Column > ColumnCount() ||
                coordinate.Column < 0)
            {
                return(null);
            }

            //Odds are at the bottom of the sqr
            var isTop = coordinate.Column % 2 == 0;

            //top-left vertex:
            int topLeftX = (int)(Math.Ceiling(coordinate.Column / 2d) - 1) * _sqrSize;
            var topLeftY = _imgSize - ((CharToNum(coordinate.Row) - 1) * _sqrSize);

            //bottom-right vertex
            var bottomRightX = (int)Math.Ceiling(coordinate.Column / 2d) * _sqrSize;
            var bottomRightY = _imgSize - (CharToNum(coordinate.Row) * _sqrSize);

            //right-angle vertex
            var midX = isTop ? bottomRightX : topLeftX;
            var midY = isTop ? topLeftY : bottomRightY;

            return(new TriangleVertices(
                       topLeftX, topLeftY,
                       bottomRightX, bottomRightY,
                       midX, midY));
        }