private void GenPoints(Image <Rgba32> buffer) { var o = PointSize - 1; var random = new Random(Seed); for (var i = 0; i < PointCount; i++) { var relX = random.NextDouble(); var relY = random.NextDouble(); var x = (int)(relX * buffer.Width); var y = (int)(relY * buffer.Height); var dist = random.NextDouble(); for (var ox = x - o; ox <= x + o; ox++) { for (var oy = y - o; oy <= y + o; oy++) { var color = Color.InterpolateBetween(FarColor, CloseColor, (float)dist).ConvertImgSharp(); buffer[MathHelper.Mod(ox, buffer.Width), MathHelper.Mod(oy, buffer.Width)] = color; } } } }
public IEnumerable <IShuffleAction> MergeWithBelow(IShuffleAction below, BigInteger deckSize) { if (below is DealIntoNewStack) { return new List <IShuffleAction> { below.Copy(), new Cut(MathHelper.Mod(-CutFrom, deckSize)) } } ; if (below is Cut cut) { return new List <IShuffleAction> { new Cut(MathHelper.Mod(CutFrom + cut.CutFrom, deckSize)) } } ; if (below is DealWithIncrement dwi) { return new List <IShuffleAction> { below.Copy(), new Cut(MathHelper.Mod(dwi.Increment * CutFrom, deckSize)) } } ; throw new NotImplementedException(); }
private void GenPoints(Image <Rgba32> buffer) { var o = PointSize - 1; var random = new Random(Seed); var span = buffer.GetPixelSpan(); for (var i = 0; i < PointCount; i++) { var x = random.Next(0, buffer.Width); var y = random.Next(0, buffer.Height); var dist = random.NextFloat(); for (var oy = y - o; oy <= y + o; oy++) { for (var ox = x - o; ox <= x + o; ox++) { var ix = MathHelper.Mod(ox, buffer.Width); var iy = MathHelper.Mod(oy, buffer.Height); var color = Color.InterpolateBetween(FarColor, CloseColor, dist).ConvertImgSharp(); span[iy * buffer.Width + ix] = color; } } } }
protected internal override void Draw(DrawingHandleScreen handle) { base.Draw(handle); for (var i = 0; i < TrackedFrames; i++) { var currentFrameIndex = MathHelper.Mod(_frameIndex - 1 - i, TrackedFrames); var frameTime = _frameTimes[currentFrameIndex]; var x = FrameWidth * UserInterfaceManager.UIScale * (TrackedFrames - 1 - i); var frameHeight = FrameHeight * (frameTime / (1f / TargetFrameRate)); var rect = new UIBox2(x, PixelHeight - frameHeight, x + FrameWidth * UserInterfaceManager.UIScale, PixelHeight); Color color; if (frameTime > 1f / (TargetFrameRate / 2 - 1)) { color = Color.Red; } else if (frameTime > 1f / (TargetFrameRate - 1)) { color = Color.Yellow; } else { color = Color.Lime; } handle.DrawRect(rect, color); } }
private void AddMoisture(Tile _tile, int _radius) { int startx = MathHelper.Mod(_tile.X - _radius, Width); int endx = MathHelper.Mod(_tile.X + _radius, Width); Vector2 center = new Vector2(_tile.X, _tile.Y); int curr = _radius; while (curr > 0) { int x1 = MathHelper.Mod(_tile.X - curr, Width); int x2 = MathHelper.Mod(_tile.X + curr, Width); int y = _tile.Y; AddMoisture(Tiles[x1, y], 0.025f / (center - new Vector2(x1, y)).magnitude); for (int i = 0; i < curr; i++) { AddMoisture(Tiles[x1, MathHelper.Mod(y + i + 1, Height)], 0.025f / (center - new Vector2(x1, MathHelper.Mod(y + i + 1, Height))).magnitude); AddMoisture(Tiles[x1, MathHelper.Mod(y - (i + 1), Height)], 0.025f / (center - new Vector2(x1, MathHelper.Mod(y - (i + 1), Height))).magnitude); AddMoisture(Tiles[x2, MathHelper.Mod(y + i + 1, Height)], 0.025f / (center - new Vector2(x2, MathHelper.Mod(y + i + 1, Height))).magnitude); AddMoisture(Tiles[x2, MathHelper.Mod(y - (i + 1), Height)], 0.025f / (center - new Vector2(x2, MathHelper.Mod(y - (i + 1), Height))).magnitude); } curr--; } }
private void AddMoisture(Tile t, int radius) { int startx = MathHelper.Mod(t.X - radius, Width); int endx = MathHelper.Mod(t.X + radius, Width); Vector2 center = new Vector2(t.X, t.Y); int curr = radius; while (curr > 0) { int x1 = MathHelper.Mod(t.X - curr, Width); int x2 = MathHelper.Mod(t.X + curr, Width); int y = t.Y; AddMoisture(Tiles[x1, y], 0.025f / (center - new Vector2(x1, y)).Length()); for (int i = 0; i < curr; i++) { AddMoisture(Tiles[x1, MathHelper.Mod(y + i + 1, Height)], 0.025f / (center - new Vector2(x1, MathHelper.Mod(y + i + 1, Height))).Length()); AddMoisture(Tiles[x1, MathHelper.Mod(y - (i + 1), Height)], 0.025f / (center - new Vector2(x1, MathHelper.Mod(y - (i + 1), Height))).Length()); AddMoisture(Tiles[x2, MathHelper.Mod(y + i + 1, Height)], 0.025f / (center - new Vector2(x2, MathHelper.Mod(y + i + 1, Height))).Length()); AddMoisture(Tiles[x2, MathHelper.Mod(y - (i + 1), Height)], 0.025f / (center - new Vector2(x2, MathHelper.Mod(y - (i + 1), Height))).Length()); } curr--; } }
public override void OnKeyUp(object sender, KeyboardKeyEventArgs e) { base.OnKeyUp(sender, e); if (!Enabled) { return; } if (e.Key == Key.P) { SelectedLayer += 1; SelectedPackedLayer += 1; } else if (e.Key == Key.O) { SelectedLayer -= 1; SelectedPackedLayer -= 1; } else if (e.Key == Key.U) { SelectedLayer = 0; SelectedPackedLayer = 0; } else if (e.Key == Key.Tab) { selectedLayerType = (LayerType)MathHelper.Mod(((int)selectedLayerType + 1), Enum.GetValues(typeof(LayerType)).Length); } }
public bool Contains(Vector2i index) { var x = MathHelper.Mod(index.X, ChunkSize); var y = MathHelper.Mod(index.Y, ChunkSize); return((_tiles[x] & (1 << y)) != 0); }
private void GenPointsMasked(Image <Rgba32> buffer) { var o = PointSize - 1; var random = new Random(Seed); var noise = new NoiseGenerator(MaskNoiseType); noise.SetSeed(MaskSeed); noise.SetFrequency(MaskFrequency); noise.SetPersistence(MaskPersistence); noise.SetLacunarity(MaskLacunarity); noise.SetOctaves(MaskOctaves); noise.SetPeriodX(buffer.Width); noise.SetPeriodY(buffer.Height); var threshVal = 1 / (1 - MaskThreshold); var powFactor = 1 / MaskPower; const int maxPointAttemptCount = 9999; var pointAttemptCount = 0; var span = buffer.GetPixelSpan(); for (var i = 0; i < PointCount; i++) { var x = random.Next(0, buffer.Width); var y = random.Next(0, buffer.Height); // Grab noise at this point. var noiseVal = MathF.Min(1, MathF.Max(0, (noise.GetNoiseTiled(x, y) + 1) / 2)); // Threshold noiseVal = MathF.Max(0, noiseVal - MaskThreshold); noiseVal *= threshVal; noiseVal = (float)MathF.Pow(noiseVal, powFactor); var randomThresh = random.NextFloat(); if (randomThresh > noiseVal) { if (++pointAttemptCount <= maxPointAttemptCount) { i--; } continue; } var dist = random.NextFloat(); for (var oy = y - o; oy <= y + o; oy++) { for (var ox = x - o; ox <= x + o; ox++) { var ix = MathHelper.Mod(ox, buffer.Width); var iy = MathHelper.Mod(oy, buffer.Height); var color = Color.InterpolateBetween(FarColor, CloseColor, dist).ConvertImgSharp(); span[iy * buffer.Width + ix] = color; } } } }
protected override void Draw(DrawingHandleBase handle, OverlaySpace currentSpace) { if (_parallaxTexture == null) { return; } handle.UseShader(_shader); var screenHandle = (DrawingHandleScreen)handle; var(sizeX, sizeY) = _parallaxTexture.Size; var(posX, posY) = _eyeManager.ScreenToMap(Vector2.Zero).Position; var(ox, oy) = (Vector2i) new Vector2(-posX / Slowness, posY / Slowness); ox = MathHelper.Mod(ox, sizeX); oy = MathHelper.Mod(oy, sizeY); var(screenSizeX, screenSizeY) = _displayManager.ScreenSize; for (var x = -sizeX; x < screenSizeX; x += sizeX) { for (var y = -sizeY; y < screenSizeY; y += sizeY) { screenHandle.DrawTexture(_parallaxTexture, new Vector2(ox + x, oy + y)); } } }
public override void Undo() { var instruments = InstrumentDefinitions.Instance.Instruments; var currInstrument = instruments.FindIndex((i) => i == m_instrument.InstrumentDefinition); int newInstrument = MathHelper.Mod(((int)currInstrument - 1), instruments.Count); m_instrument.InstrumentDefinition = InstrumentDefinitions.Instance.Instruments[newInstrument]; }
/// <inheritdoc /> public MapIndices GridTileToChunkTile(MapIndices gridTile) { var size = ChunkSize; var x = MathHelper.Mod(gridTile.X, size); var y = MathHelper.Mod(gridTile.Y, size); return(new MapIndices(x, y)); }
/// <inheritdoc /> public Vector2i GridTileToChunkTile(Vector2i gridTile) { var size = ChunkSize; var x = MathHelper.Mod(gridTile.X, size); var y = MathHelper.Mod(gridTile.Y, size); return(new Vector2i(x, y)); }
public static Vector3I GlobalToInternalChunkPosition(Vector3I globalPosition) { var vec3 = new Vector3I(MathHelper.Mod(globalPosition.X, AbstractChunk.ChunkSize.X), MathHelper.Mod(globalPosition.Y, AbstractChunk.ChunkSize.Y), MathHelper.Mod(globalPosition.Z, AbstractChunk.ChunkSize.Z)); return(vec3); }
public override void Undo() { if (!m_instrument.InstrumentDefinition.IsDrum) { var scaleNames = System.Enum.GetNames(typeof(E_Scales)); int newScale = MathHelper.Mod(((int)m_instrument.Scale + -1), scaleNames.Length); m_instrument.Scale = (E_ConverterType)newScale; } }
public string GetDebugInfo() { if (ShowDebugInfo) { var c = GetChunk((int)PlayerManager.CameraWorldPosition.X, (int)PlayerManager.CameraWorldPosition.Z); //From World Coord to Cube Array Coord int arrayX = MathHelper.Mod((int)PlayerManager.CameraWorldPosition.X, AbstractChunk.ChunkSize.X); int arrayZ = MathHelper.Mod((int)PlayerManager.CameraWorldPosition.Z, AbstractChunk.ChunkSize.Z); var columnInfo = c.BlockData.GetColumnInfo(new Vector2I(arrayX, arrayZ)); int BprimitiveCount = 0; int VprimitiveCount = 0; VisualChunk chunk; //Run over all chunks to see their status, and take action accordingly. for (var chunkIndice = 0; chunkIndice < SortedChunks.Length; chunkIndice++) { chunk = SortedChunks[chunkIndice]; if (!chunk.Graphics.IsFrustumCulled) { if (chunk.Graphics.SolidCubeIB != null) { VprimitiveCount += chunk.Graphics.SolidCubeIB.IndicesCount; } if (chunk.Graphics.LiquidCubeIB != null) { VprimitiveCount += chunk.Graphics.LiquidCubeIB.IndicesCount; } } if (chunk.Graphics.SolidCubeIB != null) { BprimitiveCount += chunk.Graphics.SolidCubeIB.IndicesCount; } if (chunk.Graphics.LiquidCubeIB != null) { BprimitiveCount += chunk.Graphics.LiquidCubeIB.IndicesCount; } } var line0 = string.Format("Nbr chunks : {0:000}, Nbr Visible chunks : {1:000}, {2:0000000} Buffered indices, {3:0000000} Visible indices", SortedChunks.Length, _chunkDrawByFrame, BprimitiveCount, VprimitiveCount); var line1 = string.Format("Static entity draw calls {2}: {0}, time {1}", _staticEntityDrawCalls, _staticEntityDrawTime, DrawStaticInstanced ? "[INSTANCED]" : ""); var line2 = string.Format("Biomes MetaData : Temperature {0:0.00}, Moisture {1:0.00}, ColumnMaxHeight : {2}, ChunkID : {3}", columnInfo.Temperature / 255.0f, columnInfo.Moisture / 255.0f, columnInfo.MaxHeight, c.Position); var line3 = string.Format("Zone id : {0}", columnInfo.Zone); string line4 = string.Empty; if (_utopiaProcessorParam != null) { line4 = string.Format("Biomes MetaData : Chunk Biome Type {0}, Column Biome Type {1}", _utopiaProcessorParam.Biomes[c.BlockData.ChunkMetaData.ChunkMasterBiomeType].Name, _utopiaProcessorParam.Biomes[columnInfo.Biome].Name); } return(string.Join("\r\n", line0, line1, line2, line3, line4)); } else { return(string.Empty); } }
public void ModZero() { const int val = 0; const int mod = 13; const int expected = 0; int result = MathHelper.Mod(val, mod); Assert.AreEqual(result, expected); }
public void ModPositive() { const int val = 25; const int mod = 4; const int expected = 1; int result = MathHelper.Mod(val, mod); Assert.AreEqual(result, expected); }
public void ModNegative() { const int val = -12; const int mod = 3; const int expected = 0; int result = MathHelper.Mod(val, mod); Assert.AreEqual(result, expected); }
/// <summary> /// Get a world's chunk from a Cube location in world coordinate /// </summary> /// <param name="X">Cube X coordinate in world coordinate</param> /// <param name="Z">Cube Z coordinate in world coordinate</param> /// <returns></returns> public VisualChunk GetChunk(int X, int Z) { //From World Coord to Cube Array Coord int arrayX = MathHelper.Mod(X, VisualWorldParameters.WorldVisibleSize.X); int arrayZ = MathHelper.Mod(Z, VisualWorldParameters.WorldVisibleSize.Z); //From Cube Array coord to Chunk Array coord int chunkX = arrayX >> VisualWorldParameters.ChunkPOWsize; int chunkZ = arrayZ >> VisualWorldParameters.ChunkPOWsize; return(Chunks[chunkX + chunkZ * VisualWorldParameters.VisibleChunkInWorld.X]); }
private void Snapping(int currentDistance, int sizeLength, int maxSize) { int modDistance = (MathHelper.Mod(currentDistance, maxSize)); this.CurrentCenterIndex = modDistance / sizeLength + this.centerOffset; this.CurrentPosition = (this.CurrentCenterIndex - centerOffset) * this.slotItemSize; if (this.slotDisplay != null) { this.slotDisplay.UpdatePosition(this.CurrentPosition); } }
public override void UpdatePosition(IntVector2 position) { int dx = spinDirection.X; int dy = spinDirection.Y; IntVector2 maxDistance = this.imageList.Count * this.slotItemSize; for (int i = 0; i < this.imageList.Count; i++) { IntVector2 pos = position + i * this.slotItemSize; pos.X = MathHelper.Mod(pos.X, maxDistance.X) * dx; pos.Y = MathHelper.Mod(pos.Y, maxDistance.Y) * dy; this.imageList[i].transform.localPosition = (Vector2)pos; } }
public bool Add(Vector2i index) { var x = MathHelper.Mod(index.X, ChunkSize); var y = MathHelper.Mod(index.Y, ChunkSize); var oldFlags = _tiles[x]; var newFlags = oldFlags | (1 << y); if (newFlags == oldFlags) { return(false); } _tiles[x] = newFlags; return(true); }
/// <summary> /// Initiliaze the WrapEnd variable. Is not needed if the starting world point is (0,X,0). /// </summary> private void InitWrappingVariables() { //Find the next number where mod == 0 ! int XWrap = VisualWorldParameters.WorldChunkStartUpPosition.X; int ZWrap = VisualWorldParameters.WorldChunkStartUpPosition.Z; while (MathHelper.Mod(XWrap, VisualWorldParameters.WorldVisibleSize.X) != 0) { XWrap++; } while (MathHelper.Mod(ZWrap, VisualWorldParameters.WorldVisibleSize.Z) != 0) { ZWrap++; } VisualWorldParameters.WrapEnd = new Vector2I(XWrap, ZWrap); }
protected override void Draw(DrawingHandle handle) { if (_parallaxTexture == null) { return; } var(sizeX, sizeY) = _parallaxTexture.Size; var(posX, posY) = _eyeManager.ScreenToWorld(Vector2.Zero).ToWorld().Position; var(ox, oy) = (Vector2i) new Vector2(-posX / Slowness, posY / Slowness); ox = MathHelper.Mod(ox, sizeX); oy = MathHelper.Mod(oy, sizeY); handle.DrawTexture(_parallaxTexture, new Vector2(ox, oy)); handle.DrawTexture(_parallaxTexture, new Vector2(ox - sizeX, oy)); handle.DrawTexture(_parallaxTexture, new Vector2(ox, oy - sizeY)); handle.DrawTexture(_parallaxTexture, new Vector2(ox - sizeX, oy - sizeY)); }
private void RefreshMetaData(Vector3I worldPosition, byte newBlockValue) { //From World Coordinate to Chunk Coordinate int arrayX = MathHelper.Mod(worldPosition.X, AbstractChunk.ChunkSize.X); int arrayZ = MathHelper.Mod(worldPosition.Z, AbstractChunk.ChunkSize.Z); //Compute 2D index of ColumnInfo and update ColumnInfo int index2D = arrayX * AbstractChunk.ChunkSize.Z + arrayZ; if (newBlockValue != WorldConfiguration.CubeId.Air) { //Change being made above surface ! if (ColumnsInfo[index2D].MaxHeight < worldPosition.Y) { ColumnsInfo[index2D].MaxHeight = (byte)worldPosition.Y; ChunkMetaData.setChunkMaxHeightBuilt((byte)worldPosition.Y); if (ColumnsInfo[index2D].IsWild) { ColumnsInfo[index2D].IsWild = false; ChunkMetaData.setChunkWildStatus(ColumnsInfo); } } } else { //Change being made at the surface (Block removed) if (ColumnsInfo[index2D].MaxHeight <= worldPosition.Y) { int yPosi = worldPosition.Y - 1; int index = ChunkCubes.Index(worldPosition.X, yPosi, worldPosition.Z); while (ChunkCubes.Cubes[index].Id == WorldConfiguration.CubeId.Air && yPosi > 0) { index = ChunkCubes.FastIndex(index, yPosi, SingleArrayChunkContainer.IdxRelativeMove.Y_Minus1, false); yPosi--; } ChunkMetaData.setChunkMaxHeightBuilt((byte)yPosi); if (ColumnsInfo[index2D].IsWild) { ColumnsInfo[index2D].IsWild = false; ChunkMetaData.setChunkWildStatus(ColumnsInfo); } } } }
private static int GetSequenceContribution(IReadOnlyList <HitObject> hitObjects, int startIndex, IReadOnlyList <int> colourSequence) { if (colourSequence == null) { return(0); } int index = startIndex; int sequenceIndex = 0; int score = 0; while (index < hitObjects.Count && hitObjects[index].ColourIndex == colourSequence[sequenceIndex]) { score++; index++; sequenceIndex = MathHelper.Mod(sequenceIndex + 1, colourSequence.Count); } return(score); }
private void PrevCommand() { if (!commandChanged) { if (searchResults.Count == 0) { return; } searchIndex = MathHelper.Mod(searchIndex - 1, searchResults.Count); SetInput(searchResults[searchIndex]); return; } FindCommands(); if (searchResults.Count == 0) { return; } SetInput(searchResults[^ 1]);
public IEnumerable <IShuffleAction> MergeWithBelow(IShuffleAction below, BigInteger deckSize) { if (below is DealIntoNewStack) { return new List <IShuffleAction> { new DealWithIncrement(MathHelper.Mod(-Increment, deckSize)), new Cut(1) } } ; if (below is DealWithIncrement dwi) { return new List <IShuffleAction> { new DealWithIncrement(MathHelper.Mod(Increment * dwi.Increment, deckSize)) } } ; if (below is Cut cut) { throw new NotImplementedException("not implemented for Cut below, shouldn't be necessary though"); } throw new NotImplementedException(); }
protected internal override void Draw(DrawingHandleScreen handle) { base.Draw(handle); float maxHeight = 0; for (var i = 0; i < _frameTimes.Length; i++) { var currentFrameIndex = MathHelper.Mod(_frameIndex - 1 - i, TrackedFrames); var frameTime = _frameTimes[currentFrameIndex]; maxHeight = System.Math.Max(maxHeight, FrameHeight * (frameTime * TargetFrameRate)); } float ratio = maxHeight > PixelHeight ? PixelHeight / maxHeight : 1; for (int i = 0; i < _frameTimes.Length; i++) { var currentFrameIndex = MathHelper.Mod(_frameIndex - 1 - i, TrackedFrames); var frameTime = _frameTimes[currentFrameIndex]; var frameHeight = FrameHeight * (frameTime * TargetFrameRate); var x = FrameWidth * UserInterfaceManager.UIScale * (TrackedFrames - 1 - i); var rect = new UIBox2(x, PixelHeight - (frameHeight * ratio), x + FrameWidth * UserInterfaceManager.UIScale, PixelHeight); Color color; if (frameTime > 1f / (TargetFrameRate / 2 - 1)) { color = Color.Red; } else if (frameTime > 1f / (TargetFrameRate - 1)) { color = Color.Yellow; } else { color = Color.Lime; } handle.DrawRect(rect, color); } }