fix: Use inclusive boundaries in ofRectangle::inside() (Issue #4871) #8475
      
        
          +79
        
        
          −2
        
        
          
        
      
    
  
  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.
  
    
  
    
Problem
Issue #4871 reported that
ofRectangle::intersects()returnsfalsefor certain line segments that should intersect the rectangle.Failing test case:
Both endpoints
(0, 50)and(50, 0)lie exactly on the rectangle's boundaries, butinside()was using exclusive boundary checks (>and<) which incorrectly classified boundary points as outside.Solution
Changed
ofRectangle::inside()from exclusive to inclusive boundary checks:Before:
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
ofxUnitTestsframework pattern.Impact
>=and<=)Standards Applied
This fix follows the C++ Geometric Algorithms Standard from Equilateral AI:
>=,<=) for containment testsFull 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]