public void Resizing_and_moving_sets_the_centre_point() { // Given CreateMockFactory(); _mockUniqueFractalPolygon.Setup(m => m.SetOutlineWidth(It.IsAny <double>())); // centred square _mockUniqueFractalPolygonPoints.Add(new System.Windows.Point(-1, 1)); _mockUniqueFractalPolygonPoints.Add(new System.Windows.Point(1, 1)); _mockUniqueFractalPolygonPoints.Add(new System.Windows.Point(1, -1)); _mockUniqueFractalPolygonPoints.Add(new System.Windows.Point(-1, -1)); Color unused = Color.FromRgb(1, 2, 3); var islandShape = new IslandShape(unused); // When var islandSize = 5.0; // arbitrary var islandLocation = new System.Windows.Point(-10, -10); // arbitrary islandShape.ResizeAndMove(islandSize, islandLocation); // Then var expectedCentrePoint = islandLocation; var actualCentrePoint = islandShape.CentrePoint; Assert.AreEqual(expectedCentrePoint, actualCentrePoint); }
public void Resizing_and_moving_sets_the_height_and_width() { // Given CreateMockFactory(); _mockUniqueFractalPolygon.Setup(m => m.SetOutlineWidth(It.IsAny <double>())); // centred square _mockUniqueFractalPolygonPoints.Add(new System.Windows.Point(-1, 1)); _mockUniqueFractalPolygonPoints.Add(new System.Windows.Point(1, 1)); _mockUniqueFractalPolygonPoints.Add(new System.Windows.Point(1, -1)); _mockUniqueFractalPolygonPoints.Add(new System.Windows.Point(-1, -1)); Color unused = Color.FromRgb(1, 2, 3); var islandShape = new IslandShape(unused); // When var islandSize = 1.0; // no resize var islandLocation = new System.Windows.Point(-10, -10); // arbitrary islandShape.ResizeAndMove(islandSize, islandLocation); // Then var expectedWidthAndHeight = new System.Windows.Point(2, 2); var actualWidth = islandShape.Width; Assert.AreEqual(expectedWidthAndHeight.X, actualWidth); var actualHeight = islandShape.Height; Assert.AreEqual(expectedWidthAndHeight.Y, actualHeight); }
public void Moving_for_the_first_time_in_a_positive_location_relocates_the_shape() { // Given CreateMockFactory(); _mockUniqueFractalPolygon.Setup(m => m.SetOutlineWidth(It.IsAny <double>())); // centred square _mockUniqueFractalPolygonPoints.Add(new System.Windows.Point(-1, 1)); _mockUniqueFractalPolygonPoints.Add(new System.Windows.Point(1, 1)); _mockUniqueFractalPolygonPoints.Add(new System.Windows.Point(1, -1)); _mockUniqueFractalPolygonPoints.Add(new System.Windows.Point(-1, -1)); Color unused = Color.FromRgb(1, 2, 3); var islandShape = new IslandShape(unused); // When var pointsBeforeResizeAndMove = new PointCollection(_mockPolygonPoints); var islandSize = 1.0; // no resizing var islandLocation = new System.Windows.Point(10, 10); // not origin islandShape.ResizeAndMove(islandSize, islandLocation); // Then var expectedCentrePoint = islandLocation; var actualCentrePoint = TestHelper_GetCentrePoint(_mockPolygonPoints); Assert.AreEqual(expectedCentrePoint, actualCentrePoint); }
/// <summary> /// /// </summary> /// <param name="source"></param> /// <param name="shoreLength">the distance from the start of the beach to the water</param> /// <param name="waterLevel"></param> /// <param name="shoreHeight">the height as measured from the water level</param> /// <param name="type"></param> /// <param name="method"></param> public HeightMapIslandTrim(IHeightMap source, float shoreLength, float waterLevel, float shoreHeight, IslandShape type, IslandTrimMethod method) { mSource = source; mWaterLevel = waterLevel; mShoreHeight = shoreHeight; mShoreLength = shoreLength; mType = type; mMethod = method; }
public Graph(int _width, int _height, NoiseSettings _settings, float _poissonRadius) { width = _width; height = _height; settings = _settings; poissonRadius = _poissonRadius; IslandShape.SetupIslandShape(_width, _height, _settings); inside = IslandShape.makePerlin(); //GenerateHeightMap(_settings); }
public override void Generate(Map map, GenStepParams parms) { Log.Message("[Biomes! Core] Generating an island"); // if the island didn't specify any shapes, all shapes are valid. List <IslandShape> allowedShapes = map.Biome.GetModExtension <BiomesMap>().islandShapes; if (allowedShapes.NullOrEmpty()) { allowedShapes = new List <IslandShape>(); foreach (IslandShape s in Enum.GetValues(typeof(IslandShape))) { allowedShapes.Add(s); } } //pick and run a random allowable shape IslandShape shape = allowedShapes.RandomElement(); switch (shape) { case IslandShape.Smooth: new GenStep_IslandShape_Smooth().Generate(map, parms); break; case IslandShape.Rough: new GenStep_IslandShape_Rough().Generate(map, parms); break; case IslandShape.Crescent: new GenStep_IslandShape_Crescent().Generate(map, parms); break; case IslandShape.Pair: new GenStep_IslandShape_Pair().Generate(map, parms); break; case IslandShape.Cluster: new GenStep_IslandShape_Cluster().Generate(map, parms); break; case IslandShape.Broken: new GenStep_IslandShape_Broken().Generate(map, parms); break; // rough islands are probably the best default island shape default: new GenStep_IslandShape_Rough().Generate(map, parms); break; } }
public void Resizing_and_moving_for_the_first_time_in_a_negative_location_relocates_the_shape_by_the_given_size() { // Given CreateMockFactory(); _mockUniqueFractalPolygon.Setup(m => m.SetOutlineWidth(It.IsAny <double>())); // centred square _mockUniqueFractalPolygonPoints.Add(new System.Windows.Point(-1, 1)); _mockUniqueFractalPolygonPoints.Add(new System.Windows.Point(1, 1)); _mockUniqueFractalPolygonPoints.Add(new System.Windows.Point(1, -1)); _mockUniqueFractalPolygonPoints.Add(new System.Windows.Point(-1, -1)); Color unused = Color.FromRgb(1, 2, 3); var islandShape = new IslandShape(unused); // When var widthBeforeResizeAndMove = 2; var heightBeforeResizeAndMove = 2; var pointsBeforeResizeAndMove = new PointCollection(_mockPolygonPoints); var islandSize = 5.0; var islandLocation = new System.Windows.Point(-10, -10); // not origin islandShape.ResizeAndMove(islandSize, islandLocation); // Then var expectedCentrePoint = islandLocation; var actualCentrePoint = TestHelper_GetCentrePoint(_mockPolygonPoints); Assert.AreEqual(expectedCentrePoint, actualCentrePoint); var expectedWidth = widthBeforeResizeAndMove * islandSize; var actualWidth = TestHelper_GetWidthAndHeight(_mockPolygonPoints).X; Assert.AreEqual(expectedWidth, actualWidth); var expectedHeight = heightBeforeResizeAndMove * islandSize; var actualHeight = TestHelper_GetWidthAndHeight(_mockPolygonPoints).Y; Assert.AreEqual(expectedHeight, actualHeight); var expectedPoints = pointsBeforeResizeAndMove; var actualPoints = _mockPolygonPoints; Assert.AreNotEqual(expectedPoints, actualPoints); }
public void NewIsland(string type, int seed, int variant) { _mapRandom = new Random(variant); _islandShape = IslandShapes.Get(type, seed); }
public void NewIsland(string type, int seed, int variant) { _mapRandom = new Random(variant); _islandShape = IslandShapes.Get(type, seed); }
/// <summary> /// /// </summary> /// <param name="source"></param> /// <param name="shoreLength">the distance from the start of the beach to the water</param> /// <param name="waterLevel"></param> /// <param name="shoreHeight">the height as measured from the water level</param> /// <param name="type"></param> /// <param name="method"></param> public HeightMapIslandTrim( IHeightMap source, float shoreLength, float waterLevel, float shoreHeight, IslandShape type, IslandTrimMethod method ) { mSource = source; mWaterLevel = waterLevel; mShoreHeight = shoreHeight; mShoreLength = shoreLength; mType = type; mMethod = method; }
// Determine elevations and water at Voronoi corners. By // construction, we have no local minima. This is important for // the downslope vectors later, which are used in the river // construction algorithm. Also by construction, inlets/bays // push low elevation areas inland, which means many rivers end // up flowing out through them. Also by construction, lakes // often end up on river paths because they don't raise the // elevation as much as other terrain does. public static void AssignCorner(ref Map map, IslandShape islandShape, bool needsMoreRandomness) { System.Random mapRandom = new System.Random(map.seed); Queue <Graph.Corner> queue = new Queue <Graph.Corner>(); foreach (var q in map.corners) { q.water = !islandShape.IsInside(q.pos); } foreach (var q in map.corners) { // The edges of the map are elevation 0 if (q.border) { q.elevation = 0.0f; queue.Enqueue(q); } else { q.elevation = Mathf.Infinity; } } // Traverse the graph and assign elevations to each point. As we // move away from the map border, increase the elevations. This // guarantees that rivers always have a way down to the coast by // going downhill (no local minima). while (queue.Count > 0) { var q = queue.Dequeue(); foreach (var s in q.adjacent) { // Every step up is epsilon over water or 1 over land. The // number doesn't matter because we'll rescale the // elevations later. var newElevation = 0.01f + q.elevation; if (!q.water && !s.water) { newElevation += 1; if (needsMoreRandomness) { // HACK: the map looks nice because of randomness of // points, randomness of rivers, and randomness of // edges. Without random point selection, I needed to // inject some more randomness to make maps look // nicer. I'm doing it here, with elevations, but I // think there must be a better way. This hack is only // used with square/hexagon grids. newElevation += (float)mapRandom.NextDouble(); } } // If this point changed, we'll add it to the queue so // that we can process its neighbors too. if (newElevation < s.elevation) { s.elevation = newElevation; queue.Enqueue(s); } } } }
public Map Generate(Vector2 dimensions, int seed, PointSelector.FaceType faceType, IslandShape.FunctionType functionType, float height, AnimationCurve heightMap, int regionCount, int relaxationCount, float radius) { data = new Map(); data.seed = seed; this.height = height; this.heigtMap = heightMap; islandShape = new IslandShape(seed, dimensions.x, dimensions.y, functionType); rectangle = new Rectangle(0, 0, dimensions.x, dimensions.y); if (faceType == PointSelector.FaceType.Hexagon || faceType == PointSelector.FaceType.Square) { relaxationCount = 0; } Polygon polygon = PointSelector.Generate(dimensions, seed, faceType, regionCount, radius); VoronoiBase voronoi = GenerateVoronoi(ref polygon, relaxationCount); Build(polygon, voronoi); ImproveCorners(); // Determine the elevations and water at Voronoi corners. Elevation.AssignCorner(ref data, islandShape, faceType == PointSelector.FaceType.Hexagon || faceType == PointSelector.FaceType.Square); // Determine polygon and corner type: ocean, coast, land. Biomes.AssignOceanCoastAndLand(ref data); // Rescale elevations so that the highest is 1.0, and they're // distributed well. We want lower elevations to be more common // than higher elevations, in proportions approximately matching // concentric rings. That is, the lowest elevation is the // largest ring around the island, and therefore should more // land area than the highest elevation, which is the very // center of a perfectly circular island. List <Graph.Corner> corners = LandCorners(data.corners); Elevation.Redistribute(ref corners); // Assign elevations to non-land corners foreach (var q in data.corners) { if (q.ocean || q.coast) { q.elevation = 0.0f; } } // Polygon elevations are the average of their corners Elevation.AssignPolygon(ref data); // Determine moisture at corners, starting at rivers // and lakes, but not oceans. Then redistribute // moisture to cover the entire range evenly from 0.0 // to 1.0. Then assign polygon moisture as the average // of the corner moisture. Moisture.AssignCorner(ref data); Moisture.Redistribute(ref corners); Moisture.AssignPolygon(ref data); Biomes.AssignBiomes(ref data); return(data); }