geometry: standardize is_in() semantics and optimize H-Polytope boundary checks#451
Open
Divinesoumyadip wants to merge 1 commit intoGeomScale:developfrom
Open
geometry: standardize is_in() semantics and optimize H-Polytope boundary checks#451Divinesoumyadip wants to merge 1 commit intoGeomScale:developfrom
Divinesoumyadip wants to merge 1 commit intoGeomScale:developfrom
Conversation
Mohit-Lakra
suggested changes
Feb 21, 2026
Contributor
Mohit-Lakra
left a comment
There was a problem hiding this comment.
Found broken callers in hpolytope.h (Need little fixes)
Comment on lines
+327
to
+331
| int is_in(Point const& p, NT tol=NT(0)) const { | ||
| Eigen::Matrix<NT, Eigen::Dynamic, 1> res = A * p.getCoefficients() - b; | ||
| NT max_val = res.maxCoeff(); | ||
| if (max_val > tol) return 1; | ||
| return (max_val >= -tol) ? 0 : -1; |
Contributor
There was a problem hiding this comment.
This breaks ComputeInnerBall()
if (is_in(Point(...)) == 0 || ...)
Old: == 0 meant outside (correct)
New: == 0 means boundary (wrong - accepts invalid inner balls)
Also,
The old loop had early exit on first violation. This always computes full A*p and allocates temp vector.
| if (g(p) > NT(-tol)) return 0; | ||
| int is_in(Point const& p, NT tol=NT(0)) const { | ||
| NT max_val = -std::numeric_limits<NT>::max(); | ||
| for (const auto& g : gs) { |
Contributor
There was a problem hiding this comment.
Nice - adding const and using const auto& are good improvements.
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.
This PR standardizes the is_in return contract across Ball, ConvexBody, and HPolytope to return -1 for inside the body, 0 for the boundary within tolerance, and 1 for outside the body.
Key optimization includes replacing manual loops in HPolytope::is_in with Eigen's .maxCoeff() for faster violation detection in Ax <= b constraints. This ensures consistency across the library and prevents ambiguity in sampling algorithms.
These changes also implement a unified tolerance-based comparison to handle floating-point precision issues specifically at the geometric boundaries.