예제 #1
0
        /// <summary>
        /// Gets all points along an edge.
        /// <paramref name="edgeValues"/> should contain 4 values:
        /// <paramref name="edgeValues"/>[i] should be the constant value
        /// corresponding to the <paramref name="coordinateOrder"/>[i]th
        /// coordinate, for i in {0, 1}
        /// <paramref name="edgeValues"/>[2] and <paramref name="edgeValues"/>[3]
        /// should be the min and max values of the <paramref name="coordinateOrder"/>[2]nd
        /// coordinate.
        /// </summary>
        /// <param name="edgeValues"></param>
        /// <param name="coordinateOrder"></param>
        /// <returns></returns>
        public static IList <GridPoint3D> GetPointsAlongEdge(
            int[] edgeValues,
            string coordinateOrder)
        {
            if (edgeValues.Length != 4)
            {
                throw new ArgumentException(nameof(edgeValues));
            }
            if (coordinateOrder.Length != 3)
            {
                throw new ArgumentException(nameof(coordinateOrder));
            }
            coordinateOrder = coordinateOrder.ToUpper();
            if (!coordinateOrder.Contains("X"))
            {
                throw new ArgumentException(nameof(coordinateOrder));
            }
            if (!coordinateOrder.Contains("Y"))
            {
                throw new ArgumentException(nameof(coordinateOrder));
            }
            if (!coordinateOrder.Contains("Z"))
            {
                throw new ArgumentException(nameof(coordinateOrder));
            }

            var result = new List <GridPoint3D>();

            for (int rangeCoordinate = edgeValues[2]; rangeCoordinate <= edgeValues[3]; rangeCoordinate++)
            {
                var pointValues = new int[3];
                for (int pointCoordinateIndex = 0; pointCoordinateIndex < 3; pointCoordinateIndex++)
                {
                    var coordinate = "XYZ"[pointCoordinateIndex];
                    var pointCoordinateOrderIndex = coordinateOrder.IndexOf(coordinate);
                    int value;
                    if (pointCoordinateOrderIndex == 2)
                    {
                        value = rangeCoordinate;
                    }
                    else
                    {
                        value = edgeValues[pointCoordinateOrderIndex];
                    }
                    pointValues[pointCoordinateIndex] = value;
                }
                var point = new GridPoint3D(pointValues[0], pointValues[1], pointValues[2]);
                result.Add(point);
            }
            return(result);
        }
예제 #2
0
 private static ConsoleColor GetPointColorDefault(GridPoint3D point)
 {
     return(Console.ForegroundColor);
 }
예제 #3
0
        public static IList <Tuple <string, ConsoleColor> > GetGridRenderingData(
            int minX,
            int maxX,
            int minY,
            int maxY,
            int minZ,
            int maxZ,
            Func <GridPoint3D, string> GetPointString,
            Func <GridPoint3D, ConsoleColor> GetPointColor,
            string prependText,
            bool invertY,
            bool invertZ)
        {
            var result  = new List <Tuple <string, ConsoleColor> >();
            var builder = new StringBuilder();

            var yDirection = invertY ? -1 : 1;
            var yStart     = invertY ? maxY : minY;
            var yEnd       = invertY ? minY : maxY;
            int yDiff      = Math.Abs(yEnd - yStart);

            var zDirection = invertZ ? -1 : 1;
            var zStart     = invertZ ? maxZ : minZ;
            var zEnd       = invertZ ? minZ : maxZ;
            int zDiff      = Math.Abs(zEnd - zStart);

            for (int zIndex = 0; zIndex <= zDiff; zIndex++)
            {
                int z = zStart + (zIndex * zDirection);
                builder.Append(Environment.NewLine);
                builder.Append(prependText + $"Z: {z}");
                builder.Append(Environment.NewLine);

                for (int yIndex = 0; yIndex <= yDiff; yIndex++)
                {
                    int y = yStart + (yIndex * yDirection);
                    builder.Append(prependText);
                    for (int x = minX; x <= maxX; x++)
                    {
                        var point       = new GridPoint3D(x, y, z);
                        var pointString = GetPointString(point);
                        var pointColor  = GetPointColor(point);
                        if (!pointColor.Equals(Console.ForegroundColor))
                        {
                            result.Add(new Tuple <string, ConsoleColor>(builder.ToString(), Console.ForegroundColor));
                            builder.Clear();
                        }
                        builder.Append(pointString);
                        if (!pointColor.Equals(Console.ForegroundColor))
                        {
                            result.Add(new Tuple <string, ConsoleColor>(builder.ToString(), pointColor));
                            builder.Clear();
                        }
                    }
                    builder.Append(Environment.NewLine);
                }
            }

            builder.Append(Environment.NewLine);
            result.Add(new Tuple <string, ConsoleColor>(builder.ToString(), Console.ForegroundColor));
            return(result);
        }