Skip to content

Conversation

Jarvis-BOT-Equilateral-AI

Problem

Issue #4871 reported that ofRectangle::intersects() returns false for certain line segments that should intersect the rectangle.

Failing test case:

ofRectangle(0, 0, 100, 100).intersects(ofPoint(0, 50), ofPoint(50, 0))
// Returns false, but should return true

Both endpoints (0, 50) and (50, 0) lie exactly on the rectangle's boundaries, but inside() was using exclusive boundary checks (> and <) which incorrectly classified boundary points as outside.

Solution

Changed ofRectangle::inside() from exclusive to inclusive boundary checks:

Before:

return p.x > getMinX() && p.y > getMinY() &&
       p.x < getMaxX() && p.y < getMaxY();

After:

return p.x >= getMinX() && p.y >= getMinY() &&
       p.x <= getMaxX() && p.y <= getMaxY();

This is a minimal 2-character change that fixes the entire class of boundary-related bugs. In computational geometry, boundary points are typically considered "inside" closed shapes. The intersects() method already handles line-edge crossing detection, so recognizing boundary points as inside provides complete intersection coverage.

Testing

Added comprehensive unit tests in tests/types/rectangleTests/ covering:

All tests follow the existing OpenFrameworks ofxUnitTests framework pattern.

Impact

Standards Applied

This fix follows the C++ Geometric Algorithms Standard from Equilateral AI:

  • Use inclusive boundaries (>=, <=) for containment tests
  • Treat boundary points as inside closed shapes
  • Ensure symmetry in intersection detection

Full standard: https://github.com/Equilateral-AI/equilateral-open-standards/blob/main/cpp-geometric-algorithms-standard.md


🤖 Generated with assistance from Equilateral AI

This contribution was created with AI assistance and reviewed by human engineers.
Our agents follow the standards documented at:
https://github.com/Equilateral-AI/equilateral-open-standards

Our Contribution Policy: https://github.com/Equilateral-AI/equilateral-open-standards/blob/main/EQUILATERAL-AI-OSS-CONTRIBUTION-POLICY.md

Opt-out: If you prefer not to receive AI-assisted contributions,
please email [email protected]

Co-Authored-By: Jarvis (Equilateral AI) [email protected]

…meworks#4871)

Changes ofRectangle::inside() from exclusive (>, <) to inclusive (>=, <=)
boundary checks. This fixes intersects() failures when line segment
endpoints lie exactly on rectangle boundaries.

Test case from issue openframeworks#4871:
ofRectangle(0, 0, 100, 100).intersects(ofPoint(0, 50), ofPoint(50, 0))
now correctly returns true.

Added comprehensive unit tests in tests/types/rectangleTests/ covering:
- Corner points
- Edge points
- Interior points
- Exterior points
- Various line segment intersection cases

Rationale: In computational geometry, boundary points are typically
considered "inside" a closed shape. The intersects() method already
handles line-edge crossing detection, so endpoints on boundaries must
be recognized as inside for complete intersection coverage.

🤖 Generated with assistance from Equilateral AI

This contribution was created with AI assistance and reviewed by
human engineers. Our agents follow the standards documented at:
https://github.com/Equilateral-AI/equilateral-open-standards

Opt-out: If you prefer not to receive AI-assisted contributions,
please email [email protected]

Co-Authored-By: Jarvis (Equilateral AI) <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant