2020-09-08 15:58:35 -04:00
|
|
|
package d2geom
|
2020-01-26 00:39:13 -05:00
|
|
|
|
2020-07-08 09:16:56 -04:00
|
|
|
// Rectangle represents a rectangle
|
2020-01-26 00:39:13 -05:00
|
|
|
type Rectangle struct {
|
|
|
|
Left int
|
|
|
|
Top int
|
|
|
|
Width int
|
|
|
|
Height int
|
|
|
|
}
|
|
|
|
|
2020-07-08 09:16:56 -04:00
|
|
|
// Bottom returns y of the bottom point of the rectangle
|
2020-01-26 00:39:13 -05:00
|
|
|
func (v *Rectangle) Bottom() int {
|
|
|
|
return v.Top + v.Height
|
|
|
|
}
|
|
|
|
|
2020-07-08 09:16:56 -04:00
|
|
|
// Right returns x of the right point of the rectangle
|
2020-01-26 00:39:13 -05:00
|
|
|
func (v *Rectangle) Right() int {
|
|
|
|
return v.Left + v.Width
|
|
|
|
}
|
|
|
|
|
2020-07-08 09:16:56 -04:00
|
|
|
// IsInRect returns if the given position is in the rectangle or not
|
2020-01-26 00:39:13 -05:00
|
|
|
func (v *Rectangle) IsInRect(x, y int) bool {
|
|
|
|
return x >= v.Left && x < v.Left+v.Width && y >= v.Top && y < v.Top+v.Height
|
|
|
|
}
|