HexGrid::SetBounds by default uses AxialCoords which fixes all tests.
parent
10afa67d85
commit
3b73480845
12
HexGrid.cs
12
HexGrid.cs
|
@ -19,7 +19,7 @@ public class HexGrid : Resource
|
|||
private Godot.Transform2D _hexTransformInv;
|
||||
private HexCell _minCoords = new HexCell();
|
||||
private HexCell _maxCoords = new HexCell();
|
||||
private Rect2 _bounds = new Rect2();
|
||||
private Rect2 _boundsAxialCoords = new Rect2();
|
||||
|
||||
public System.Collections.Generic.Dictionary<Vector2, float> Obstacles = new System.Collections.Generic.Dictionary<Vector2, float>();
|
||||
|
||||
|
@ -82,6 +82,11 @@ public class HexGrid : Resource
|
|||
return result;
|
||||
}
|
||||
|
||||
public void SetBoundsOffset(Vector2 minOffset, Vector2 maxOffset)
|
||||
{
|
||||
SetBounds (HexCell.FromOffsetCoords(minOffset), HexCell.FromOffsetCoords(maxOffset));
|
||||
}
|
||||
|
||||
public void SetBounds(Vector2 minAxial, Vector2 maxAxial)
|
||||
{
|
||||
SetBounds(new HexCell(minAxial), new HexCell(maxAxial));
|
||||
|
@ -91,7 +96,7 @@ public class HexGrid : Resource
|
|||
{
|
||||
_minCoords = minCell;
|
||||
_maxCoords = maxCell;
|
||||
_bounds = new Rect2(_minCoords.OffsetCoords, (_maxCoords.OffsetCoords - _minCoords.OffsetCoords) + Vector2.One);
|
||||
_boundsAxialCoords = new Rect2(_minCoords.AxialCoords, (_maxCoords.AxialCoords - _minCoords.AxialCoords) + Vector2.One);
|
||||
}
|
||||
|
||||
public void AddObstacle(Vector2 axialCoords, float cost = 0)
|
||||
|
@ -144,8 +149,7 @@ public class HexGrid : Resource
|
|||
|
||||
public float GetHexCost(Vector2 axialCoords)
|
||||
{
|
||||
HexCell cell = new HexCell(axialCoords);
|
||||
if (!_bounds.HasPoint(cell.OffsetCoords))
|
||||
if (!_boundsAxialCoords.HasPoint(axialCoords))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@ using Godot;
|
|||
using GoDotTest;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using Xunit;
|
||||
|
||||
public class HexCellTests : TestClass
|
||||
{
|
||||
|
@ -17,6 +18,20 @@ public class HexCellTests : TestClass
|
|||
Debug.Assert(cell.CubeCoords == new Vector3(0, 0, 0));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestHexCellEqualityInequality()
|
||||
{
|
||||
HexCell cellA = new HexCell();
|
||||
HexCell cellB = new HexCell();
|
||||
|
||||
cellA.AxialCoords = new Vector2(2, 3);
|
||||
cellB.AxialCoords = new Vector2(2, 3);
|
||||
Assert.Equal(cellA, cellB);
|
||||
|
||||
cellB.AxialCoords = new Vector2(3, 2);
|
||||
Assert.NotEqual(cellA, cellB);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestAxialCoords()
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue