예제 #1
0
        public SurfacePosition Move(SurfacePosition position, SurfaceDirection direction)
        {
            if (IsLost(position, direction))
            {
                throw new RobotLostException();
            }

            var newPosition = new SurfacePosition(position.Row, position.Column);

            switch (direction)
            {
            case SurfaceDirection.Up:
                newPosition.Row++;
                break;

            case SurfaceDirection.Left:
                newPosition.Column--;
                break;

            case SurfaceDirection.Down:
                newPosition.Row--;
                break;

            case SurfaceDirection.Right:
                newPosition.Column++;
                break;

            default:
                throw new ArgumentException(nameof(direction), "Direction is not supported: " + direction);
            }

            return(newPosition);
        }
예제 #2
0
        private bool IsLost(SurfacePosition position, SurfaceDirection direction)
        {
            if (position.Column == 0 && direction == SurfaceDirection.Left)
            {
                _leftColumnRobotScents[position.Row] = true;
                return(true);
            }
            else if (position.Column == _columnsCount - 1 && direction == SurfaceDirection.Right)
            {
                _rightColumnRobotScents[position.Row] = true;
                return(true);
            }
            else if (position.Row == 0 && direction == SurfaceDirection.Down)
            {
                _bottomRowRobotScents[position.Column] = true;
                return(true);
            }
            else if (position.Row == _rowsCount - 1 && direction == SurfaceDirection.Up)
            {
                _upperRowRobotScents[position.Column] = true;
                return(true);
            }

            return(false);
        }
예제 #3
0
        public Robot(ISurfaceGrid marsSurface, SurfacePosition position, SurfaceDirection direction)
        {
            Position  = position;
            Direction = direction;

            _marsSurface = marsSurface ?? throw new ArgumentNullException(nameof(marsSurface));
            IsLost       = !_marsSurface.IsValidPosition(position);
        }
예제 #4
0
		private IOSurfaceInfo DeclareIO(SurfaceDirection direction, string channel, SurfaceDisposition disposition)
		{
			var iosi = new IOSurfaceInfo();
			iosi.SurfaceDirection = direction;
			iosi.Channel = channel;
			iosi.SurfaceDisposition = disposition;
			IOSurfaceInfos.Add(iosi);
			return iosi;
		}
예제 #5
0
        private IOSurfaceInfo DeclareIO(SurfaceDirection direction, string channel, SurfaceDisposition disposition)
        {
            var iosi = new IOSurfaceInfo();

            iosi.SurfaceDirection   = direction;
            iosi.Channel            = channel;
            iosi.SurfaceDisposition = disposition;
            IOSurfaceInfos.Add(iosi);
            return(iosi);
        }
예제 #6
0
 IOSurfaceInfo FindIOSurfaceInfo(string channel, SurfaceDirection direction)
 {
     foreach (var iosi in IOSurfaceInfos)
     {
         if (iosi.Channel == channel && iosi.SurfaceDirection == direction)
         {
             return(iosi);
         }
     }
     return(null);
 }
예제 #7
0
        private IOSurfaceInfo DeclareIO(SurfaceDirection direction, string channel, SurfaceDisposition disposition)
        {
            var iosi = new IOSurfaceInfo
            {
                SurfaceDirection   = direction,
                Channel            = channel,
                SurfaceDisposition = disposition
            };

            _ioSurfaceInfos.Add(iosi);
            return(iosi);
        }
예제 #8
0
        public bool IsDeadScentMovement(SurfacePosition position, SurfaceDirection direction)
        {
            if (position.Column == 0 && direction == SurfaceDirection.Left)
            {
                return(_leftColumnRobotScents[position.Row]);
            }
            else if (position.Column == _columnsCount - 1 && direction == SurfaceDirection.Right)
            {
                return(_rightColumnRobotScents[position.Row]);
            }
            else if (position.Row == 0 && direction == SurfaceDirection.Down)
            {
                return(_bottomRowRobotScents[position.Column]);
            }
            else if (position.Row == _rowsCount - 1 && direction == SurfaceDirection.Up)
            {
                return(_upperRowRobotScents[position.Column]);
            }

            return(false);
        }
예제 #9
0
 public void SetDirection(SurfaceDirection newDirection)
 {
     Direction = newDirection;
 }
예제 #10
0
 /// <summary>
 /// Extracts the isoparametric curves (isocurves) at the given parameter and surface direction.
 /// </summary>
 /// <param name="parameter">The parameter between 0.0 to 1.0 whether the isocurve will be extracted.</param>
 /// <param name="direction">The U or V direction whether the isocurve will be extracted.</param>
 /// <returns>The isocurve extracted.</returns>
 public NurbsCurve IsoCurve(double parameter, SurfaceDirection direction)
 {
     return(Analyze.Surface.Isocurve(this, parameter, direction));
 }
예제 #11
0
        /// <summary>
        /// Checks if a NURBS surface is closed.<br/>
        /// A surface is closed if the first points and the lasts in a direction are coincident.
        /// </summary>
        /// <returns>True if the curve is closed.</returns>
        public bool IsClosed(SurfaceDirection direction)
        {
            var pts2d = (direction == SurfaceDirection.U) ? CollectionHelpers.Transpose2DArray(ControlPointLocations) : ControlPointLocations;

            return(pts2d.All(pts => pts[0].DistanceTo(pts.Last()) < GSharkMath.Epsilon));
        }
예제 #12
0
		IOSurfaceInfo FindIOSurfaceInfo(string channel, SurfaceDirection direction)
		{
			foreach (var iosi in IOSurfaceInfos)
				if (iosi.Channel == channel && iosi.SurfaceDirection == direction)
					return iosi;
			return null;
		}
예제 #13
0
        /// <summary>
        /// Performs a knot refinement on a surface by inserting knots at various parameters.<br/>
        /// <em>Implementation of Algorithm A5.5 of The NURBS Book by Piegl and Tiller.</em>
        /// </summary>
        internal static NurbsSurface SurfaceKnotRefine(NurbsSurface surface, IList <double> knotsToInsert, SurfaceDirection direction)
        {
            List <List <Point4> > modifiedControlPts = new List <List <Point4> >();
            List <List <Point4> > controlPts         = surface.ControlPoints;
            KnotVector            knots = surface.KnotsV;
            int degree = surface.DegreeV;

            if (direction != SurfaceDirection.V)
            {
                controlPts = CollectionHelpers.Transpose2DArray(surface.ControlPoints);
                knots      = surface.KnotsU;
                degree     = surface.DegreeU;
            }

            NurbsBase curve = null;

            foreach (List <Point4> pts in controlPts)
            {
                curve = Curve.KnotRefine(new NurbsCurve(degree, knots, pts), knotsToInsert);
                modifiedControlPts.Add(curve.ControlPoints);
            }

            if (curve == null)
            {
                throw new Exception(
                          "The refinement was not be able to be completed. A problem occur refining the internal curves.");
            }

            if (direction != SurfaceDirection.V)
            {
                var reversedControlPts = CollectionHelpers.Transpose2DArray(modifiedControlPts);
                return(new NurbsSurface(surface.DegreeU, surface.DegreeV, curve.Knots, surface.KnotsV.Copy(),
                                        reversedControlPts));
            }

            return(new NurbsSurface(surface.DegreeU, surface.DegreeV, surface.KnotsU.Copy(), curve.Knots,
                                    modifiedControlPts));
        }
예제 #14
0
 /// <summary>
 /// Performs a knot refinement on a surface by inserting knots at various parameters and updating the control point locations.<br/>
 /// <em>Implementation of Algorithm A5.5 of The NURBS Book by Piegl and Tiller.</em>
 /// ToDo: refactor this algo following the book.
 /// </summary>
 /// <param name="surface">The surface object to insert the knots.</param>
 /// <param name="knotsToInsert">The set of knots to insert.</param>
 /// <param name="direction">Whether to insert in the U or V direction of the surface.</param>
 /// <returns>A surface with the knots inserted.</returns>
 public static NurbsSurface Refine(NurbsSurface surface, IList <double> knotsToInsert, SurfaceDirection direction)
 {
     return(Modify.Surface.SurfaceKnotRefine(surface, knotsToInsert, direction));
 }
 public IRobot AddNewRobot(SurfacePosition position, SurfaceDirection direction)
 {
     return(new Robot(_marsSurface, position, direction));
 }
        public void GetCommand_Should_Success(int surfaceRowsCount, int surfaceColumnsCount, int robotPositionRow, int robotPositionColumn, SurfaceDirection surfaceDirection,
                                              string commandsString, int expectedPositionRow, int expectedPositionColumn, SurfaceDirection expectedDirection, bool expectedIsLost)
        {
            SurfaceGrid _marsSurface = new SurfaceGrid(surfaceRowsCount + 1, surfaceColumnsCount + 1);
            MarsInvasionControlCenter controlCenter = new MarsInvasionControlCenter(_marsSurface);

            var position = new SurfacePosition(robotPositionRow, robotPositionColumn);
            var newRobot = controlCenter.AddNewRobot(position, surfaceDirection);

            if (!newRobot.IsLost)
            {
                var commandSet = RobotCommandSet.Create(_commandsFactory, commandsString);
                newRobot.ExecuteCommands(commandSet);
                PrintPosition(newRobot);
            }
            else
            {
                PrintPosition(newRobot);
            }

            Assert.AreEqual(expectedPositionRow, newRobot.Position.Row);
            Assert.AreEqual(expectedPositionColumn, newRobot.Position.Column);
            Assert.AreEqual(expectedDirection, newRobot.Direction);
            Assert.AreEqual(expectedIsLost, newRobot.IsLost);
        }