예제 #1
0
        internal void OnColorPair(ColorPair newColorPair)
        {
            if (!countsOfSimilarPairs.ContainsKey(newColorPair))
            {
                countsOfSimilarPairs[newColorPair] = 1;

                foreach (var colorPairEntry in countsOfSimilarPairs)
                {
                    if (colorPairEntry.Key.IsVisiblySimilarTo(newColorPair))
                    {
                        countsOfSimilarPairs[newColorPair] = colorPairEntry.Value;

                        //All similar colors are kept in sync, so we only need ony match.
                        break;
                    }
                }
            }

            var similarPairs = new List <ColorPair>(countsOfSimilarPairs.Keys.Where(x => x.IsVisiblySimilarTo(newColorPair)));

            foreach (var colorPair in similarPairs)
            {
                countsOfSimilarPairs[colorPair] = countsOfSimilarPairs[colorPair] + 1;
            }

            if (!countsOfExactPairs.ContainsKey(newColorPair))
            {
                countsOfExactPairs[newColorPair] = 1;
            }
            else
            {
                countsOfExactPairs[newColorPair] = countsOfExactPairs[newColorPair] + 1;
            }
        }
 public override bool Equals(Object obj)
 {
     //Check for null and compare run-time types.
     if ((obj == null) || !this.GetType().Equals(obj.GetType()))
     {
         return(false);
     }
     else
     {
         ColorPair p = (ColorPair)obj;
         return(p.ToString().Equals(ToString(), StringComparison.Ordinal));
     }
 }
예제 #3
0
        /**
         * How confident we are that this result found the actual (or Visibly Similar)
         * Text and Background color combination.
         *
         * Note: A value of HIGH can be depended on for a Rule.
         */
        public Confidence ConfidenceValue()
        {
            if (countsOfSimilarPairs.Count == 0)
            {
                return(Confidence.Low);
            }

            var orderedByCountThenContrast = countsOfSimilarPairs
                                             .OrderByDescending(x => x.Value)
                                             .ThenByDescending(x => x.Key.ColorContrast());

            int       lastCount     = 0;
            ColorPair lastColorPair = null;

            if (orderedByCountThenContrast.First().Value >= ColorContrastConfig.MinNumberColorTransitions)
            {
                foreach (var entry in orderedByCountThenContrast)
                {
                    var colorPair = entry.Key;

                    if (lastColorPair != null)
                    {
                        if (lastColorPair.IsVisiblySimilarTo(colorPair))
                        {
                            continue;
                        }
                        else
                        {
                            if (lastCount > entry.Value * ColorContrastConfig.TextColorPairDominanceValue)
                            {
                                return(Confidence.High);
                            }
                        }
                    }

                    lastColorPair = entry.Key;
                    lastCount     = entry.Value;
                }

                return(Confidence.Mid);
            }

            return(Confidence.Low);
        }
예제 #4
0
        internal ColorContrastResult Add(ColorPair newColorPair)
        {
            var newTextColor = newColorPair.foregroundColor;

            var newBackgroundColor = newColorPair.backgroundColor;

            if (mostContrastingPair == null ||
                mostContrastingPair.ColorContrast() < newColorPair.ColorContrast())
            {
                mostContrastingPair = newColorPair;
            }

            foreach (var alternativePair in alternatives)
            {
                if (!alternativePair.IsVisiblySimilarTo(newColorPair))
                {
                    numDifferentBackgroundColors++;
                    numVisiblyDifferentTextColors++;
                }
            }

            if (numDifferentBackgroundColors > 3 || numVisiblyDifferentTextColors > 3)
            {
                confidence = Confidence.Low;
            }
            else if (numDifferentBackgroundColors > 1 || numVisiblyDifferentTextColors > 1)
            {
                confidence = Confidence.Mid;
            }
            else
            {
                this.confidence = Confidence.High;
            }

            alternatives.Add(newColorPair);

            return(this);
        }
 /**
  * True when a pair of colors have visibly similar pairs of colors.
  */
 public Boolean IsVisiblySimilarTo(ColorPair otherPair)
 {
     return(lighterColor.IsSimilarColor(otherPair.lighterColor) &&
            darkerColor.IsSimilarColor(otherPair.darkerColor));
 }
예제 #6
0
 /**
  * True when a pair of colors have visibly similar pairs of colors.
  */
 public Boolean IsVisiblySimilarTo(ColorPair otherPair)
 {
     return(LighterColor.IsSimilarColor(otherPair.LighterColor) &&
            DarkerColor.IsSimilarColor(otherPair.DarkerColor));
 }