Repository navigation
ofRectangle::inside(): include points on the edge (fixes #4871, clean version of #8475) - #8584
Merged
danoli3 merged 2 commits intoOct 13, 2026
Merged
Conversation
inside() used exclusive bounds (> and <), so points exactly on an edge
or corner were outside. intersects(p0, p1) relies on inside() for its
endpoints, so a segment whose endpoints both lie on the boundary, e.g.
ofRectangle(0, 0, 100, 100).intersects({0, 50}, {50, 0})
returned false. inside() now uses inclusive bounds (>= and <=).
Cherry-picked from openframeworks#8475 (a674147).
The inside() docs said points on the edge are outside; update them to match the inclusive bounds. Add the tests from openframeworks#8475 to the existing tests/types/ofRectangleTests app (it already has addons.make with ofxUnitTests) instead of a new rectangleTests folder, which could not find ofxUnitTests.h. Corner and edge names now use OF's y-down coordinates. Also test segments that lie along part of an edge or touch the rectangle from outside, which intersects(p0, p1) missed before; the exact segment from openframeworks#4871 already passes on master because ofLineSegmentIntersection counts endpoints on an edge. intersects(rect) is unchanged: rectangles sharing only an edge still do not intersect.
Member
Author
|
updated and merged with Qwen |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Clean version of #8475, fixing the issues raised there. Fixes #4871.
Change
ofRectangle::inside(p): inclusive bounds (>=/<=), so points on an edge or corner are inside. This is the core change from fix: Use inclusive boundaries in ofRectangle::inside() (Issue #4871) #8475, cherry-picked with its original author.ofRectangle.h: theinside()docs said edge points are outside; they now say edge points are inside.tests/types/ofRectangleTestsapp instead of a newrectangleTestsfolder. That folder had noaddons.make, soofxUnitTests.hwasn't found. Corner and edge names now use OF's y-down coordinates ((0,0)is top-left).What it fixes
intersects(p0, p1)checks whether either endpoint isinside(), then checks for crossings with each edge. With exclusive bounds it missed segments that only touch the boundary:The exact segment from #4871,
({0, 50}, {50, 0}), already returnstrueon master, becauseofLineSegmentIntersectioncounts an endpoint lying on an edge. The cases above still fail on master.Tested (macOS,
make RunDebug, as in CI)ofRectangleTestsBehaviour change
inside()now returnstruefor points on the edge, andinside(rect)returnstruefor a rectangle that shares an edge, including an identical rectangle.Callers that use
inside()for mouse hit-testing (ofxGui,ofEasyCam) now also count the edge pixel. AdjacentofxGuicontrols that share an edge can both match a click exactly on the shared edge.intersects(ofRectangle)is unchanged: rectangles that only share an edge still don't intersect.Original description from #8475 (by @Jarvis-BOT-Equilateral-AI)