You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
25 lines
431 B
Go
25 lines
431 B
Go
4 years ago
|
package math
|
||
|
|
||
4 years ago
|
type Rect struct {
|
||
4 years ago
|
Origin Vec `json:"origin"`
|
||
|
Width int `json:"width"`
|
||
|
Height int `json:"height"`
|
||
4 years ago
|
}
|
||
|
|
||
4 years ago
|
func CreateRect(width, height int) Rect {
|
||
|
return Rect{
|
||
4 years ago
|
Origin: Vec{0, 0},
|
||
|
Width: width,
|
||
|
Height: height,
|
||
4 years ago
|
}
|
||
|
}
|
||
|
|
||
4 years ago
|
func (b Rect) Area() int { return b.Width * b.Height }
|
||
4 years ago
|
|
||
4 years ago
|
func (b Rect) Contains(v Vec) bool {
|
||
4 years ago
|
return v.X >= b.Origin.X &&
|
||
|
v.X < b.Origin.X+b.Width &&
|
||
|
v.Y >= b.Origin.Y &&
|
||
|
v.Y < b.Height
|
||
4 years ago
|
}
|