asmrobot
2019-11-21 589ed88a5924a7494e21b95b6bbff5e46ff49ddd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace RichCreator.Utility.Structs
{
    public struct ZTHsvColor
    {
        public ZTHsvColor(ZTColor color)
        {
            float h, s, v;
            ColorUtils.RGBtoHSV(color.Red, color.Green, color.Blue, out h, out s, out v);
            this.H = (byte)(h * 180);
            this.S = (byte)(s * 255);
            this.V = (byte)(v * 255);
        }
 
        /// <summary>
        /// 
        /// </summary>
        /// <param name="h">色相(0~180)</param>
        /// <param name="s">饱合度(0~255)</param>
        /// <param name="v">明度(0~255)</param>
        public ZTHsvColor(byte h, byte s, byte v)
        {
            this.H = h;
            this.S = s;
            this.V = v;
        }
 
        /// <summary>
        /// 
        /// </summary>
        /// <param name="h">色相(0~1)</param>
        /// <param name="s">饱合度(0~1)</param>
        /// <param name="v">明度(0~1)</param>
        public ZTHsvColor(double h, double s, double v)
        {
            this.H = (byte)(h * 180);
            this.S = (byte)(s * 255);
            this.V = (byte)(v * 255);
        }
 
        /// <summary>
        /// 色相(0~180)
        /// </summary>
        public byte H;
 
        /// <summary>
        /// 饱合度(0~255)
        /// </summary>
        public byte S;
 
        /// <summary>
        /// 明度(0~255)
        /// </summary>
        public byte V;
 
 
        public bool IsBetween(ZTHsvColor min, ZTHsvColor max)
        {
            if (this.H >= min.H && this.S >= min.S && this.V >= min.V &&
                this.H <= max.H && this.S <= max.S && this.V <= max.V)
            {
                return true;
            }
            return false;
        }
    }
}