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 <christopher.waldon.dev@gmail.com>
This commit is contained in:
Chris Waldon
2021-06-28 14:16:35 -04:00
committed by Elias Naur
parent d331f63d20
commit cf778ecd06
+10
View File
@@ -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 {