Skip to content

Commit

Permalink
Contains also means on the boundary
Browse files Browse the repository at this point in the history
  • Loading branch information
tdewolff committed Jan 6, 2025
1 parent 6efb2b9 commit 0471c8b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
5 changes: 4 additions & 1 deletion path.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
10 changes: 5 additions & 5 deletions util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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.
Expand All @@ -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
}
Expand Down

0 comments on commit 0471c8b

Please sign in to comment.