public void FillGrid(Grid g, FillOptions options) { using (var bitmapWrapper = new BmpPixelSnoop(drawArea)) using (var textureWrapper = options.Texture != null ? new BmpPixelSnoop(options.Texture) : null) Parallel.ForEach(g.GetPolygons(), t => AlgorithmUtils.FillPolygon(t, options, bitmapWrapper, textureWrapper)); //g.GetPolygons().ForEach(t => AlgorithmUtils.FillPolygon(t, options, bitmapWrapper, textureWrapper)); }
public void OnCorrect(long eventId, long orderId, Side side, long newFillPrice, int newFilledQuantity, int quantityLeft, DateTime transactTime, string symbol, FillOptions options) { _logger.LogInformation( $"Corrected: {eventId}, order id: {orderId}, exec id: {options.ExecId}, changing to {newFilledQuantity} @{newFillPrice}"); }
public void Fill(FillOptions options) { fillGridOptions = options; //clear old grid drawingModule.ClearGridBorders(grid); drawingModule.ClearGridFilling(grid); grid = new Grid(this.fillGridOptions.GridN, this.fillGridOptions.GridM, CONSTS.gridLeft, CONSTS.gridTop, CONSTS.gridWidth / this.fillGridOptions.GridM, CONSTS.gridHeight / this.fillGridOptions.GridN); fillGridOptions.GridLeft = grid.Left; fillGridOptions.GridTop = grid.Top; if (options.LightVectorOption == LightVectorOpt.FromPointOnSpiral) { this.fillGridOptions.LightVectorOption = LightVectorOpt.FromPointOnSpiral; this.fillGridOptions.LightPoint = new Vector(animatingSpiralPointState.X, animatingSpiralPointState.Y, animatingSpiralPointState.Z); StartAnimation(); } else { StopAnimation(); drawingModule.ClearGridBorders(grid); drawingModule.ClearGridFilling(grid); Redraw(); } }
public void CopyFrom() { FillOptions other = new FillOptions() { FillType = FillType.Triangle, LayerByLayer = false, Percentage = 55, AngleInDegrees = 30f, CrossAngleInDegrees = 60f, FillLocation = FillLocation.OuterPerimeter, SolidLayerCount = 3 }; FillOptions options = new FillOptions(); options.CopyFrom(other); Assert.AreEqual(FillType.Triangle, options.FillType); Assert.AreEqual(false, options.LayerByLayer); Assert.AreEqual(55, options.Percentage); Assert.AreEqual(30f, options.AngleInDegrees); Assert.AreEqual(60f, options.CrossAngleInDegrees); Assert.AreEqual(FillLocation.OuterPerimeter, options.FillLocation); Assert.AreEqual(3, options.SolidLayerCount); }
private static Vector getNormalVectorFromTexture(int x, int y, FillOptions options, BmpPixelSnoop textureWrapper) { if (textureWrapper == null) { return(DEFAULT_OPTIONS.defaultNormalVector); } var vector = textureWrapper.GetPixel(x - (int)(options.GridLeft), y - (int)(options.GridTop)); return(new Vector(scaleToNormalVector(vector.R), scaleToNormalVector(vector.G), scale_Form_0_255_To_0_1(vector.B)).GetNormalised()); double scaleToNormalVector(int c) { var ret = ((double)c / 255) * 2 - 1; if (ret > 1) { return(1); } if (ret < -1) { return(-1); } return(ret); } }
public void OnFill(long eventId, long orderId, Side side, int liquidity, long fillPrice, int quantityFilled, int quantityLeft, DateTime transactTime, string symbol, FillOptions options) { _logger.LogInformation( $"TransactTime: {transactTime}, Shares fill: {eventId}, order id: {orderId}, symbol: {symbol}, quantity filled: {quantityFilled}/{quantityLeft}, fill price {fillPrice}"); if (quantityLeft == 0) { _activeOrders.Remove(orderId); } }
public void Defaults() { FillOptions options = new FillOptions(); Assert.AreEqual(FillType.CrossHatch, options.FillType); Assert.AreEqual(true, options.LayerByLayer); Assert.AreEqual(20, options.Percentage); Assert.AreEqual(45f, options.AngleInDegrees); Assert.AreEqual(90f, options.CrossAngleInDegrees); Assert.AreEqual(FillLocation.InsideInnerPerimeter, options.FillLocation); Assert.AreEqual(2, options.SolidLayerCount); }
public AggregationModule(FillOptions fillGridOptions, PictureBox drawBox) { this.fillGridOptions = fillGridOptions; grid = new Grid(this.fillGridOptions.GridN, this.fillGridOptions.GridM, CONSTS.gridLeft, CONSTS.gridTop, CONSTS.gridWidth / this.fillGridOptions.GridM, CONSTS.gridHeight / this.fillGridOptions.GridN); drawingModule = new DrawingModule(drawBox); movingVertexState = new MovingVertexState(null); animatingSpiralPointState = new AnimatingSpiralPointState(Math.Max(grid.Height, grid.Width) / 2, grid.Center); lightAnimationTimer = new Timer(); lightAnimationTimer.Interval = 30; lightAnimationTimer.Tick += (object sender, EventArgs e) => { AnimationHandler(); }; }
/// <summary> /// Fills string to given length /// </summary> /// <param name="x"></param> /// <param name="length"></param> /// <param name="filler"></param> /// <param name="options">If used truncate with prepend option, the returned string will be token from the end of original string. Defualt is (no prepend, no truncate, no overwrite)</param> /// <returns></returns> public static string Fill( this string x, int length, FillOptions options, char filler = ' ') { if (x.Length > length) { // No truncate option if ((options & FillOptions.Truncate) == 0) { return(x); } // Truncate with Prepend if ((options & (FillOptions.Truncate | FillOptions.Prepend)) != 0) { // No overwrite if ((options & FillOptions.OverwriteBaseString) == 0) { return(x.Substring(x.Length - length - 1)); } x = x.Substring(x.Length - length - 1); return(x); } } // Prepend option if ((options & FillOptions.Prepend) != 0) { if ((options & FillOptions.OverwriteBaseString) == 0) { return(filler.Repeat(length - x.Length) + x); } x = filler.Repeat(length - x.Length) + x; return(x); } if ((options & FillOptions.OverwriteBaseString) == 0) { return(x + filler.Repeat(length - x.Length)); } x = x + filler.Repeat(length - x.Length); return(x); }
/// <summary> /// </summary> /// <param name="x"></param> /// <param name="y"></param> /// <param name="options"></param> /// <returns></returns> /// <remarks>Only for triangles.</remarks> private static Color GetInterpolatedColorForPixel( double x1, double y1, double x2, double y2, double x3, double y3, double triangleDenominator, // cout once, use for each pixel Vector normalVector1, // cout once, use for each pixel Vector normalVector2, // cout once, use for each pixel Vector normalVector3, // cout once, use for each pixel Color objectColor1, // cout once, use for each pixel Color objectColor2, // cout once, use for each pixel Color objectColor3, // cout once, use for each pixel int x, int y, FillOptions options, BmpPixelSnoop textureWrapper) { // calculate barycentric coordinates double W1 = ((y2 - y3) * (x - x3) + (x3 - x2) * (y - y3)) / triangleDenominator; double W2 = ((y3 - y1) * (x - x3) + (x1 - x3) * (y - y3)) / triangleDenominator; double W3 = 1 - W1 - W2; Vector N = options.NormalVectorOption == NormalVectorOpt.FromTexture ? W1 * normalVector1 + W2 * normalVector2 + W3 * normalVector3 // inerpolated normal vector : DEFAULT_OPTIONS.defaultNormalVector; Vector V = new Vector(0, 0, 1); var LightPoint = options.LightPoint; var L = (options.LightVectorOption == LightVectorOpt.FromPointOnSpiral && LightPoint != null) ? new Vector(LightPoint.X - x, (-1) * (LightPoint.Y - y), LightPoint.Z - 0).GetNormalised() : DEFAULT_OPTIONS.defaultLightVector; Vector R = 2 * Vector.DotProduct(N, L) * N - L; Color Il = options.LightColor; Color Io = (options.ObjectColorOption == ObjectColorOpt.Constant || options.Texture == null) ? (Color)options.ObjectColor : Color.FromArgb( round_To_0_255((int)(W1 * objectColor1.R + W2 * objectColor2.R + W3 * objectColor3.R)), round_To_0_255((int)(W1 * objectColor1.G + W2 * objectColor2.G + W3 * objectColor3.G)), round_To_0_255((int)(W1 * objectColor1.B + W2 * objectColor2.B + W3 * objectColor3.B))); // interpolated object color double kd = options.LambertModelFactor; double ks = options.ReflectionFactor; int m = options.ReflectionLevel; return(Color.FromArgb(calculatePart(Il.R, Io.R, kd, ks, N, L, V, R, m), calculatePart(Il.G, Io.G, kd, ks, N, L, V, R, m), calculatePart(Il.B, Io.B, kd, ks, N, L, V, R, m))); }
private static Color GetPreciseColorForPixel(int x, int y, FillOptions options, BmpPixelSnoop textureWrapper) { Vector N = options.NormalVectorOption == NormalVectorOpt.FromTexture ? getNormalVectorFromTexture(x, y, options, textureWrapper) : DEFAULT_OPTIONS.defaultNormalVector; Vector V = new Vector(0, 0, 1); var LightPoint = options.LightPoint; var L = (options.LightVectorOption == LightVectorOpt.FromPointOnSpiral && LightPoint != null) ? new Vector(LightPoint.X - x, (-1) * (LightPoint.Y - y), LightPoint.Z - 0).GetNormalised() : DEFAULT_OPTIONS.defaultLightVector; Vector R = 2 * Vector.DotProduct(N, L) * N - L; Color Il = options.LightColor; Color Io = (options.ObjectColorOption == ObjectColorOpt.Constant || options.Texture == null) ? (Color)options.ObjectColor : textureWrapper.GetPixel(x - (int)(options.GridLeft), y - (int)(options.GridTop)); double kd = options.LambertModelFactor; double ks = options.ReflectionFactor; int m = options.ReflectionLevel; return(Color.FromArgb(calculatePart(Il.R, Io.R, kd, ks, N, L, V, R, m), calculatePart(Il.G, Io.G, kd, ks, N, L, V, R, m), calculatePart(Il.B, Io.B, kd, ks, N, L, V, R, m))); }
public void Reset() { FillOptions options = new FillOptions() { FillType = FillType.Triangle, LayerByLayer = false, Percentage = 55, AngleInDegrees = 30f, CrossAngleInDegrees = 60f, FillLocation = FillLocation.OuterPerimeter, SolidLayerCount = 3 }; options.Reset(); Assert.AreEqual(FillType.CrossHatch, options.FillType); Assert.AreEqual(true, options.LayerByLayer); Assert.AreEqual(20, options.Percentage); Assert.AreEqual(45f, options.AngleInDegrees); Assert.AreEqual(90f, options.CrossAngleInDegrees); Assert.AreEqual(FillLocation.InsideInnerPerimeter, options.FillLocation); Assert.AreEqual(2, options.SolidLayerCount); }
public int Fill(FillOptions options, DbTransaction transaction, object[] parameterValues) { throw new NotImplementedException(); }
public static void FillPolygon(Polygon polygon, FillOptions options, BmpPixelSnoop bitmapWrapper, BmpPixelSnoop textureWrapper) { #region prepare data for interpolation if needed double x1 = 1, y1 = 1; double x2 = 1, y2 = 1; double x3 = 1, y3 = 1; double triangleDenominator = 1; Vector normalVector1 = null; Vector normalVector2 = null; Vector normalVector3 = null; Color objectColor1 = Color.FromArgb(1, 1, 1); Color objectColor2 = Color.FromArgb(1, 1, 1); Color objectColor3 = Color.FromArgb(1, 1, 1); if (options.FillColorPrecisionOption == FillColorPrecisionOpt.Interpolated) { // assume polygon is a traingle if (polygon.Vertices.Count != 3) { throw new ArgumentException("Interpolated Presices is possible only for triangles!"); } x1 = polygon.Vertices[0].X; y1 = polygon.Vertices[0].Y; x2 = polygon.Vertices[1].X; y2 = polygon.Vertices[1].Y; x3 = polygon.Vertices[2].X; y3 = polygon.Vertices[2].Y; triangleDenominator = (y2 - y3) * (x1 - x3) + (x3 - x2) * (y1 - y3); if (triangleDenominator == 0) { triangleDenominator = 1; } normalVector1 = getNormalVectorFromTexture((int)x1, (int)y1, options, textureWrapper); normalVector2 = getNormalVectorFromTexture((int)x2, (int)y2, options, textureWrapper); normalVector3 = getNormalVectorFromTexture((int)x3, (int)y3, options, textureWrapper); objectColor1 = (options.ObjectColorOption == ObjectColorOpt.Constant || options.Texture == null) ? (Color)options.ObjectColor : textureWrapper.GetPixel((int)(x1 - options.GridLeft), (int)(y1 - options.GridTop)); objectColor2 = (options.ObjectColorOption == ObjectColorOpt.Constant || options.Texture == null) ? (Color)options.ObjectColor : textureWrapper.GetPixel((int)(x2 - options.GridLeft), (int)(y2 - options.GridTop)); objectColor3 = (options.ObjectColorOption == ObjectColorOpt.Constant || options.Texture == null) ? (Color)options.ObjectColor : textureWrapper.GetPixel((int)(x3 - options.GridLeft), (int)(y3 - options.GridTop)); } #endregion var sortedVertices = polygon.Vertices.ConvertAll(v => v); sortedVertices.Sort((a, b) => { if (a.Y < b.Y) { return(-1); } if (a.Y == b.Y) { return(0); } return(1); }); var ind = sortedVertices.ConvertAll(v => polygon.Vertices.IndexOf(v)); var P = polygon.Vertices; double ymin = P[ind[0]].Y; double ymax = P[ind[ind.Count - 1]].Y; int k = 0; // current vertex index; List <AETItem> AET = new List <AETItem>(); // for each scanline for (double y = ymin + 1; y <= ymax + 1; y++) { while (k < ind.Count && y - 1 == P[ind[k]].Y) { // previous vertex int pVertInd = ind[k] - 1 >= 0 ? ind[k] - 1 : P.Count - 1; if (P[pVertInd].Y >= P[ind[k]].Y) { // add to AET double dx = (double)(P[pVertInd].X - P[ind[k]].X); double dy = (double)(P[pVertInd].Y - P[ind[k]].Y); if (dy != 0) { AET.Add(new AETItem(P[pVertInd], P[ind[k]], P[ind[k]].X, dx / dy)); } } else { // remove from AET AET.RemoveAll(i => i.start == P[pVertInd] && i.end == P[ind[k]]); } // next vertex int nVertInd = ind[k] + 1 < P.Count ? ind[k] + 1 : 0; if (P[nVertInd].Y >= P[ind[k]].Y) { // add to AET double dx = (double)(P[ind[k]].X - P[nVertInd].X); double dy = (double)(P[ind[k]].Y - P[nVertInd].Y); if (dy != 0) { AET.Add(new AETItem(P[ind[k]], P[nVertInd], P[ind[k]].X, dx / dy)); } } else { // remove from AET AET.RemoveAll(i => i.start == P[ind[k]] && i.end == P[nVertInd]); } k++; } // sort by x AET.Sort((a, b) => { if (a.x < b.x) { return(-1); } if (a.x == b.x) { return(0); } return(1); }); // set pixels for (int i = 0; i < AET.Count - 1; i += 2) { for (double x = AET[i].x; x <= AET[i + 1].x; x++) { bitmapWrapper.SetPixel((int)x, (int)y - 1, options.FillColorPrecisionOption == FillColorPrecisionOpt.Precise ? GetPreciseColorForPixel((int)x, (int)y - 1, options, textureWrapper) : GetInterpolatedColorForPixel( (int)x1, (int)y1, (int)x2, (int)y2, (int)x3, (int)y3, triangleDenominator, normalVector1, normalVector2, normalVector3, objectColor1, objectColor2, objectColor3, (int)x, (int)y - 1, options, textureWrapper)); } } // update x AET.ForEach(v => v.x += v.reciprocalM); } }
public void OnUSOptionsBust(long eventId, long orderId, Side reversedSide, long bustedPrice, int quantityBusted, int quantityLeft, DateTime transactTime, USOptionsSymbol symbol, FillOptions options) { _logger.LogInformation($"Busted: {eventId}, order id: {orderId}, exec id: {options.ExecId}"); }
public int Fill (FillOptions options, DbTransaction transaction, object[] parameterValues) { throw new NotImplementedException (); }
public static void Randomize() { var fileNames = new List <string>(Directory.GetFiles(Environment.CurrentDirectory)); var logicFile = ChooseLogic(fileNames.Where(x => Path.GetExtension(x) == ".lgc").ToList()); if (logicFile == null) { // Log issue _logMessage += $"No logic file chosen{Environment.NewLine}"; } var data = JsonConvert.DeserializeObject <SaveData>(File.ReadAllText(logicFile)); KeyManager.Initialize(data); var traverser = new NodeTraverser(); var settingsFile = ChooseSettings(fileNames.Where(x => Path.GetExtension(x) == ".txt" || Path.GetExtension(x) == ".log").ToList()); if (settingsFile == null) { // Log issue _logMessage += $"No settings chosen{Environment.NewLine}"; } if (!TryParseSettingsFile(startingInventory, settingsFile)) { // Log issue _logMessage += "Failed to parse settings"; } var randomizationType = ChooseRandomization(); var gameCompletion = ChooseGameCompletion(); var random = new Random(); var seed = random.Next(); // var seed = 1083686163; var count = 0; _Timer.Start(); while (true) { if (randomizationType == 1) { var placer = new ItemPlacer(); var options = new FillOptions(); options.gameCompletion = gameCompletion; options.majorSwap = FillOptions.ItemSwap.GlobalPool; options.minorSwap = FillOptions.ItemSwap.LocalPool; // options.noEarlyPbs = true; var result = false; var itemMap = new Dictionary <string, Guid>(); ItemPool pool = new ItemPool(); pool.CreatePool(); foreach (var item in itemMap.Values) { pool.Pull(item); } while (true) { random = new Random(seed); //pool.RemoveRandomItemsExcept(90, random, new List<Guid>() { StaticKeys.Morph, StaticKeys.Missile, StaticKeys.Bombs, StaticKeys.IceBeam, StaticKeys.PlasmaBeam }); var testInventory = new Inventory(startingInventory); testInventory.myKeys.AddRange(pool.AvailableItems().Where(key => key != StaticKeys.Nothing && (!options.noEarlyPbs || key != StaticKeys.PowerBombs)).Select(id => KeyManager.GetKey(id))); if (traverser.VerifyBeatable(data, itemMap, testInventory)) { break; } seed = random.Next(); pool.CreatePool(); foreach (var item in itemMap.Values) { pool.Pull(item); } } random = new Random(seed); var randomMap = placer.FillLocations(data, options, pool, startingInventory, random, itemMap); if (gameCompletion == FillOptions.GameCompletion.Beatable) { result = traverser.VerifyBeatable(data, randomMap, new Inventory(startingInventory)); } else if (gameCompletion == FillOptions.GameCompletion.AllItems) { result = traverser.VerifyFullCompletable(data, randomMap, new Inventory(startingInventory)); } if (result) { Console.WriteLine($"{Environment.NewLine}Randomization complete after {count} attempts - Successful seed: {seed}"); Console.WriteLine(traverser.GetWaveLog()); _Timer.Stop(); resultItemMap = randomMap; return; } seed = random.Next(); Console.WriteLine($"Attempts {count}"); } else if (randomizationType == 2) { var pool = new ItemPool(); pool.CreatePool(); random = new Random(seed); var randomMap = StaticData.Locations.ToDictionary(location => location, location => pool.Pull(random)); var morphItem = randomMap.FirstOrDefault(x => x.Value.Equals(StaticKeys.Morph)); if (string.IsNullOrWhiteSpace(morphItem.Key)) { seed = random.Next(); continue; } var morphLocation = randomMap.FirstOrDefault(x => x.Key.Equals("BrinstarMorph")); randomMap[morphItem.Key] = morphLocation.Value; randomMap[morphLocation.Key] = StaticKeys.Morph; var result = false; if (gameCompletion == FillOptions.GameCompletion.Beatable) { result = traverser.VerifyBeatable(data, randomMap, new Inventory(startingInventory)); } else if (gameCompletion == FillOptions.GameCompletion.AllItems) { result = traverser.VerifyFullCompletable(data, randomMap, new Inventory(startingInventory)); } if (result) { Console.WriteLine($"Randomization complete after {count} attempts - Successful seed: {seed}"); _Timer.Stop(); resultItemMap = randomMap; return; } if (count % 50 == 0) { Console.WriteLine($"Attempts {count}"); } } count++; seed = random.Next(); } }
public int FillPage (int startRecord, int maxRecords, FillOptions options, DbTransaction transaction, object[] parameterValues) { throw new NotImplementedException (); }
public int FillPage(int startRecord, int maxRecords, FillOptions options, DbTransaction transaction, object[] parameterValues) { throw new NotImplementedException(); }