Exemple #1
0
        public void TestGetNextPoint()
        {
            GridPoint point = new GridPoint(2, 3);
            GridPoint nextPoint;

            nextPoint = point.GetNextPoint(Direction.DOWN);
            Assert.AreEqual(new GridPoint(1, 3), nextPoint);

            nextPoint = point.GetNextPoint(Direction.LEFT);
            Assert.AreEqual(new GridPoint(2, 2), nextPoint);

            nextPoint = point.GetNextPoint(Direction.LEFT_DOWN);
            Assert.AreEqual(new GridPoint(1, 2), nextPoint);

            nextPoint = point.GetNextPoint(Direction.LEFT_UP);
            Assert.AreEqual(new GridPoint(3, 2), nextPoint);

            nextPoint = point.GetNextPoint(Direction.RIGHT);
            Assert.AreEqual(new GridPoint(2, 4), nextPoint);

            nextPoint = point.GetNextPoint(Direction.RIGHT_DOWN);
            Assert.AreEqual(new GridPoint(1, 4), nextPoint);

            nextPoint = point.GetNextPoint(Direction.RIGHT_UP);
            Assert.AreEqual(new GridPoint(3, 4), nextPoint);

            nextPoint = point.GetNextPoint(Direction.UP);
            Assert.AreEqual(new GridPoint(3, 3), nextPoint);
        }
Exemple #2
0
        /// <summary>
        /// Field boundary with a unique representation. For example,
        /// if this is called once with (0, 0) UP and once with (1, 0) DOWN
        /// then both represent the same boundary and are equal.
        /// </summary>
        /// <param name="basePoint"> Point which has the boundary </param>
        /// <param name="directionFromBase"> Direction of the boundary relative to the base point </param>
        public FieldBoundary(GridPoint basePoint, Direction directionFromBase)
        {
            // Unique representation for the same boundary
            if (!baseDirections.Contains(directionFromBase))
            {
                basePoint         = basePoint.GetNextPoint(directionFromBase);
                directionFromBase = directionFromBase.GetOpposite();
            }

            BasePoint         = basePoint;
            DirectionFromBase = directionFromBase;
        }
        /// <summary>
        /// A segment of field changes
        /// </summary>
        /// <param name="startPoint"> Starting point </param>
        /// <param name="direction"> Direction to continue from the starting point </param>
        /// <param name="values"> Field values of the changes </param>
        public FieldsToChange(GridPoint startPoint, Direction direction, IEnumerable <T> values) : this()
        {
            if (values == null)
            {
                throw new ArgumentNullException();
            }

            GridPoint currentPoint = startPoint;

            foreach (T v in values)
            {
                Add(currentPoint, v);
                currentPoint = currentPoint.GetNextPoint(direction);
            }
        }