Example #1
0
        public void ToHsl()
        {
            foreach (HtmlColorSample sample in HtmlColorSamples.All)
            {
                double h = sample.Hsv.Hue / 360d;
                double s = sample.Hsv.Saturation;
                double v = sample.Hsv.Value;

                HsvColor hsv = new HsvColor(h, s, v);

                double h1 = sample.Hsl.Hue / 360d;
                double s1 = sample.Hsl.Saturation;
                double l1 = sample.Hsl.Lightness;

                ColorUtils.HsvToHsl(h, s, v, out double h2, out double s2, out double l2);
                Assert.AreEqual(h1.ToString("N2"), h2.ToString("N2"), "#1 H (" + sample.Name + ")");
                Assert.AreEqual(s1.ToString("N2"), s2.ToString("N2"), "#1 S (" + sample.Name + ")");
                Assert.AreEqual(l1.ToString("N2"), l2.ToString("N2"), "#1 L (" + sample.Name + ")");

                HslColor hsv1 = ColorUtils.HsvToHsl(h, s, v);
                Assert.AreEqual(h1.ToString("N2"), hsv1.Hue.ToString("N2"), "#2 H (" + sample.Name + ")");
                Assert.AreEqual(s1.ToString("N2"), hsv1.Saturation.ToString("N2"), "#2 S (" + sample.Name + ")");
                Assert.AreEqual(l1.ToString("N2"), hsv1.Lightness.ToString("N2"), "#2 L (" + sample.Name + ")");

                HslColor hsv2 = ColorUtils.HsvToHsl(hsv);
                Assert.AreEqual(h1.ToString("N2"), hsv2.Hue.ToString("N2"), "#3 H (" + sample.Name + ")");
                Assert.AreEqual(s1.ToString("N2"), hsv2.Saturation.ToString("N2"), "#3 S (" + sample.Name + ")");
                Assert.AreEqual(l1.ToString("N2"), hsv2.Lightness.ToString("N2"), "#3 L (" + sample.Name + ")");

                HslColor hsv3 = hsv.ToHsl();
                Assert.AreEqual(h1.ToString("N2"), hsv3.Hue.ToString("N2"), "#4 H (" + sample.Name + ")");
                Assert.AreEqual(s1.ToString("N2"), hsv3.Saturation.ToString("N2"), "#4 S (" + sample.Name + ")");
                Assert.AreEqual(l1.ToString("N2"), hsv3.Lightness.ToString("N2"), "#4 L (" + sample.Name + ")");
            }
        }
Example #2
0
        public void HsvTo()
        {
            HsvColor hsv = new HsvColor(208, 0.05882352941176472, 1, 0.5);

            Assert.AreEqual(0.5, hsv.ToCmy().Alpha, "To CMY");

            Assert.AreEqual(0.5, hsv.ToCmyk().Alpha, "To CMYK");

            Assert.AreEqual(0.5, hsv.ToHsl().Alpha, "To HSL");

            Assert.AreEqual(0.5, hsv.ToHsv().Alpha, "To HSV");

            Assert.AreEqual(0.5, hsv.ToRgb().Alpha, "To RGB");
        }