~sbinet/star-tex

bb815b96d680a95dffcd37f85c943e1957eb47ed — Sebastien Binet 4 months ago 035c3b7
font/fixed: add convenience method to convert Int12_20 to Int26_6

Signed-off-by: Sebastien Binet <s@sbinet.org>
3 files changed, 16 insertions(+), 0 deletions(-)

M font/fixed/int12_20.go
M go.mod
A go.sum
M font/fixed/int12_20.go => font/fixed/int12_20.go +9 -0
@@ 7,6 7,8 @@ package fixed
import (
	"fmt"
	"strconv"

	"golang.org/x/image/math/fixed"
)

// Int12_20 is a signed 12.20 fixed-point number.


@@ 31,6 33,7 @@ func ParseInt12_20(s string) (Int12_20, error) {
	return Int12_20(f * (1 << 20)), nil
}

// Float64 converts the 12.20 fixed-point number to a floating point one.
func (x Int12_20) Float64() float64 {
	v := int32(x)
	return float64(v) / (1 << 20)


@@ 51,3 54,9 @@ func (x Int12_20) String() string {
	}
	return "-2048:00" // The minimum value is -(1<<(12-1)).
}

// ToInt26_6 converts the 12.20 fixed-point number to a 26.6 one.
func (x Int12_20) ToInt26_6() fixed.Int26_6 {
	f := x.Float64()
	return fixed.Int26_6(f * (1 << 6))
}

M go.mod => go.mod +2 -0
@@ 10,3 10,5 @@ retract (
	v0.1.1
	v0.1.0
)

require golang.org/x/image v0.0.0-20210628002857-a66eb6448b8d

A go.sum => go.sum +5 -0
@@ 0,0 1,5 @@
golang.org/x/image v0.0.0-20210628002857-a66eb6448b8d h1:RNPAfi2nHY7C2srAV8A49jpsYr0ADedCk1wq6fTMTvs=
golang.org/x/image v0.0.0-20210628002857-a66eb6448b8d/go.mod h1:023OzeP/+EPmXeapQh35lcL3II3LrY8Ic+EFFKVhULM=
golang.org/x/text v0.3.6 h1:aRYxNxv6iGQlyVaZmk6ZgYEDa+Jg18DxebPSrd6bg1M=
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=