From 144e9c401b306b3de93127dc9d394bafccb68294 Mon Sep 17 00:00:00 2001 From: Alexniver Date: Sun, 18 Mar 2018 22:31:50 +0800 Subject: [PATCH] add equals func for Vec and Rect I think it is useful to add equals func for Vec and Rect. --- geometry.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/geometry.go b/geometry.go index 0cb1436..78af3ce 100644 --- a/geometry.go +++ b/geometry.go @@ -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).