/// <summary> /// be sure to get a new one after a reset, CNS changes will not be respected /// </summary> /// <param name="stopFromDestGrid">how close to centreDestination grid to stop, if centreDestination is a grid</param> /// <returns></returns> public CollisionAvoidance(ref NavSettings CNS, GridDimensions gridDims) { VRage.Exceptions.ThrowIf <ArgumentNullException>(CNS == null, "CNS"); VRage.Exceptions.ThrowIf <ArgumentNullException>(gridDims == null, "gridDims"); this.CNS = CNS; this.wayDest = (Vector3D)CNS.getWayDest(); this.myGridDims = gridDims; this.ignoreAsteroids = CNS.ignoreAsteroids; myLogger = new Logger(gridDims.myGrid.DisplayName, "CollisionAvoidance"); // decide whether to use collision avoidance or slowdown switch (CNS.getTypeOfWayDest()) { case NavSettings.TypeOfWayDest.BLOCK: case NavSettings.TypeOfWayDest.GRID: // run slowdown. see Navigator.calcMoveAndRotate() this.destGrid = CNS.CurrentGridDest.Grid; break; case NavSettings.TypeOfWayDest.LAND: default: if (CNS.landingState != NavSettings.LANDING.OFF && CNS.CurrentGridDest != null) { this.destGrid = CNS.CurrentGridDest.Grid; } break; } log(myLogger, "created CollisionAvoidance", ".ctor()", Logger.severity.TRACE); currentStage = stage.S0_start; }
public void Init() { dims_4321_789 = new GridDimensions(4321, 789); grid_4321_789 = new Grid(dims_4321_789); grid_22_55555 = new Grid(22, 55555); iGrid_22_55555 = grid_22_55555; }
public Spheres(Vector3D end, GridDimensions gridDims, bool isAlternate) { myLogger = new Logger(gridDims.myGrid.DisplayName, "Spheres"); sphereNum = startAtSphere; this.radius = Math.Max(gridDims.width, gridDims.height) / 2; float projection = 0; if (isAlternate) { radius = radius * 3f + 10f; // alternate buffer projection = gridDims.length * 5; // alternate projection } else { radius = radius * 1.5f + 5f; // straight buffer } this.start = gridDims.myGrid.GetCentre(); Vector3 RCtoCentre = this.start - gridDims.getRCworld(); // in metres, world distance this.end = end + RCtoCentre; startToEnd = end - start; // set direction to start -> end. current length is (end-start).length() float distance_between = radius / 2; maxSphereNum = (int)Math.Ceiling((startToEnd.Length() + projection) / distance_between); startToEnd.Normalize(); // length is now 1 start += startToEnd * gridDims.distance_to_front_from_centre; // otherwise it is much harder to find an alt path startToEnd *= distance_between; // length is now distance_between log(myLogger, "maxSphereNum: " + maxSphereNum + ", distance_between=" + distance_between + ", projection=" + projection, "constructor", Logger.severity.TRACE); }
public void Test12_EqualsWithDiffObjSameValue() { GridDimensions dims_0_0 = new GridDimensions(); Assert.IsTrue(dims.Equals(dims_0_0)); Assert.IsTrue(dims_4321_789.Equals(new GridDimensions(4321, 789))); }
private Coordinate GetGridCoordinate(Coordinate coordinate, GridDimensions gridDimensions) { return(new Coordinate { X = (coordinate.X + gridDimensions.Height) % gridDimensions.Height, Y = (coordinate.Y + gridDimensions.Width) % gridDimensions.Width }); }
public void Init() { dims_4321_789 = new GridDimensions(4321, 789); grid_4321_789_dataType = typeof(float); grid_4321_789 = new GridWithType(dims_4321_789, grid_4321_789_dataType); grid_22_55555_dataType = typeof(Foo); grid_22_55555 = new GridWithType(22, 55555, grid_22_55555_dataType); }
public Collision(GridDimensions gridDim) { if (gridDim.myRC == null) { (new Logger("*missing*", "Collision")).log(Logger.severity.FATAL, "..ctor", "ArgumentNullException at Collision()"); } myLogger = new Logger(gridDim.myRC.CubeGrid.DisplayName, "Collision"); //myGrid = remoteControl.CubeGrid; //myRC = remoteControl; myGridDim = gridDim; }
/** * Convert grid index (GridX, GridY) to triangle coords and returns Vector3 */ public Vector3 GetPosFromIndex(int GridX, int GridY) { Vector2 CoordDim = new Vector2(GridDimensions.GetSize().X, GridDimensions.GetSize().Y); Vector2 EachGridSize = Vector2.Zero; EachGridSize.X = CoordDim.X / NumGridDivisions.X; EachGridSize.Y = CoordDim.Y / NumGridDivisions.Y; // for now only 2D return(new Vector3(GridX * EachGridSize.X + GridDimensions.Min.X, GridY * EachGridSize.Y + GridDimensions.Min.Y, 0.0f)); }
//--------------------------------------------------------------------- public override bool Equals(object obj) { //Check for null and compare run-time types. if (obj == null || GetType() != obj.GetType()) { return(false); } GridDimensions loc = (GridDimensions)obj; return(this == loc); }
public void Generate(GridDimensions gridDimensions) { Grid = new CellType[gridDimensions.Height, gridDimensions.Width]; for (var i = 0; i < gridDimensions.Height; i++) { for (var j = 0; j < gridDimensions.Width; j++) { Grid[i, j] = CellType.Dead; } } }
public void T_IsValid_False_SquareSizeY() { // Arrange GridDimensions gridDimensions = new GridDimensions( 9, 9, 3, 4 ); // Act bool isValid = gridDimensions.IsValid(); // Assert Assert.IsFalse(isValid); }
public void T_IsValid_True() { // Arrange GridDimensions gridDimensions = new GridDimensions( 9, 9, 3, 3 ); // Act bool isValid = gridDimensions.IsValid(); // Assert Assert.IsTrue(isValid); }
public void T_NumberOfSquaresOnColumn() { // Arrange GridDimensions gridDimensions = new GridDimensions( 12, 12, 3, 3 ); // Act int numberOfSquaresOnColumn = gridDimensions.NumberOfSquaresOnColumn(); // Assert Assert.AreEqual(numberOfSquaresOnColumn, 4); }
public void T_NumberOfSquaresOnLine() { // Arrange GridDimensions gridDimensions = new GridDimensions( 9, 9, 3, 3 ); // Act int numberOfSquaresOnLine = gridDimensions.NumberOfSquaresOnLine(); // Assert Assert.AreEqual(numberOfSquaresOnLine, 3); }
public void T_GridDimensions() { // Arrange // Act GridDimensions gridDimensions = new GridDimensions( 10, 20, 1, 2 ); // Assert Assert.AreEqual(gridDimensions.GridSizeX, 10, "Wrong GridSizeX."); Assert.AreEqual(gridDimensions.GridSizeY, 20, "Wrong GridSizeY."); Assert.AreEqual(gridDimensions.SquareSizeX, 1, "Wrong SquareSizeX"); Assert.AreEqual(gridDimensions.SquareSizeY, 2, "Wrong SquareSizeY."); }
public void Init() { dimensions = new GridDimensions(321, 89); grid = new DataGrid <int>(dimensions); grid_rowColCtor = new DataGrid <int>(dimensions.Rows, dimensions.Columns); data = new int[4, 7] { { 1, 2, 3, 4, 5, 6, 7 }, { 111, 222, 333, 444, 555, 666, 777 }, { -1, -2, -3, -4, -5, -6, -7 }, { 1, 4, 9, 16, 25, 36, 49 } }; dataDims = new GridDimensions((uint)data.GetLength(0), (uint)data.GetLength(1)); grid_dataCtor = new DataGrid <int>(data); }
public void Init() { data = new bool[7, 5] { { false, false, false, false, false }, { false, false, true, false, false }, { false, true, true, true, false }, { true, true, true, true, true }, { false, true, true, true, false }, { false, false, true, false, false }, { false, false, false, false, false } }; dimensions = new GridDimensions((uint)data.GetLength(0), (uint)data.GetLength(1)); dataGrid = new DataGrid <bool>(data); grid = new InputGrid <bool>(dataGrid); }
public List <Coordinate> GetCoordinates(Coordinate cellCoordinates, GridDimensions gridDimensions) { var neighboursCoordinates = new List <Coordinate> { }; var coordinatesToGenerate = new List <Coordinate> { new Coordinate { X = cellCoordinates.X - 1, Y = cellCoordinates.Y - 1 }, new Coordinate { X = cellCoordinates.X - 1, Y = cellCoordinates.Y }, new Coordinate { X = cellCoordinates.X - 1, Y = cellCoordinates.Y + 1 }, new Coordinate { X = cellCoordinates.X, Y = cellCoordinates.Y - 1 }, new Coordinate { X = cellCoordinates.X, Y = cellCoordinates.Y }, new Coordinate { X = cellCoordinates.X, Y = cellCoordinates.Y + 1 }, new Coordinate { X = cellCoordinates.X + 1, Y = cellCoordinates.Y - 1 }, new Coordinate { X = cellCoordinates.X + 1, Y = cellCoordinates.Y }, new Coordinate { X = cellCoordinates.X + 1, Y = cellCoordinates.Y + 1 } }; foreach (var coordinate in coordinatesToGenerate) { neighboursCoordinates.Add(GetGridCoordinate(coordinate, gridDimensions)); } return(neighboursCoordinates); }
public void Generate_And_Update_GameGrid_With_Specified_LiveCells_And_DeadCells() { var gridDimensions = new GridDimensions { Height = 6, Width = 6 }; _gameGrid.Generate(gridDimensions); var liveCellCoordinates = new List <Coordinate> { new Coordinate { X = 3, Y = 1 }, new Coordinate { X = 3, Y = 2 }, new Coordinate { X = 3, Y = 3 }, new Coordinate { X = 2, Y = 2 }, new Coordinate { X = 2, Y = 3 }, new Coordinate { X = 2, Y = 4 } }; _gameGrid.Update(liveCellCoordinates, CellType.Live); var deadCellCoordinates = new List <Coordinate> { new Coordinate { X = 3, Y = 2 }, new Coordinate { X = 3, Y = 3 }, new Coordinate { X = 2, Y = 2 }, new Coordinate { X = 2, Y = 3 } }; _gameGrid.Update(deadCellCoordinates, CellType.Dead); var expectedGrid = new[, ] { { CellType.Dead, CellType.Dead, CellType.Dead, CellType.Dead, CellType.Dead, CellType.Dead }, { CellType.Dead, CellType.Dead, CellType.Dead, CellType.Dead, CellType.Dead, CellType.Dead }, { CellType.Dead, CellType.Dead, CellType.Dead, CellType.Dead, CellType.Live, CellType.Dead }, { CellType.Dead, CellType.Live, CellType.Dead, CellType.Dead, CellType.Dead, CellType.Dead }, { CellType.Dead, CellType.Dead, CellType.Dead, CellType.Dead, CellType.Dead, CellType.Dead }, { CellType.Dead, CellType.Dead, CellType.Dead, CellType.Dead, CellType.Dead, CellType.Dead }, }; Assert.Equal(expectedGrid, _gameGrid.Grid); }
public CanFlyTo(Vector3D destination, Sandbox.ModAPI.IMyCubeGrid gridDest, GridDimensions gridDims, bool isAlternate, bool ignoreAsteroids) { this.myGrid = gridDims.myGrid; this.gridDest = gridDest; this.myAttached = AttachedGrids.getFor(gridDims.myGrid); this.ignoreAsteroids = ignoreAsteroids; myLogger = new Logger(gridDims.myGrid.DisplayName, "CanFlyTo"); collisionSpheres = new Spheres(destination, gridDims, isAlternate); log(myLogger, "got grid dest: " + this.gridDest, ".ctor()", Logger.severity.TRACE); }
public GridWithType(GridDimensions dimensions, System.Type dataType) : base(dimensions, dataType) { }
//--------------------------------------------------------------------- //!< Create a grid. protected GridWithType(GridDimensions dimensions, System.Type dataType) : base(dimensions) { this.dataType = dataType; }
public Grid(GridDimensions dimensions) : base(dimensions) { }
//--------------------------------------------------------------------- //!< Create a grid. protected Grid(uint rows, uint columns) { this.dimensions = new GridDimensions(rows, columns); this.count = rows * columns; }
//--------------------------------------------------------------------- //!< Create a grid. protected Grid(GridDimensions dimensions) { this.dimensions = dimensions; this.count = dimensions.Rows * dimensions.Columns; }
public void Init() { dims_4321_789 = new GridDimensions(4321, 789); }
//--------------------------------------------------------------------- //!< Create a grid. protected Grid(uint rows, uint columns) { this.dimensions = new GridDimensions(rows, columns); this.count = rows * columns; }
//--------------------------------------------------------------------- //!< Create a grid. protected GridWithType(GridDimensions dimensions, System.Type dataType) : base(dimensions) { this.dataType = dataType; }
//--------------------------------------------------------------------- //!< Create a grid. protected Grid(GridDimensions dimensions) { this.dimensions = dimensions; this.count = dimensions.Rows * dimensions.Columns; }