public List <Vector2> Generate(MyRectangle generationArea, float generationCount, float exclusionRadius, int maxTries, int maxPerGridCount, IIntensitySamplingProvider intensityProvider) { var random = new UnsafeRandomProvider(); //todo! var offsetGenerationArea = new MyRectangle(0, 0, generationArea.Width, generationArea.Height); float cellSize = exclusionRadius; var width = generationArea.Width; var height = generationArea.Height; var grid = new CountingGenerationGrid( cellSize, new IntVector2(Mathf.CeilToInt(width / cellSize), Mathf.CeilToInt(height / cellSize)) ); var processList = new GenerationRandomQueue <Vector2>(); var acceptedPoints = new List <Vector2>(1000); var firstPoint = new Vector2(random.Next(0, width), random.Next(0, height)); processList.Add(firstPoint); acceptedPoints.Add(firstPoint); grid.Increment(firstPoint); int tryCount = 0; while (!processList.Empty) { var point = processList.RandomPop(); for (int i = 0; i < generationCount; i++) { Vector2 newPoint = GenerateRandomPointAround(point, exclusionRadius, random); if (offsetGenerationArea.Contains(newPoint)) { var maxPointsInGrid = intensityProvider.Sample( RectangleUtils.CalculateSubelementUv(offsetGenerationArea, newPoint)) * maxPerGridCount; if (grid.Retrive(newPoint) < maxPointsInGrid) { processList.Add(newPoint); acceptedPoints.Add(newPoint); grid.Increment(newPoint); } } tryCount++; } if (tryCount > maxTries) { break; } } return(acceptedPoints.Select(c => c + generationArea.DownLeftPoint).ToList()); }
public override void Update() { if (MouseHovering) { HoverAlpha += 0.1f; } else { HoverAlpha -= 0.1f; } HoverAlpha = MathHelper.Clamp(HoverAlpha, 0, 1); if (!Changing) { if (MyRectangle.Contains(ParentWindow.MousePoint)) { MoveToRect = HoverRectangle; } else { MoveToRect = StartRectangle; } Changing = true; } Vector4 MoveVec2 = new Vector4(MoveToRect.X, MoveToRect.Y, MoveToRect.Width, MoveToRect.Height); Vector4 MyVec2 = new Vector4(PositionRectangle.X, PositionRectangle.Y, PositionRectangle.Width, PositionRectangle.Height); if (Vector4.Distance(MoveVec2, MyVec2) > 4) { Vector4 MoveAmount = MyVec2 + (MoveVec2 - MyVec2) * MoveSpeed; MoveAmount += Vector4.Normalize(MoveVec2 - MyVec2); PositionRectangle.X = (int)MoveAmount.X; PositionRectangle.Y = (int)MoveAmount.Y; PositionRectangle.Width = (int)MoveAmount.Z; PositionRectangle.Height = (int)MoveAmount.W; } else { PositionRectangle.X = MoveToRect.X; PositionRectangle.Y = MoveToRect.Y; PositionRectangle.Width = MoveToRect.Width; PositionRectangle.Height = MoveToRect.Height; Changing = false; } MyRectangle = new Rectangle(PositionRectangle.X - PositionRectangle.Width / 2, PositionRectangle.Y - PositionRectangle.Height / 2, PositionRectangle.Width, PositionRectangle.Height); ImageRectangle = new Rectangle(MyRectangle.X + Margin, MyRectangle.Y + Margin, MyRectangle.Width - Margin * 2, MyRectangle.Height - Margin * 2); base.Update(); }
public List <Vector2> Generate(MyRectangle generationArea, float generationCount, float exclusionRadius) { var random = new UnsafeRandomProvider(); //todo! var offsetGenerationArea = new MyRectangle(0, 0, generationArea.Width, generationArea.Height); float cellSize = exclusionRadius / Mathf.Sqrt(2); var width = generationArea.Width; var height = generationArea.Height; var grid = new SingleElementGenerationGrid( cellSize, Mathf.CeilToInt(width / cellSize), Mathf.CeilToInt(height / cellSize), exclusionRadius ); var processList = new GenerationRandomQueue <Vector2>(); var acceptedPoints = new List <Vector2>(1000); var firstPoint = new Vector2(random.Next(0, width), random.Next(0, height)); processList.Add(firstPoint); acceptedPoints.Add(firstPoint); grid.Set(firstPoint); while (!processList.Empty) { var point = processList.RandomPop(); for (int i = 0; i < generationCount; i++) { Vector2 newPoint = GenerateRandomPointAround(point, exclusionRadius, random); if (offsetGenerationArea.Contains(newPoint) && !grid.Collides(newPoint)) { processList.Add(newPoint); acceptedPoints.Add(newPoint); grid.Set(newPoint); } } } return(acceptedPoints.Select(c => c + generationArea.DownLeftPoint).ToList()); }
static void Main(string[] args) { //"{topLeftX} {topLeftY} {bottomRightX} {bottomRightY}". int[] coord = Console.ReadLine() .Split(" ", StringSplitOptions.RemoveEmptyEntries) .Select(int.Parse) .ToArray(); MyRectangle rect = new MyRectangle(coord[0], coord[1], coord[2], coord[3]); int n = int.Parse(Console.ReadLine()); for (int i = 0; i < n; i++) { int[] aPointCoord = Console.ReadLine() .Split(" ", StringSplitOptions.RemoveEmptyEntries) .Select(int.Parse) .ToArray(); Point myPoint = new Point(aPointCoord[0], aPointCoord[1]); rect.Contains(myPoint); } }
public List <Vector2> Generate(MyRectangle generationArea, float generationCount, MyRange exclusionRadiusRange, IIntensitySamplingProvider intensityProvider, int maxTries) { var random = new UnsafeRandomProvider(); //todo! var offsetGenerationArea = new MyRectangle(0, 0, generationArea.Width, generationArea.Height); float cellSize = exclusionRadiusRange.Max / Mathf.Sqrt(2); var width = generationArea.Width; var height = generationArea.Height; var grid = new GenerationMultipointGrid( cellSize, new IntVector2(Mathf.CeilToInt(width / cellSize), Mathf.CeilToInt(height / cellSize)) ); //if (usedCount++ % 2 == 0) //{ // return new List<Vector2>(); //} var processList = new GenerationRandomQueue <PointWithExclusionRadius>(); var acceptedPoints = new List <Vector2>(1000); PointWithExclusionRadius firstPoint = null; while (firstPoint == null) { maxTries--; if (maxTries < 0) { return(acceptedPoints); } var randX = random.Next(0, width); var randY = random.Next(0, height); var randomPoint = new Vector2(randY, randX); var exclusionRadius = CalculateExclusionRadius(randomPoint, offsetGenerationArea, exclusionRadiusRange, intensityProvider); if (!exclusionRadius.HasValue) { continue; } firstPoint = new PointWithExclusionRadius() { ExclusionRadius = exclusionRadius.Value, Point = randomPoint }; } ; processList.Add(firstPoint); acceptedPoints.Add(firstPoint.Point); grid.Set(firstPoint); while (!processList.Empty) { var point = processList.RandomPop(); for (int i = 0; i < generationCount; i++) { Vector2 newPoint = GenerateRandomPointAround(point.Point, point.ExclusionRadius, random); if (offsetGenerationArea.Contains(newPoint)) { var calculatedExclusionRadius = CalculateExclusionRadius(newPoint, offsetGenerationArea, exclusionRadiusRange, intensityProvider); if (!calculatedExclusionRadius.HasValue) { continue; } var newPointWithExclusionRadius = new PointWithExclusionRadius() { Point = newPoint, ExclusionRadius = calculatedExclusionRadius.Value }; if (!grid.Collides(newPointWithExclusionRadius)) { processList.Add(newPointWithExclusionRadius); acceptedPoints.Add(newPoint); grid.Set(newPointWithExclusionRadius); } } maxTries--; } if (maxTries < 0) { break; } } return(acceptedPoints.Select(c => c + generationArea.DownLeftPoint).ToList()); }
public List <Vector2> Generate(float generationCount, float exclusionRadius, int seed, List <Vector2> previousPoints = null) { if (previousPoints == null) { previousPoints = new List <Vector2>(); } var random = new UnsafeRandomProvider(seed); //todo! var offsetGenerationArea = new MyRectangle(0, 0, 1, 1); float cellSize = exclusionRadius / Mathf.Sqrt(2); var width = 1f; var height = 1f; var grid = new SingleElementGenerationGrid( cellSize, Mathf.CeilToInt(width / cellSize), Mathf.CeilToInt(height / cellSize), exclusionRadius ); var processList = new GenerationRandomQueue <Vector2>(); var acceptedPoints = new List <Vector2>(1000); var firstPoints = Enumerable.Range(0, 10).Select(c => new Vector2(random.Next(0, width), random.Next(0, height))).ToList(); foreach (var point in firstPoints) { processList.Add(point); acceptedPoints.Add(point); if (!grid.IsCellFilled(point)) { grid.Set(point); } } previousPoints.ForEach(c => { if (!grid.IsCellFilled(c)) { grid.Set(c); } }); while (!processList.Empty) { var point = processList.RandomPop(); for (int i = 0; i < generationCount; i++) { Vector2 newPoint = GenerateRandomPointAround(point, exclusionRadius, random); if (offsetGenerationArea.Contains(newPoint) && !grid.Collides(newPoint)) { processList.Add(newPoint); acceptedPoints.Add(newPoint); grid.Set(newPoint); } } } return(acceptedPoints); }