public void GetAlphamapFromOrientation_AndNextRightWeightAboveZero_IgnoresNextRightWeightIfNextRightNull() { var orientationData = new PointOrientationData() { IsOnGrid = true, NextRight = null, NextRightWeight = 3f }; var returnMap = new float[5]; var intermediateMap = new float[5]; MockCellAlphamapLogic.Setup( logic => logic.GetAlphamapForCell(intermediateMap, orientationData.NextRight) ).Callback <float[], IHexCell>((array, cell) => { array[0] = 1f; array[1] = 2f; array[2] = 3f; array[3] = 4f; array[4] = 5f; }); var alphamapLogic = Container.Resolve <TerrainAlphamapLogic>(); alphamapLogic.GetAlphamapFromOrientation(returnMap, intermediateMap, orientationData); CollectionAssert.AreEqual( new float[] { 0f, 0f, 0f, 0f, 0f }, returnMap ); }
public void GetTerrainHeightForPoint_AndLeftWeightGreaterThanZero_ReturnsLeftWeightTimesLeftHeight() { var point = new Vector2(1f, 2f); var left = BuildCell(); var orientationData = new PointOrientationData() { IsOnGrid = true, Left = left, LeftWeight = 12f, ElevationDuck = 5.5f }; var flatlandsNoise = new AsyncTextureUnsafe <Color32>(); var hillsNoise = new AsyncTextureUnsafe <Color32>(); MockCellHeightmapLogic.Setup( logic => logic.GetHeightForPointForCell(point, left, 5.5f, flatlandsNoise, hillsNoise) ).Returns(8f); var heightLogic = Container.Resolve <TerrainHeightLogic>(); Assert.AreEqual(96, heightLogic.GetHeightForPoint(point, orientationData, flatlandsNoise, hillsNoise)); }
public void GetOrientationDataFromColors_AndCenterNotNull_NeighborsAssignedFromSextant() { var center = BuildCell(); var left = BuildCell(); var right = BuildCell(); var nextRight = BuildCell(); var cells = new List <IHexCell>() { center, left, right, nextRight }; MockGrid.Setup(grid => grid.Cells).Returns(cells.AsReadOnly()); MockGrid.Setup(grid => grid.GetNeighbor(center, HexDirection.NE)).Returns(left); MockGrid.Setup(grid => grid.GetNeighbor(center, HexDirection.E)).Returns(right); MockGrid.Setup(grid => grid.GetNeighbor(center, HexDirection.SE)).Returns(nextRight); var orientationData = new PointOrientationData(); var indexBytes = new byte[2]; var orientationColor = new Color32(1, 0, 1, 0); var weightsColor = new Color(); var orientationLogic = Container.Resolve <PointOrientationLogic>(); orientationLogic.GetOrientationDataFromColors(orientationData, indexBytes, orientationColor, weightsColor, Color.clear); Assert.AreEqual(left, orientationData.Left, "Left has an unexpected value"); Assert.AreEqual(right, orientationData.Right, "Right has an unexpected value"); Assert.AreEqual(nextRight, orientationData.NextRight, "NextRight has an unexpected value"); }
public void GetAlphamapFromOrientation_AndNextRightWeightAboveZero_AppliesWeightToNextRightAlphamap() { var orientationData = new PointOrientationData() { IsOnGrid = true, NextRight = BuildCell(CellTerrain.Grassland), NextRightWeight = 3f }; var returnMap = new float[5]; var intermediateMap = new float[5]; MockCellAlphamapLogic.Setup( logic => logic.GetAlphamapForCell(intermediateMap, orientationData.NextRight) ).Callback <float[], IHexCell>((array, cell) => { array[0] = 1f; array[1] = 2f; array[2] = 3f; array[3] = 4f; array[4] = 5f; }); var alphamapLogic = Container.Resolve <TerrainAlphamapLogic>(); alphamapLogic.GetAlphamapFromOrientation(returnMap, intermediateMap, orientationData); CollectionAssert.AreEqual( new float[] { 3f, 6f, 9f, 12f, 15f }, returnMap ); }
public void GetOrientationDataFromColors_AndCenterNull_ReturnedDataIsClear() { var cells = new List <IHexCell>() { BuildCell() }; MockGrid.Setup(grid => grid.Cells).Returns(cells.AsReadOnly()); var orientationData = new PointOrientationData() { IsOnGrid = true, Center = BuildCell(), Left = BuildCell(), Right = BuildCell(), NextRight = BuildCell(), CenterWeight = 1f, LeftWeight = 1f, RightWeight = 1f, NextRightWeight = 1f, RiverWeight = 1f, ElevationDuck = 1f }; var indexBytes = new byte[2]; var orientationColor = new Color32(0, 0, 3, 0); var weightsColor = new Color(1f, 1f, 1f, 1f); var orientationLogic = Container.Resolve <PointOrientationLogic>(); orientationLogic.GetOrientationDataFromColors(orientationData, indexBytes, orientationColor, weightsColor, Color.clear); Assert.IsFalse(orientationData.IsOnGrid, "IsOnGrid has an unexpected value"); Assert.IsNull(orientationData.Center, "Center has an unexpected value"); Assert.IsNull(orientationData.Left, "Left has an unexpected value"); Assert.IsNull(orientationData.Right, "Right has an unexpected value"); Assert.IsNull(orientationData.NextRight, "NextRight has an unexpected value"); Assert.AreEqual(0f, orientationData.CenterWeight, "CenterWeight has an unexpected value"); Assert.AreEqual(0f, orientationData.LeftWeight, "LeftWeight has an unexpected value"); Assert.AreEqual(0f, orientationData.RightWeight, "RightWeight has an unexpected value"); Assert.AreEqual(0f, orientationData.NextRightWeight, "NextRightWeight has an unexpected value"); Assert.AreEqual(0f, orientationData.RiverWeight, "RiverWeight has an unexpected value"); Assert.AreEqual(0f, orientationData.ElevationDuck, "ElevationDuck has an unexpected value"); }
public void GetTerrainHeightForPoint_AndPointNotOnGrid_ReturnsZero() { var point = new Vector2(1f, 2f); var orientationData = new PointOrientationData() { IsOnGrid = false }; var flatlandsNoise = new AsyncTextureUnsafe <Color32>(); var hillsNoise = new AsyncTextureUnsafe <Color32>(); var heightLogic = Container.Resolve <TerrainHeightLogic>(); Assert.AreEqual(0f, heightLogic.GetHeightForPoint(point, orientationData, flatlandsNoise, hillsNoise)); }
public void GetAlphamapFromOrientation_NotOnGrid_ReturnsEmptyAlphamap() { var orientationData = new PointOrientationData() { IsOnGrid = false }; var returnMap = new float[5]; var intermediateMap = new float[5]; var alphamapLogic = Container.Resolve <TerrainAlphamapLogic>(); alphamapLogic.GetAlphamapFromOrientation(returnMap, intermediateMap, orientationData); CollectionAssert.AreEqual(new float[5], returnMap); }
public void GetAlphamapFromOrientation_AndMultipleWeightsAboveZero_SumsWeightsWithAlphamaps() { var orientationData = new PointOrientationData() { IsOnGrid = true, Center = BuildCell(CellTerrain.Grassland), CenterWeight = 2f, Left = BuildCell(CellTerrain.Grassland), LeftWeight = 3f, Right = BuildCell(CellTerrain.Grassland), RightWeight = 4f, NextRight = BuildCell(CellTerrain.Grassland), NextRightWeight = 5f }; var returnMap = new float[5]; var intermediateMap = new float[5]; MockCellAlphamapLogic.Setup( logic => logic.GetAlphamapForCell(intermediateMap, orientationData.Center) ).Callback <float[], IHexCell>((array, cell) => { array[0] = array[1] = array[2] = array[3] = 1f; }); MockCellAlphamapLogic.Setup( logic => logic.GetAlphamapForCell(intermediateMap, orientationData.Left) ).Callback <float[], IHexCell>((array, cell) => { array[0] = array[1] = array[2] = array[3] = 2f; }); MockCellAlphamapLogic.Setup( logic => logic.GetAlphamapForCell(intermediateMap, orientationData.Right) ).Callback <float[], IHexCell>((array, cell) => { array[0] = array[1] = array[2] = array[3] = 3f; }); MockCellAlphamapLogic.Setup( logic => logic.GetAlphamapForCell(intermediateMap, orientationData.NextRight) ).Callback <float[], IHexCell>((array, cell) => { array[0] = array[1] = array[2] = array[3] = 4f; }); var alphamapLogic = Container.Resolve <TerrainAlphamapLogic>(); alphamapLogic.GetAlphamapFromOrientation(returnMap, intermediateMap, orientationData); CollectionAssert.AreEqual(new float[] { 40f, 40f, 40f, 40f, 0f }, returnMap); }
public void GetTerrainHeightForPoint_AndRiverWeightGreaterThanZero_ReturnsRiverWeightTimesTroughElevation() { var point = new Vector2(1f, 2f); var orientationData = new PointOrientationData() { IsOnGrid = true, RiverWeight = 12f }; var flatlandsNoise = new AsyncTextureUnsafe <Color32>(); var hillsNoise = new AsyncTextureUnsafe <Color32>(); MockMapRenderConfig.Setup(config => config.RiverTroughElevation).Returns(8f); var heightLogic = Container.Resolve <TerrainHeightLogic>(); Assert.AreEqual(96, heightLogic.GetHeightForPoint(point, orientationData, flatlandsNoise, hillsNoise)); }
public void GetTerrainHeightForPoint_AndMultipleWeightsGreaterThanZero_SumsAllWeightContributions() { var point = new Vector2(1f, 2f); var center = BuildCell(); var left = BuildCell(); var right = BuildCell(); var nextRight = BuildCell(); var orientationData = new PointOrientationData() { IsOnGrid = true, Center = center, CenterWeight = 1f, Left = left, LeftWeight = 5f, Right = right, RightWeight = 1.5f, NextRight = nextRight, NextRightWeight = 0.6f, RiverWeight = 2f, ElevationDuck = 5.5f }; var flatlandsNoise = new AsyncTextureUnsafe <Color32>(); var hillsNoise = new AsyncTextureUnsafe <Color32>(); MockCellHeightmapLogic.Setup(logic => logic.GetHeightForPointForCell(point, center, 5.5f, flatlandsNoise, hillsNoise)).Returns(10f); MockCellHeightmapLogic.Setup(logic => logic.GetHeightForPointForCell(point, left, 5.5f, flatlandsNoise, hillsNoise)).Returns(11f); MockCellHeightmapLogic.Setup(logic => logic.GetHeightForPointForCell(point, right, 5.5f, flatlandsNoise, hillsNoise)).Returns(12f); MockCellHeightmapLogic.Setup(logic => logic.GetHeightForPointForCell(point, nextRight, 5.5f, flatlandsNoise, hillsNoise)).Returns(13f); MockMapRenderConfig.Setup(config => config.RiverTroughElevation).Returns(6.2f); var heightLogic = Container.Resolve <TerrainHeightLogic>(); float expectedValue = 10f + 55f + 1.5f * 12f + 0.6f * 13f + 2f * 6.2f; float pointHeight = heightLogic.GetHeightForPoint(point, orientationData, flatlandsNoise, hillsNoise); Assert.IsTrue( Mathf.Approximately(expectedValue, pointHeight), string.Format( "Resulting height not approximately equal to expected results (Expected {0}, got {1})", expectedValue, pointHeight ) ); }
public void GetOrientationDataFromColors_PullsCenterFromOrientationRG_MinusOne_AndCastAsAnIndex() { var cells = new List <IHexCell>() { BuildCell(), BuildCell(), BuildCell(), BuildCell() }; MockGrid.Setup(grid => grid.Cells).Returns(cells.AsReadOnly()); var orientationData = new PointOrientationData(); var indexBytes = new byte[2]; var orientationColor = new Color32(3, 0, 0, 0); var weightsColor = new Color(); var orientationLogic = Container.Resolve <PointOrientationLogic>(); orientationLogic.GetOrientationDataFromColors(orientationData, indexBytes, orientationColor, weightsColor, Color.clear); Assert.AreEqual(cells[2], orientationData.Center); }
public void GetOrientationDataFromColors_AndCenterNotNull_RiverWeightCeilingsAtOne() { var cells = new List <IHexCell>() { BuildCell() }; MockGrid.Setup(grid => grid.Cells).Returns(cells.AsReadOnly()); var orientationData = new PointOrientationData(); var indexBytes = new byte[2]; var orientationColor = new Color32(1, 0, 3, 0); var weightsColor = new Color(-1f, -1f, -1f, -1f); var orientationLogic = Container.Resolve <PointOrientationLogic>(); orientationLogic.GetOrientationDataFromColors(orientationData, indexBytes, orientationColor, weightsColor, Color.clear); Assert.AreEqual(1f, orientationData.RiverWeight); }
public void GetOrientationDataFromColors_AndCenterNotNull_RiverWeightOneMinusOtherWeights() { var cells = new List <IHexCell>() { BuildCell() }; MockGrid.Setup(grid => grid.Cells).Returns(cells.AsReadOnly()); var orientationData = new PointOrientationData(); var indexBytes = new byte[2]; var orientationColor = new Color32(1, 0, 3, 0); var weightsColor = new Color(0.1f, 0.15f, 0.2f, 0.25f); var orientationLogic = Container.Resolve <PointOrientationLogic>(); orientationLogic.GetOrientationDataFromColors(orientationData, indexBytes, orientationColor, weightsColor, Color.clear); Assert.That(Mathf.Approximately(1f - 0.1f - 0.15f - 0.2f - 0.25f, orientationData.RiverWeight)); }
public void GetOrientationDataFromColors_AndCenterNotNull_NextRightWeightPulledFromSampledA_OfWeightsTexture() { var cells = new List <IHexCell>() { BuildCell() }; MockGrid.Setup(grid => grid.Cells).Returns(cells.AsReadOnly()); var orientationData = new PointOrientationData(); var indexBytes = new byte[2]; var orientationColor = new Color32(1, 0, 3, 0); var weightsColor = new Color(0.45f, 0.55f, 0.65f, 0.75f); var orientationLogic = Container.Resolve <PointOrientationLogic>(); orientationLogic.GetOrientationDataFromColors(orientationData, indexBytes, orientationColor, weightsColor, Color.clear); Assert.AreEqual(weightsColor.a, orientationData.NextRightWeight); }
public void GetOrientationDataFromColors_AndRGIndexGreaterThanCellCount_CenterSetToNull() { var cells = new List <IHexCell>() { BuildCell(), BuildCell(), BuildCell(), BuildCell() }; MockGrid.Setup(grid => grid.Cells).Returns(cells.AsReadOnly()); var orientationData = new PointOrientationData(); var indexBytes = new byte[2]; var orientationColor = new Color32(10, 0, 0, 0); var weightsColor = new Color(); var orientationLogic = Container.Resolve <PointOrientationLogic>(); orientationLogic.GetOrientationDataFromColors(orientationData, indexBytes, orientationColor, weightsColor, Color.clear); Assert.IsNull(orientationData.Center); }
public void GetOrientationDataFromColors_TakesDuckFromDuckColorR() { var cells = new List <IHexCell>() { BuildCell(), BuildCell(), BuildCell(), BuildCell() }; MockGrid.Setup(grid => grid.Cells).Returns(cells.AsReadOnly()); var orientationData = new PointOrientationData(); var indexBytes = new byte[2]; var orientationColor = new Color32(3, 0, 0, 0); var weightsColor = new Color(); var duckColor = new Color(0.5f, 0.6f, 0.7f, 0.8f); var orientationLogic = Container.Resolve <PointOrientationLogic>(); orientationLogic.GetOrientationDataFromColors(orientationData, indexBytes, orientationColor, weightsColor, duckColor); Assert.AreEqual(0.5f, orientationData.ElevationDuck); }
public void GetTerrainHeightForPoint_AndNextRightNull_IgnoresNextRightContribution() { var point = new Vector2(1f, 2f); var orientationData = new PointOrientationData() { IsOnGrid = true, NextRight = null, NextRightWeight = 12f, ElevationDuck = 5.5f }; var flatlandsNoise = new AsyncTextureUnsafe <Color32>(); var hillsNoise = new AsyncTextureUnsafe <Color32>(); MockCellHeightmapLogic.Setup( logic => logic.GetHeightForPointForCell(point, It.IsAny <IHexCell>(), 5.5f, flatlandsNoise, hillsNoise) ).Returns(8f); var heightLogic = Container.Resolve <TerrainHeightLogic>(); Assert.AreEqual(0, heightLogic.GetHeightForPoint(point, orientationData, flatlandsNoise, hillsNoise)); }
public void GetAlphamapFromOrientation_RiverWeightAboveZero_AndNotFloodPlains_AppliesAlphamapWithWeight() { var orientationData = new PointOrientationData() { IsOnGrid = true, Center = BuildCell(CellTerrain.Grassland), RiverWeight = 0.5f }; var returnMap = new float[5]; var intermediateMap = new float[5]; var alphamap = new float[] { 1f, 2f, 3f, 4f, 5f }; MockRenderConfig.Setup(config => config.RiverAlphamap).Returns(alphamap); var alphamapLogic = Container.Resolve <TerrainAlphamapLogic>(); alphamapLogic.GetAlphamapFromOrientation(returnMap, intermediateMap, orientationData); CollectionAssert.AreEqual( new float[] { 0.5f, 1f, 3f * 0.5f, 2f, 5f * 0.5f }, returnMap ); }