summaryrefslogtreecommitdiff
path: root/internal/colors/precise.go
diff options
context:
space:
mode:
authorBenjamin Chausse <benjamin@chausse.xyz>2024-11-23 21:05:11 -0500
committerBenjamin Chausse <benjamin@chausse.xyz>2024-11-23 21:05:11 -0500
commit4d25e4ece0b72d240bb2565f8abb7389e650990a (patch)
tree55af982b45d9ed576871c6f3ccf5f800cddc9b56 /internal/colors/precise.go
parentb42ab480dd4c4eec83d79bba9400232ddb79f6b1 (diff)
Preview + Unit-tests for color conversions
Diffstat (limited to 'internal/colors/precise.go')
-rw-r--r--internal/colors/precise.go6
1 files changed, 5 insertions, 1 deletions
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",