From 0a0b9b8cc9cdc0ffe1819de0266dd1e3c3eb564f Mon Sep 17 00:00:00 2001 From: Sam Anthony Date: Tue, 3 Mar 2026 14:22:43 -0500 Subject: style: unit conversion Implemented the golang.org/x/exp/shiny/unit.Converter interface on style.Style. --- style/fixed_test.go | 74 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 style/fixed_test.go (limited to 'style/fixed_test.go') diff --git a/style/fixed_test.go b/style/fixed_test.go new file mode 100644 index 0000000..5cae4bf --- /dev/null +++ b/style/fixed_test.go @@ -0,0 +1,74 @@ +package style + +import ( + "testing" + + "golang.org/x/image/math/fixed" +) + +func TestFixed26ToFloat(t *testing.T) { + t.Parallel() + + var ( + in fixed.Int26_6 + out, want float64 + ) + + in = 0 + out = fixed26ToFloat(in) + want = 0 + if out != want { + t.Errorf("float(%#v) = %v; want %v", in, out, want) + } + + in = fixed.I(123) + out = fixed26ToFloat(in) + want = 123 + if out != want { + t.Errorf("float(%#v) = %v; want %v", in, out, want) + } + + in = fixed.I(-123) + out = fixed26ToFloat(in) + want = -123 + if out != want { + t.Errorf("float(%#v) = %v; want %v", in, out, want) + } + + in = fixed.Int26_6(1<<6 + 1<<4) + out = fixed26ToFloat(in) + want = 1.25 + if out != want { + t.Errorf("float(%#v) = %v; want %v", in, out, want) + } +} + +func TestFloatToFixed26(t *testing.T) { + t.Parallel() + + var ( + in float64 + out, want fixed.Int26_6 + ) + + in = 0 + out = floatToFixed26(in) + want = 0 + if out != want { + t.Errorf("fixed(%#v) = %v; want %v", in, out, want) + } + + in = 1.25 + out = floatToFixed26(in) + want = fixed.Int26_6(1<<6 + 1<<4) + if out != want { + t.Errorf("fixed(%#v) = %v; want %v", in, out, want) + } + + in = -1.25 + out = floatToFixed26(in) + want = -fixed.Int26_6(1<<6 + 1<<4) + if out != want { + t.Errorf("fixed(%#v) = %v; want %v", in, out, want) + } +} -- cgit v1.2.3