Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions include/convex_bodies/ball.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,10 @@ class Ball{
return c.dimension();
}

int is_in(Point const& p) const
{
if (p.squared_length() <= R)
return -1;
else return 0;
int is_in(Point const& p, NT tol = NT(0)) const {
NT diff = (p - c).squared_length() - R;
if (diff > tol) return 1;
return (diff >= -tol) ? 0 : -1;
}

std::pair<NT,NT> line_intersect(Point const& r, Point const& v) const
Expand Down
11 changes: 7 additions & 4 deletions include/convex_bodies/convex_body.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,14 @@ class ConvexBody {
}

// Check if point is in K
int is_in(Point const& p, NT tol=NT(0)) {
for (func g : gs) {
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.

NT val = g(p);
if (val > tol) return 1;
if (val > max_val) max_val = val;
}
return -1;
return (max_val >= -tol) ? 0 : -1;
}

};
Expand Down
18 changes: 5 additions & 13 deletions include/convex_bodies/hpolytope.h
Original file line number Diff line number Diff line change
Expand Up @@ -324,19 +324,11 @@ class HPolytope {


//Check if Point p is in H-polytope P:= Ax<=b
int is_in(Point const& p, NT tol=NT(0)) const
{
int m = A.rows();
const NT* b_data = b.data();

for (int i = 0; i < m; i++) {
//Check if corresponding hyperplane is violated
if (*b_data - A.row(i) * p.getCoefficients() < NT(-tol))
return 0;

b_data++;
}
return -1;
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;
Comment on lines +327 to +331
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.

}

// compute intersection point of ray starting from r and pointing to v
Expand Down