From 4d25e4ece0b72d240bb2565f8abb7389e650990a Mon Sep 17 00:00:00 2001 From: Benjamin Chausse Date: Sat, 23 Nov 2024 21:05:11 -0500 Subject: Preview + Unit-tests for color conversions --- internal/colors/precise.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'internal/colors/precise.go') diff --git a/internal/colors/precise.go b/internal/colors/precise.go index fafa104..a58d7c5 100644 --- a/internal/colors/precise.go +++ b/internal/colors/precise.go @@ -11,6 +11,10 @@ type ColorSpace interface { FromPrecise(PreciseColor) ColorSpace } +func (c PreciseColor) String() string { + return fmt.Sprintf("PC(%.4f, %.4f, %.4f)", c.R, c.G, c.B) +} + // PreciseColor is a color with floating point values for red, green, and blue. // The extra precision minimizes rounding errors when converting between different // color spaces. It is used as an intermediate representation when converting between @@ -27,7 +31,7 @@ func (c PreciseColor) FromPrecise(p PreciseColor) ColorSpace { return p } -func ToHexString(cs ColorSpace) string { +func Hex(cs ColorSpace) string { p := cs.ToPrecise() return strings.ToUpper(fmt.Sprintf("#%02x%02x%02x", -- cgit v1.2.3