• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2022 Google LLC
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.google.ux.material.libmonet.dislike;
18 
19 import com.google.ux.material.libmonet.hct.Hct;
20 
21 /**
22  * Check and/or fix universally disliked colors.
23  *
24  * <p>Color science studies of color preference indicate universal distaste for dark yellow-greens,
25  * and also show this is correlated to distate for biological waste and rotting food.
26  *
27  * <p>See Palmer and Schloss, 2010 or Schloss and Palmer's Chapter 21 in Handbook of Color
28  * Psychology (2015).
29  */
30 public final class DislikeAnalyzer {
31 
DislikeAnalyzer()32   private DislikeAnalyzer() {
33     throw new UnsupportedOperationException();
34   }
35 
36   /**
37    * Returns true if color is disliked.
38    *
39    * <p>Disliked is defined as a dark yellow-green that is not neutral.
40    */
isDisliked(Hct hct)41   public static boolean isDisliked(Hct hct) {
42     final boolean huePasses = Math.round(hct.getHue()) >= 90.0 && Math.round(hct.getHue()) <= 111.0;
43     final boolean chromaPasses = Math.round(hct.getChroma()) > 16.0;
44     final boolean tonePasses = Math.round(hct.getTone()) < 65.0;
45 
46     return huePasses && chromaPasses && tonePasses;
47   }
48 
49   /** If color is disliked, lighten it to make it likable. */
50   public static Hct fixIfDisliked(Hct hct) {
51     if (isDisliked(hct)) {
52       return Hct.from(hct.getHue(), hct.getChroma(), 70.0);
53     }
54 
55     return hct;
56   }
57 }
58