public async Task <List <float> > GetValuesAsync(RandomFieldNature nature, float seed, List <Vector2> queryPositions) { Dictionary <MyRectangle, IntensityFieldFigure> segmentsDict = null; var randomFieldFigureId = new RandomFieldFigureId(nature, seed); if (!_figuresDictionary.ContainsKey(randomFieldFigureId)) { segmentsDict = new Dictionary <MyRectangle, IntensityFieldFigure>(); _figuresDictionary[randomFieldFigureId] = segmentsDict; } else { segmentsDict = _figuresDictionary[randomFieldFigureId]; } List <MyRectangle> segmentCoordsList = new List <MyRectangle>(queryPositions.Count); for (int i = 0; i < queryPositions.Count; i++) { segmentCoordsList.Add(CalculateSegment(queryPositions[i])); } List <MyRectangle> distinctCoords = segmentCoordsList.Distinct().ToList(); List <MyRectangle> coordsToCreateFigureFor = distinctCoords.Where(c => !segmentsDict.ContainsKey(c)).ToList(); if (coordsToCreateFigureFor.Any()) { var createdFigures = await TaskUtils.WhenAll(Enumerable.Range(0, coordsToCreateFigureFor.Count).Select( (i) => { var coord = coordsToCreateFigureFor[i]; return(_figureGenerator.GenerateRandomFieldFigureAsync(nature, seed, coord)); })); for (int i = 0; i < coordsToCreateFigureFor.Count; i++) { var coord = coordsToCreateFigureFor[i]; segmentsDict[coord] = createdFigures[i]; } } List <float> outList = new List <float>(queryPositions.Count); for (int i = 0; i < queryPositions.Count; i++) { var position = queryPositions[i]; var segmentCoords = segmentCoordsList[i]; IntensityFieldFigure fieldFigure = segmentsDict[segmentCoords]; var inFigureUv = new Vector2((position.x - segmentCoords.X) / segmentCoords.Width, (position.y - segmentCoords.Y) / segmentCoords.Height); outList.Add(fieldFigure.GetPixelWithUv(inFigureUv)); } return(outList); }
protected bool Equals(RandomFieldFigureId other) { return(Equals(_nature, other._nature) && seed.Equals(other.seed)); }