From 0471c8bf5f22a836ac432bd106003aa8164d9702 Mon Sep 17 00:00:00 2001 From: Taco de Wolff Date: Mon, 6 Jan 2025 22:23:11 +0100 Subject: [PATCH] Contains also means on the boundary --- path.go | 5 ++++- util.go | 10 +++++----- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/path.go b/path.go index 39a758a..4ff3087 100644 --- a/path.go +++ b/path.go @@ -927,7 +927,10 @@ func (p *Path) Crossings(x, y float64) (int, bool) { // FillRule. It uses a ray from (x,y) toward (∞,y) and counts the number of intersections with // the path. When the point is on the boundary it is considered to be on the path's exterior. func (p *Path) Contains(x, y float64, fillRule FillRule) bool { - n, _ := p.Windings(x, y) + n, boundary := p.Windings(x, y) + if boundary { + return true + } return fillRule.Fills(n) } diff --git a/util.go b/util.go index c68a7d8..ff02240 100644 --- a/util.go +++ b/util.go @@ -466,10 +466,10 @@ func (r Rect) Transform(m Matrix) Rect { // ContainsPoint returns true if the rectangles contains a point, not if it touches an edge. func (r Rect) ContainsPoint(p Point) bool { - if p.X <= r.X0 || r.X1 <= p.X { + if p.X < r.X0 || r.X1 < p.X { // left or right return false - } else if p.Y <= r.Y0 || r.Y1 <= p.Y { + } else if p.Y < r.Y0 || r.Y1 < p.Y { // below or above return false } @@ -557,7 +557,7 @@ func (r Rect) TouchesLine(a, b Point) bool { // Contains returns true if r contains q. func (r Rect) Contains(q Rect) bool { - return r.X0 < q.X0 && q.X1 < r.X1 && r.Y0 < q.Y0 && q.Y1 < r.Y1 + return r.X0 <= q.X0 && q.X1 <= r.X1 && r.Y0 <= q.Y0 && q.Y1 <= r.Y1 } // Overlaps returns true if both rectangles overlap. @@ -574,10 +574,10 @@ func (r Rect) Overlaps(q Rect) bool { // Touches returns true if both rectangles touch (or overlap). func (r Rect) Touches(q Rect) bool { - if q.X1+Epsilon <= r.X0 || r.X1 <= q.X0-Epsilon { + if q.X1+Epsilon < r.X0 || r.X1 < q.X0-Epsilon { // left or right return false - } else if q.Y1+Epsilon <= r.Y0 || r.Y1 <= q.Y0-Epsilon { + } else if q.Y1+Epsilon < r.Y0 || r.Y1 < q.Y0-Epsilon { // below or above return false }