49 lines
804 B
Go
49 lines
804 B
Go
package util
|
|
|
|
type Vec2 struct {
|
|
X, Y int64
|
|
}
|
|
|
|
func (v Vec2) Mult(by int64) Vec2 {
|
|
return Vec2{v.X * by, v.Y * by}
|
|
}
|
|
|
|
func (v Vec2) Add(a Vec2) Vec2 {
|
|
return Vec2{v.X + a.X, v.Y + a.Y}
|
|
}
|
|
|
|
func (v Vec2) Eq(a Vec2) bool {
|
|
return v.X == a.X && v.Y == a.Y
|
|
}
|
|
|
|
func (v Vec2) Up() Vec2 {
|
|
return v.Add(Vec2{0, -1})
|
|
}
|
|
|
|
func (v Vec2) Down() Vec2 {
|
|
return v.Add(Vec2{0, 1})
|
|
}
|
|
|
|
func (v Vec2) Left() Vec2 {
|
|
return v.Add(Vec2{-1, 0})
|
|
}
|
|
|
|
func (v Vec2) Right() Vec2 {
|
|
return v.Add(Vec2{1, 0})
|
|
}
|
|
|
|
func (v Vec2) RotateCounterClock() Vec2 {
|
|
return Vec2{v.Y, -v.X}
|
|
}
|
|
|
|
func (v Vec2) RotateClock() Vec2 {
|
|
return Vec2{-v.Y, v.X}
|
|
}
|
|
|
|
func (v Vec2) LenSquared() uint64 {
|
|
return uint64(v.X*v.X + v.Y*v.Y)
|
|
}
|
|
|
|
func (v Vec2) IsInBounds(bounds Vec2) bool {
|
|
return v.X >= 0 && v.X < bounds.X && v.Y >= 0 && v.Y < bounds.Y
|
|
}
|