Skip to content

Commit

Permalink
Fix squared distance for CPU impl. (#83)
Browse files Browse the repository at this point in the history
Summary:
`PointLineDistanceForward()` should return squared distance. However, it seems that it returned non-squared distance when `v0` was near by `v1` in CPU implementation.
Pull Request resolved: #83

Reviewed By: bottler

Differential Revision: D20097181

Pulled By: nikhilaravi

fbshipit-source-id: 7ea851c0837ab89364e42d283c999df21ff5ff02
  • Loading branch information
takiyu authored and facebook-github-bot committed Feb 25, 2020
1 parent a0f3dc2 commit f358b9b
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion pytorch3d/csrc/rasterize_meshes/geometry_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ T PointLineDistanceForward(
const vec2<T> v1v0 = v1 - v0;
const T l2 = dot(v1v0, v1v0);
if (l2 <= kEpsilon) {
return sqrt(dot(p - v1, p - v1));
return dot(p - v1, p - v1);
}

const T t = dot(v1v0, p - v0) / l2;
Expand Down
4 changes: 2 additions & 2 deletions pytorch3d/renderer/mesh/rasterize_meshes.py
Original file line number Diff line number Diff line change
Expand Up @@ -445,8 +445,8 @@ def point_line_distance(p, v0, v1):

v1v0 = v1 - v0
l2 = v1v0.dot(v1v0) # |v1 - v0|^2
if l2 == 0.0:
return torch.sqrt((p - v1).dot(p - v1)) # v0 == v1
if l2 <= kEpsilon:
return (p - v1).dot(p - v1) # v0 == v1

t = (v1v0).dot(p - v0) / l2
t = torch.clamp(t, min=0.0, max=1.0)
Expand Down

0 comments on commit f358b9b

Please sign in to comment.