@@ -635,11 +635,11 @@ func (l *GridLayout) IterateGravity() bool {
635635 }
636636
637637 origCenter := p .Rect .Center ()
638- // pos := parent.Rect.Center()
639638 p .Rect = l .MoveTowards (p .Rect , origCenter , 1 )
640639 l .place [child ] = p
641- // if HasRectIntersections(l.place, child) || AnyEdgesIntersect(l.dag, l.place) {
640+
642641 if HasRectIntersections (l .place , child ) || ! l .AllEdgesAxisAligned (l .tolerance ) {
642+ // If constraints are violated, then change it back
643643 p .Rect = p .Rect .WithCenter (origCenter )
644644 l .place [child ] = p
645645 } else {
@@ -676,14 +676,14 @@ func (l *GridLayout) AllEdgesAxisAligned(tolerance int) bool {
676676func AxisAligned (tol int , a , b tile.Rect ) bool {
677677 // align from center, adjusted for room width
678678 minXRadius := math .Min (float64 (a .W ())/ 2 , float64 (b .W ())/ 2 )
679- tolX := int (minXRadius ) - tol
679+ tolX := max ( 0 , int (minXRadius ) - tol )
680680 xOverlap := int (math .Abs (float64 (a .Center ().X - b .Center ().X )))
681681 if xOverlap < tolX {
682682 return true
683683 }
684684
685685 minYRadius := math .Min (float64 (a .H ())/ 2 , float64 (b .H ())/ 2 )
686- tolY := int (minYRadius ) - tol
686+ tolY := max ( 0 , int (minYRadius ) - tol )
687687 yOverlap := int (math .Abs (float64 (a .Center ().Y - b .Center ().Y )))
688688 if yOverlap < tolY {
689689 return true
0 commit comments