Exemplo n.º 1
0
        /// <summary>
        /// This function stores the field lines passed in
        /// </summary>
        /// <remarks>
        /// 2D arrays are not optimized, but in this case, it's easier for the outside user to work with.
        /// </remarks>
        /// <param name="fieldLines">fieldLines[X, Y] (x and y go from 0 to SquaresPerSide - 1)</param>
        public void SetFieldLines(MyVector[,] fieldLines)
        {
            // Check out the array
            if (fieldLines == null)
            {
                throw new ArgumentNullException("fieldLines", "fieldLines cannot be null");
            }

            if (fieldLines.GetUpperBound(0) != _squaresPerSideX - 1)
            {
                throw new ArgumentOutOfRangeException("fieldLines.GetUpperBound(0)", fieldLines.GetUpperBound(0), "fieldLines.GetUpperBound(0) must be the same as _squaresPerSideX - 1\nUBound: " + fieldLines.GetUpperBound(0).ToString() + ", _squaresPerSideX - 1: " + ((int)(_squaresPerSideX - 1)).ToString());
            }

            if (fieldLines.GetUpperBound(1) != _squaresPerSideY - 1)
            {
                throw new ArgumentOutOfRangeException("fieldLines.GetUpperBound(1)", fieldLines.GetUpperBound(1), "fieldLines.GetUpperBound(1) must be the same as _squaresPerSideY - 1\nUBound: " + fieldLines.GetUpperBound(1).ToString() + ", _squaresPerSideY - 1: " + ((int)(_squaresPerSideY - 1)).ToString());
            }

            // Init my grid
            _grid = new MyVector[fieldLines.Length];

            // Store the lines
            for (int xCntr = 0; xCntr <= fieldLines.GetUpperBound(0); xCntr++)
            {
                for (int yCntr = 0; yCntr <= fieldLines.GetUpperBound(1); yCntr++)
                {
                    _grid[GetIndex(xCntr, yCntr)] = fieldLines[xCntr, yCntr];
                }
            }

            // Put myself into a custom state
            _fieldMode = VectorField2DMode.Custom;

            // No need to call ResetField()
        }