001/*
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements.  See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License.  You may obtain a copy of the License at
008 *
009 *      http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017package org.apache.commons.imaging.color;
018
019public final class ColorHsv {
020
021    /**
022     * A constant for color black. Color components are:
023     * <pre>
024     *     Hue:        0
025     *     Saturation: 0
026     *     Value:      0
027     * </pre>
028     */
029    public static final ColorHsv BLACK = new ColorHsv(0, 0, 0);
030
031    /**
032     * A constant for color white. Color components are:
033     * <pre>
034     *     Hue:        0
035     *     Saturation: 0
036     *     Value:      100
037     * </pre>
038     */
039    public static final ColorHsv WHITE = new ColorHsv(0, 0, 100);
040
041    /**
042     * A constant for color red. Color components are:
043     * <pre>
044     *     Hue:        0
045     *     Saturation: 100
046     *     Value:      100
047     * </pre>
048     */
049    public static final ColorHsv RED = new ColorHsv(0, 100, 100);
050
051    /**
052     * A constant for color green. Color components are:
053     * <pre>
054     *     Hue:        120
055     *     Saturation: 100
056     *     Value:      100
057     * </pre>
058     */
059    public static final ColorHsv GREEN = new ColorHsv(120, 100, 100);
060
061    /**
062     * A constant for color blue. Color components are:
063     * <pre>
064     *     Hue:        240
065     *     Saturation: 100
066     *     Value:      100
067     * </pre>
068     */
069    public static final ColorHsv BLUE = new ColorHsv(240, 100, 100);
070
071    public final double H;
072    public final double S;
073    public final double V;
074
075    public ColorHsv(final double H, final double S, final double V) {
076        this.H = H;
077        this.S = S;
078        this.V = V;
079    }
080
081    @Override
082    public String toString() {
083        return "{H: " + H + ", S: " + S + ", V: " + V + "}";
084    }
085
086    @Override
087    public boolean equals(final Object o) {
088        if (this == o) {
089            return true;
090        }
091        if (o == null || getClass() != o.getClass()) {
092            return false;
093        }
094
095        final ColorHsv colorHsv = (ColorHsv) o;
096        if (Double.compare(colorHsv.H, H) != 0) {
097            return false;
098        }
099        if (Double.compare(colorHsv.S, S) != 0) {
100            return false;
101        }
102        if (Double.compare(colorHsv.V, V) != 0) {
103            return false;
104        }
105
106        return true;
107    }
108
109    @Override
110    public int hashCode() {
111        int result;
112        long temp;
113        temp = Double.doubleToLongBits(H);
114        result = (int) (temp ^ (temp >>> 32));
115        temp = Double.doubleToLongBits(S);
116        result = 31 * result + (int) (temp ^ (temp >>> 32));
117        temp = Double.doubleToLongBits(V);
118        result = 31 * result + (int) (temp ^ (temp >>> 32));
119        return result;
120    }
121}