From 234503f104ab1e098a2b38eb972fdd761e987cd3 Mon Sep 17 00:00:00 2001 From: Sasha Koshka Date: Wed, 15 Feb 2023 18:41:03 -0500 Subject: [PATCH] Added fixed precision point utilities --- fixedutil/fixedutil.go | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 fixedutil/fixedutil.go diff --git a/fixedutil/fixedutil.go b/fixedutil/fixedutil.go new file mode 100644 index 0000000..dde63d0 --- /dev/null +++ b/fixedutil/fixedutil.go @@ -0,0 +1,26 @@ +// Package fixedutil contains functions that make working with fixed precision +// values easier. +package fixedutil + +import "image" +import "golang.org/x/image/math/fixed" + +// Pt creates a fixed point from a regular point. +func Pt (point image.Point) fixed.Point26_6 { + return fixed.P(point.X, point.Y) +} + +// RoundPt rounds a fixed point into a regular point. +func RoundPt (point fixed.Point26_6) image.Point { + return image.Pt(point.X.Round(), point.Y.Round()) +} + +// FloorPt creates a regular point from the floor of a fixed point. +func FloorPt (point fixed.Point26_6) image.Point { + return image.Pt(point.X.Floor(),point.Y.Floor()) +} + +// CeilPt creates a regular point from the ceiling of a fixed point. +func CeilPt (point fixed.Point26_6) image.Point { + return image.Pt(point.X.Ceil(),point.Y.Ceil()) +}