Skip to content

Commit

Permalink
Add rect padding functions
Browse files Browse the repository at this point in the history
  • Loading branch information
unitoftime committed Oct 26, 2024
1 parent 911c478 commit f8712da
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion glm/rect.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,11 +224,21 @@ func (r Rect) Snap() Rect {
return r
}

// Adds padding to a rectangle consistently
// Adds padding to a rectangle consistently on every edge
func (r Rect) PadAll(padding float64) Rect {
return r.Pad(R(padding, padding, padding, padding))
}

// Adds padding to a rectangle on the X axis
func (r Rect) PadX(padding float64) Rect {
return r.Pad(R(padding, 0, padding, 0))
}

// Adds padding to a rectangle on the Y Axis
func (r Rect) PadY(padding float64) Rect {
return r.Pad(R(0, padding, 0, padding))
}

// Adds padding to a rectangle (pads inward if padding is negative)
func (r Rect) Pad(pad Rect) Rect {
return R(r.Min.X-pad.Min.X, r.Min.Y-pad.Min.Y, r.Max.X+pad.Max.X, r.Max.Y+pad.Max.Y)
Expand Down

0 comments on commit f8712da

Please sign in to comment.