From e66e94b9433c40efa1c0360f2d6ea56f4c9c4e91 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nathana=C3=ABl?= Date: Tue, 11 Aug 2020 09:17:51 +0200 Subject: [PATCH] func AlignedTo is used for Rect instead of Matrix --- geometry.go | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/geometry.go b/geometry.go index e1ba2e5..03b4302 100644 --- a/geometry.go +++ b/geometry.go @@ -589,22 +589,13 @@ func (anchorPos AnchorPos) String() string { } // AnchorPos returns the position of the given anchor of the Rect. -func (r *Rect) AnchorPos(anchorPos AnchorPos) Vec { - return r.Min.Add(r.Size().ScaledXY(anchorPos.Val)) +func (r Rect) AnchorPos(anchorPos AnchorPos) Vec { + return r.Size().ScaledXY(V(0, 0).Sub(anchorPos.Val)) } -// AnchorTo updates the Rect position to align it on the given anchor. -func (rect *Rect) AnchorTo(anchorPos AnchorPos) { - size := rect.Size() - rect.Min = rect.Min.Sub(size.ScaledXY(anchorPos.Val)) - rect.Max = rect.Max.Sub(size.ScaledXY(anchorPos.Val)) -} - -// Aligned moves everything to align the given rectangle on the given anchor position. -func (m Matrix) Aligned(rect Rect, anchorPos AnchorPos) Matrix { - vect := rect.Size().ScaledXY(anchorPos.Val) - m[4], m[5] = m[4]-vect.X, m[5]-vect.Y - return m +// AlignedTo returns the rect moved to be aligned on the given anchor. +func (rect Rect) AlignedTo(anchorPos AnchorPos) Rect { + return rect.Moved(rect.AnchorPos(anchorPos)) } // Center returns the position of the center of the Rect.