Skip to content

Comments

geometry: standardize is_in() semantics and optimize H-Polytope boundary checks#451

Open
Divinesoumyadip wants to merge 1 commit intoGeomScale:developfrom
Divinesoumyadip:fix/is-in-semantics
Open

geometry: standardize is_in() semantics and optimize H-Polytope boundary checks#451
Divinesoumyadip wants to merge 1 commit intoGeomScale:developfrom
Divinesoumyadip:fix/is-in-semantics

Conversation

@Divinesoumyadip
Copy link

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.

Copy link
Contributor

@Mohit-Lakra Mohit-Lakra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice - adding const and using const auto& are good improvements.

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.

2 participants