public virtual void TryGetPreferredPosition() { Check(); PreferredPosition.Clear(); Point spritetSize = SpriteColorSize; Value[,] valueMap = new Value[spritetSize.X, spritetSize.Y]; EffectiveArea = GetEffectiveArea(); foreach (Point point in GetShiftPosition()) { for (int index = 0; index < EffectiveArea.Length; index++) { Point selectPoint = EffectiveArea[index]; JPColor spriteColor = SpriteColor[selectPoint.X, selectPoint.Y]; JPColor effectColor = EffectSpriteColor[point.X + selectPoint.X, point.Y + selectPoint.Y]; valueMap[selectPoint.X, selectPoint.Y] = GetDeltaValue(effectColor, spriteColor); } if (ValueMapIsBetter(valueMap, out float averageValue)) { PreferredPosition.Add(new WeightedPoint(point, averageValue)); } } #if DEBUG && MVC && !PARALLELMODE System.Text.StringBuilder builder = new System.Text.StringBuilder(); foreach (WeightedPoint weightedPoint in PreferredPosition) { builder.AppendLine($"{nameof(WeightedPoint)} : {weightedPoint}"); } Log.WriteData(null, $"ColorMatch.TryGetPreferredPosition, PreferredPosition : {PreferredPosition.Count}", builder.ToString()); #endif }
public virtual void TryGetNearlyPreferredPosition(int distance) { Check(); Point spriteSize = SpriteColorSize; HashSet <Point> points = new HashSet <Point>(); foreach (WeightedPoint weightedPoint in PreferredPosition) { foreach (Point point in ShiftPosition.EnumItNearly(EffectSpriteColorSize, spriteSize, weightedPoint.Position, distance)) { points.Add(point); } } PreferredPosition.Clear(); EffectiveArea = GetEffectiveArea(); Value[,] valueMap = new Value[spriteSize.X, spriteSize.Y]; foreach (Point point in points) { foreach (Point selectPoint in EffectiveArea) { JPColor effectColor = EffectSpriteColor[point.X + selectPoint.X, point.Y + selectPoint.Y]; JPColor spriteColor = SpriteColor[selectPoint.X, selectPoint.Y]; valueMap[selectPoint.X, selectPoint.Y] = GetDeltaValue(effectColor, spriteColor); } if (ValueMapIsBetter(valueMap, out float averageValue)) { PreferredPosition.Add(new WeightedPoint(point, averageValue)); } } }