public static Dictionary <Color, DiscreteValue> GetAlphaDiscreteColorsForIntents(IIntentStates states) { Dictionary <Color, DiscreteValue> colors = new Dictionary <Color, DiscreteValue>(); IEnumerable <IGrouping <Color, IIntentState> > colorStates = states.GroupBy( (x => { if (x is IIntentState <DiscreteValue> state) { return(state.GetValue().Color); } return(Color.Empty); } )); foreach (IGrouping <Color, IIntentState> grouping in colorStates) { double intensity = grouping.Max(x => { if (x is IIntentState <DiscreteValue> state) { return(state.GetValue().Intensity); } return(0); }); Color brightest = Color.FromArgb(grouping.Key.R, grouping.Key.G, grouping.Key.B); colors.Add(brightest, new DiscreteValue(brightest, intensity)); } return(colors); }
/// <summary> /// Returns a list of alpha affected distinct colors from the states, combined so that the brightest of each color is returned /// </summary> public static IEnumerable <Color> GetAlphaAffectedDiscreteColorsForIntents(IIntentStates states) { List <Color> colors = new List <Color>(); IEnumerable <IGrouping <Color, IIntentState> > colorStates = states.GroupBy( (x => { if (x is IntentState <LightingValue> ) { return((x as IntentState <LightingValue>).GetValue().HueSaturationOnlyColor); } if (x is IntentState <RGBValue> ) { return((x as IntentState <RGBValue>).GetValue().Color); } return(Color.Empty); } )); foreach (IGrouping <Color, IIntentState> grouping in colorStates) { double intensity = grouping.Max(x => { if (x is IntentState <LightingValue> ) { return((x as IntentState <LightingValue>).GetValue().Intensity); } if (x is IntentState <RGBValue> ) { return((x as IntentState <RGBValue>).GetValue().Intensity); } return(0); }); Color brightest = Color.FromArgb((byte)(intensity * byte.MaxValue), grouping.Key.R, grouping.Key.G, grouping.Key.B); colors.Add(brightest); } return(colors); }
/// <summary> /// Returns a list of alpha affected distinct colors from the states, combined so that the brightest of each color is returned /// </summary> public static IEnumerable<Color> GetAlphaAffectedDiscreteColorsForIntents(IIntentStates states) { List<Color> colors = new List<Color>(); IEnumerable<IGrouping<Color, IIntentState>> colorStates = states.GroupBy( (x => { if (x is IntentState<LightingValue>) { return (x as IntentState<LightingValue>).GetValue().HueSaturationOnlyColor; } if (x is IntentState<RGBValue>) { return (x as IntentState<RGBValue>).GetValue().Color; } return Color.Empty; } )); foreach (IGrouping<Color, IIntentState> grouping in colorStates) { double intensity = grouping.Max(x => { if (x is IntentState<LightingValue>) { return (x as IntentState<LightingValue>).GetValue().Intensity; } if (x is IntentState<RGBValue>) { return (x as IntentState<RGBValue>).GetValue().Intensity; } return 0; }); Color brightest = Color.FromArgb((byte)(intensity * byte.MaxValue), grouping.Key.R, grouping.Key.G, grouping.Key.B); colors.Add(brightest); } return colors; }
public static Dictionary<Color, DiscreteValue> GetAlphaDiscreteColorsForIntents(IIntentStates states) { Dictionary<Color, DiscreteValue> colors = new Dictionary<Color, DiscreteValue>(); IEnumerable<IGrouping<Color, IIntentState>> colorStates = states.GroupBy( (x => { var state = x as IntentState<DiscreteValue>; if (state != null) { return state.GetValue().Color; } return Color.Empty; } )); foreach (IGrouping<Color, IIntentState> grouping in colorStates) { double intensity = grouping.Max(x => { var state = x as IntentState<DiscreteValue>; if (state != null) { return state.GetValue().Intensity; } return 0; }); Color brightest = Color.FromArgb(grouping.Key.R, grouping.Key.G, grouping.Key.B); colors.Add(brightest, new DiscreteValue(brightest, intensity)); } return colors; }