Example #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);
        }
Example #2
0
        /// <summary>
        /// Get all points adjacent to a given point.
        /// Adjacent is defined as all points where any of their X, Y, or Z
        /// coordinates are within 1 of the central point's respective coordinate.
        /// </summary>
        /// <param name="centerPoint"></param>
        /// <returns></returns>
        public static IList <GridPoint3D> GetAdjacentPoints(GridPoint3D centerPoint)
        {
            var result           = new List <GridPoint3D>();
            var coordinateDeltas = new List <int[]>()
            {
                new int[3] {
                    -1, -1, -1
                },
                new int[3] {
                    0, -1, -1
                },
                new int[3] {
                    1, -1, -1
                },
                new int[3] {
                    -1, 0, -1
                },
                new int[3] {
                    0, 0, -1
                },
                new int[3] {
                    1, 0, -1
                },
                new int[3] {
                    -1, 1, -1
                },
                new int[3] {
                    0, 1, -1
                },
                new int[3] {
                    1, 1, -1
                },

                new int[3] {
                    -1, -1, 0
                },
                new int[3] {
                    0, -1, 0
                },
                new int[3] {
                    1, -1, 0
                },
                new int[3] {
                    -1, 0, 0
                },
                //new int[3]{ 0, 0, 0 },
                new int[3] {
                    1, 0, 0
                },
                new int[3] {
                    -1, 1, 0
                },
                new int[3] {
                    0, 1, 0
                },
                new int[3] {
                    1, 1, 0
                },

                new int[3] {
                    -1, -1, 1
                },
                new int[3] {
                    0, -1, 1
                },
                new int[3] {
                    1, -1, 1
                },
                new int[3] {
                    -1, 0, 1
                },
                new int[3] {
                    0, 0, 1
                },
                new int[3] {
                    1, 0, 1
                },
                new int[3] {
                    -1, 1, 1
                },
                new int[3] {
                    0, 1, 1
                },
                new int[3] {
                    1, 1, 1
                },
            };

            // Commented out for optimization purposes
            // CombinationsHelper.GetAllPossibleOutcomesOfNExperiments(new int[3] { -1, 0, 1 }, 3);
            foreach (var delta in coordinateDeltas)
            {
                if (delta[0] == 0 && delta[1] == 0 && delta[2] == 0)
                {
                    continue;
                }
                var point = new GridPoint3D(
                    centerPoint.X + delta[0],
                    centerPoint.Y + delta[1],
                    centerPoint.Z + delta[2]);
                result.Add(point);
            }
            return(result);
        }
Example #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);
        }
Example #4
0
 private static ConsoleColor GetPointColorDefault(GridPoint3D point)
 {
     return(Console.ForegroundColor);
 }