static void FillBlots(VectorMap map, Sphere target, out BoolMap fillMap, out int area, out Rectangle bounds, out Point origin) { fillMap = new BoolMap(map.Width, map.Height); origin = Point.Empty; area = 0; bounds = Rectangle.Empty; for (int y = 0; y < map.Height; y++) { for (int x = 0; x < map.Width; x++) { if (fillMap[x, y]) { continue; } var xy = new Point(x, y); int xyArea; Rectangle xyBounds; FloodFill(map, xy, target, fillMap, out xyArea, out xyBounds); if (xyArea > area) { area = xyArea; bounds = xyBounds; origin = xy; } } } }
public void TwoDArray() { Stack <int> siX = new Stack <int>(); Stack <int> siY = new Stack <int>(); int iX, iY; Random r = new Random(); BoolMap b = new BoolMap(100, 100); for (int i = 0; i < 1000; i++) { iX = r.Next(0, 100); iY = r.Next(0, 100); b[iX, iY] = true; Assert.IsTrue(b[iX, iY]); siX.Push(iX); siY.Push(iY); } while (siX.Count > 0) { iX = siX.Pop(); iY = siY.Pop(); //Assert.IsTrue(b[iX, iY]); b[iX, iY] = false; Assert.IsFalse(b[iX, iY]); } for (iX = 0; iX < 100; iX++) { for (iY = 0; iY < 100; iY++) { Assert.IsFalse(b[iX, iY]); } } }
public virtual bool IsSolid(BoolMap data, int x, int y, int z,bool customIsSolid) { if (IsCustom(x,y,z)) return customIsSolid; if (x < 0 || y < 0 || z < 0 || x >= data.Width || y >= data.Height || z >= data.Depth) { return false; } return data.Get(x,y,z); }
private void InitResources(string modelPath, string texturePath, string normalMapPath, string specularMapPath) { m_lightVisibilityMap = new BoolMap(); m_texture = PoolProxy.GetResource <ObtainTexturePool, TextureAllocationPolicy, string, ITexture>(texturePath); m_normalMap = PoolProxy.GetResource <ObtainTexturePool, TextureAllocationPolicy, string, ITexture>(normalMapPath); m_specularMap = PoolProxy.GetResource <ObtainTexturePool, TextureAllocationPolicy, string, ITexture>(specularMapPath); m_skin = PoolProxy.GetResource <ObtainModelPool, ModelAllocationPolicy, string, Skin>(modelPath); InitShader(); }
static void FloodFill(VectorMap map, Point origin, Sphere target, BoolMap fillMap, out int area, out Rectangle bounds) { var queue = new Queue <Point>(map.Width + map.Height); queue.Enqueue(origin); bounds = new Rectangle(int.MaxValue, int.MaxValue, 0, 0); area = 0; while (queue.Count > 0) { Point p = queue.Dequeue(); if (fillMap[p.X, p.Y] || !target.Contains(map[p])) { continue; } fillMap[p.X, p.Y] = true; if (bounds.X > p.X) { bounds.X = p.X; } if (bounds.Y > p.Y) { bounds.Y = p.Y; } if (bounds.Right <= p.X) { bounds.Width = p.X - bounds.X + 1; } if (bounds.Bottom <= p.Y) { bounds.Height = p.Y - bounds.Y + 1; } area++; if (p.X > 0) { queue.Enqueue(new Point(p.X - 1, p.Y)); } if (p.Y > 0) { queue.Enqueue(new Point(p.X, p.Y - 1)); } if (p.X < map.Width - 1) { queue.Enqueue(new Point(p.X + 1, p.Y)); } if (p.Y < map.Height - 1) { queue.Enqueue(new Point(p.X, p.Y + 1)); } } if (bounds.Size == Size.Empty) { bounds.Location = Point.Empty; } }
protected override void OnPaint(PaintEventArgs e) { if (loadedImage == null || !browseButton.Enabled) { return; } Rectangle clipRectangle = Rectangle.Intersect(e.ClipRectangle, imageRect); if (clipRectangle == Rectangle.Empty) { return; } if (!showChromaMap.Checked) { e.Graphics.DrawImage(loadedImage, imageRect); } else { using (Bitmap cm = chromaMap.ToBitmap()) e.Graphics.DrawImage(cm, imageRect); } var queue = new Queue <Point>(chromaMap.Width + chromaMap.Height); var fillMap = new BoolMap(chromaMap.Width, chromaMap.Height); queue.Enqueue(fillOrigin); while (queue.Count > 0) { Point p = queue.Dequeue(); if (fillMap[p.X, p.Y] || !boundingSphere.Contains(chromaMap[p])) { continue; } fillMap[p.X, p.Y] = true; Point q = new Point(imageRect.X + p.X, imageRect.Y + p.Y); e.Graphics.FillRectangle(Brushes.Blue, q.X, q.Y, 1, 1); if (p.X > 0) { queue.Enqueue(new Point(p.X - 1, p.Y)); } if (p.Y > 0) { queue.Enqueue(new Point(p.X, p.Y - 1)); } if (p.X < chromaMap.Width - 1) { queue.Enqueue(new Point(p.X + 1, p.Y)); } if (p.Y < chromaMap.Height - 1) { queue.Enqueue(new Point(p.X, p.Y + 1)); } } }
public override BoolMap GetBlockData() { Texture2D texture = GetMainTexture(); BoolMap data = new BoolMap(texture.width, texture.height, 1); for (int x = 0; x < (textureSize.x>0 ? textureSize.x : texture.width); x++) { for (int y = 0; y < (textureSize.y > 0 ? textureSize.y : texture.height); y++) { if (IsPixelSolid(x, y)) { data.Set(x, y, 0, true); } } } return data; }
private int[] generatePrimes(int iCount) { int lNum = 0, lRoot = 0, k = 0; int[] iaPrimes = new int[iCount]; bool bIsComposite = false; string elapsedTime; TimeSpan ts; Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); lNum = 2; iaPrimes[0] = 2; lNum = 1; for (int i = 1; i < iCount;) { lNum += 2; lRoot = (int)(Math.Sqrt(lNum)); k = 0; bIsComposite = false; while (iaPrimes[k] <= lRoot && !bIsComposite && iaPrimes[k] != 0) { if (lNum % iaPrimes[k] == 0) { bIsComposite = true; } k++; } if (bIsComposite == false) { iaPrimes[i] = lNum; i++; } } _bmIsPrime = new BoolMap(iaPrimes[iCount - 1]); for (int i = 0; i < iCount; i++) { _bmIsPrime[iaPrimes[i]] = true; } stopWatch.Stop(); ts = stopWatch.Elapsed; elapsedTime = String.Format("{0:00}h{1:00}m{2:00}.{3:00}s", ts.Hours, ts.Minutes, ts.Seconds, ts.Milliseconds / 10); System.Diagnostics.Debug.WriteLine("Eratosthenes: " + iCount + " primes up to " + iaPrimes[iCount - 1] + " generated in " + elapsedTime); return(iaPrimes); }
public void Mini() { BoolMap bm = new BoolMap(16); for (int i = 0; i < 16; i++) { Assert.IsFalse(bm.Get(i)); } for (int i = 0; i < 16; i++) { bm.Enable(i); Assert.IsTrue(bm.Get(i)); bm.Disable(i); for (int k = 0; k < 16; k++) { Assert.IsFalse(bm.Get(k)); } } }
public void MajorWithIndex() { BoolMap bm = new BoolMap(1000); for (int i = 0; i < 1000; i++) { Assert.IsFalse(bm[i]); } for (int i = 0; i < 1000; i++) { bm[i] = true; Assert.IsTrue(bm[i]); bm[i] = false; for (int k = 0; k < 1000; k++) { Assert.IsFalse(bm[k]); } } }
public override bool IsSolid(BoolMap data, int x, int y, int z, bool customIsSolid) { if (Chunk.IsTileValid(x, y, z)) { return base.IsSolid(data, x,y,z,customIsSolid); } byte id = World.Current.GetTileId(new Vector3((Chunk.GetX() * Chunk.CHUNK_WIDTH) + x, (Chunk.GetY() * Chunk.CHUNK_HEIGHT) + y,z)); Tile tile = TileManager.Current.GetTile(id); if (tile.specialMesh) { return customIsSolid; } return Chunk.IsTileSolid(id); }
public bool IsSolid(BoolMap data, int x, int y, int z) { return IsSolid(data,x,y,z,false); }
private int[] generatePrimes(int iLimit) { // For tracking performance // final long lTime = System.nanoTime(); _bmIsPrime = new BoolMap(iLimit + 1); int x; int y; int n; int i; int iCount = 0; int xSquared; int nSquared; int nMod12; int sqrtLimit = (int)Math.Sqrt(iLimit); int[] iaPrimes; string elapsedTime; TimeSpan ts; Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); switch (iLimit) { case 0: case 1: iaPrimes = null; break; case 2: iaPrimes = new int[1]; iaPrimes[0] = 2; break; case 3: iaPrimes = new int[2]; iaPrimes[0] = 2; iaPrimes[1] = 3; break; case 4: iaPrimes = new int[2]; iaPrimes[0] = 2; iaPrimes[1] = 3; break; case 5: iaPrimes = new int[3]; iaPrimes[0] = 2; iaPrimes[1] = 3; iaPrimes[2] = 5; break; default: for (x = 1; x <= sqrtLimit; x++) { xSquared = x * x; if (4 * xSquared + 1 <= iLimit) { for (y = 1; y <= sqrtLimit; y++) { n = 4 * xSquared + y * y; if (n <= iLimit) { nMod12 = n % 12; if (nMod12 == 1 || nMod12 == 5) { _bmIsPrime.Flip(n); } } else { y = sqrtLimit + 1; } } } else { break; } } for (x = 1; x <= sqrtLimit; x++) { xSquared = x * x; if (3 * xSquared + 1 <= iLimit) { for (y = 1; y <= sqrtLimit; y++) { n = 3 * xSquared + y * y; if (n <= iLimit) { if (n % 12 == 7) { _bmIsPrime.Flip(n); } } else { y = sqrtLimit + 1; } } } else { break; } } for (x = 1; x <= sqrtLimit; x++) { xSquared = x * x; if (2 * (xSquared - x) + 1 <= iLimit) { for (y = x - 1; y > 0; y--) { n = 3 * xSquared - y * y; if (n <= iLimit) { if (n % 12 == 11) { _bmIsPrime.Flip(n); } } else { y = 0; } } } else { break; } } for (n = 5; n < sqrtLimit; n += 2) { if (_bmIsPrime.Get(n)) { nSquared = n * n; for (i = nSquared; i < iLimit; i += nSquared) { _bmIsPrime.Disable(i); } } } iCount = 3; for (n = 7; n < _bmIsPrime.Length(); n += 2) { if (_bmIsPrime[n]) { iCount++; } } iaPrimes = new int[iCount]; iaPrimes[0] = 2; iaPrimes[1] = 3; _bmIsPrime[2] = true; _bmIsPrime[3] = true; i = 2; for (n = 5; n < _bmIsPrime.Length(); n += 2) { if (_bmIsPrime[n]) { iaPrimes[i] = n; i++; } } break; } stopWatch.Stop(); ts = stopWatch.Elapsed; elapsedTime = String.Format("{0:00}h{1:00}m{2:00}.{3:00}s", ts.Hours, ts.Minutes, ts.Seconds, ts.Milliseconds / 10); System.Diagnostics.Debug.WriteLine("Atkin: " + iaPrimes.Length + " primes up to " + iaPrimes[iaPrimes.Length - 1] + " generated in " + elapsedTime); return(iaPrimes); }