/// <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() }
private void ResetField() { if (this.Position == null) { // The constructor isn't finished return; } switch (_fieldMode) { case VectorField2DMode.None: _grid = null; break; case VectorField2DMode.Custom: if (_grid != null) { // Fix myself _grid = null; _fieldMode = VectorField2DMode.None; throw new InvalidOperationException("_fieldMode should only become Custom within this.SetFieldLines, and only after _grid is set up"); } break; case VectorField2DMode.Inward: ResetFieldSprtInOut(-1); break; case VectorField2DMode.Outward: ResetFieldSprtInOut(1); break; case VectorField2DMode.SwirlLeft: ResetFieldSprtSwirl(true); break; case VectorField2DMode.SwirlRight: ResetFieldSprtSwirl(false); break; default: throw new ApplicationException("Unknown VectorField2DMode: " + _fieldMode.ToString()); } }
public VectorField2D(VectorField2DMode fieldMode, double sizeX, double sizeY, int squaresPerSideX, int squaresPerSideY, double strength, MyVector position) { // I use the property sets to enforce constraints this.FieldMode = fieldMode; this.SizeX = sizeX; this.SizeY = sizeY; this.SquaresPerSideX = squaresPerSideX; this.SquaresPerSideY = squaresPerSideY; this.Strength = strength; // By waiting until now to set the position, I've kept ResetField from running (called by the property sets) _position = position; ResetField(); }
public VectorField2D(VectorField2DMode fieldMode, double size, int squaresPerSide, double strength, MyVector position) : this(fieldMode, size, size, squaresPerSide, squaresPerSide, strength, position) { }
public VectorField2D() { _fieldMode = VectorField2DMode.None; _position = new MyVector(); }