Skip to content

Commit

Permalink
Constraint fix.
Browse files Browse the repository at this point in the history
  • Loading branch information
mdavis36 committed Aug 4, 2021
1 parent 75b12f7 commit 1d39a9b
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/Utilities/pointDistances.hh
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ closestPointOnSegment(const Vector& p,
const auto ahat = a01*safeInv(a01mag);
const auto a0p = p - a0;
const auto ptest = a0p.dot(ahat);
return a0 + ptest*ahat;
return a0 + std::max(0.0, std::min(a01mag,ptest))*ahat;
}

// This version returns true if the closest point forms a right angle between
Expand All @@ -44,7 +44,7 @@ closestPointOnSegment(const Vector& p,
const auto ahat = a01*safeInv(a01mag);
const auto a0p = p - a0;
const auto ptest = a0p.dot(ahat);
result = a0 + ptest*ahat;
result = a0 + std::max(0.0, std::min(a01mag,ptest))*ahat;
return (ptest >= 0.0 and ptest <= a01mag);
}

Expand Down

0 comments on commit 1d39a9b

Please sign in to comment.