add equals func for Vec and Rect

I think it is useful to add equals func for Vec and Rect.
This commit is contained in:
Alexniver 2018-03-18 22:31:50 +08:00 committed by GitHub
parent 81ecf115f0
commit 144e9c401b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 10 additions and 0 deletions

View File

@ -92,6 +92,11 @@ func (u Vec) To(v Vec) Vec {
}
}
// Equals returns is vector u and v equals.
func (u Vec) Equals(v Vec) bool {
return v.X == u.X && v.Y == u.Y
}
// Scaled returns the vector u multiplied by c.
func (u Vec) Scaled(c float64) Vec {
return Vec{u.X * c, u.Y * c}
@ -294,6 +299,11 @@ func (r Rect) Union(s Rect) Rect {
)
}
// Equals checks if Rect r and s equals
func (r Rect) Equals(s Rect) bool {
return r.Min.Equals(s.Min) && r.Max.Equals(s.Max)
}
// Intersect returns the maximal Rect which is covered by both r and s. Rects r and s must be normalized.
//
// If r and s don't overlap, this function returns R(0, 0, 0, 0).