From cf778ecd0640c7a078c7239871eb163244d12e7c Mon Sep 17 00:00:00 2001 From: Chris Waldon Date: Mon, 28 Jun 2021 14:16:35 -0400 Subject: [PATCH] layout: add Axis.FConvert for f32.Points This creates a floating-point analog to layout.Axis.Convert for converting from (x,y) coordinate space to (main,cross) coordinate space. Signed-off-by: Chris Waldon --- layout/layout.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/layout/layout.go b/layout/layout.go index a13572e2..0619b914 100644 --- a/layout/layout.go +++ b/layout/layout.go @@ -245,6 +245,16 @@ func (a Axis) Convert(pt image.Point) image.Point { return image.Pt(pt.Y, pt.X) } +// FConvert a point in (x, y) coordinates to (main, cross) coordinates, +// or vice versa. Specifically, FConvert((x, y)) returns (x, y) unchanged +// for the horizontal axis, or (y, x) for the vertical axis. +func (a Axis) FConvert(pt f32.Point) f32.Point { + if a == Horizontal { + return pt + } + return f32.Pt(pt.Y, pt.X) +} + // mainConstraint returns the min and max main constraints for axis a. func (a Axis) mainConstraint(cs Constraints) (int, int) { if a == Horizontal {