Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #15, error with latest StaticArrays due to dot change. #16

Merged
merged 3 commits into from
Jun 20, 2019
Merged
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
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ notifications:
email: false
matrix:
allow_failures:
- julia: 1.0 # because of https://github.com/JuliaRobotics/EnhancedGJK.jl/pull/16#issuecomment-503319584
- julia: nightly
branches:
only:
Expand Down
20 changes: 16 additions & 4 deletions src/gjk.jl
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,18 @@ end
transform_simplex_impl(N, cache, poseA, poseB)
end

# Note: it looks like this can be replaced with transpose(weights) * points in Julia 1.3 (before that, it's a lot slower)
@generated function linear_combination(weights::StaticVector{N}, points::StaticVector{N}) where {N}
expr = :(weights[1] * points[1])
for i = 2 : N
expr = :($expr + weights[$i] * points[$i])
end
return quote
Base.@_inline_meta
$expr
end
end

function transform_simplex_impl(N, cache, poseA, poseB)
Expr(:call, :(SVector),
[:((poseA(value(cache.simplex_points[$i].a)) -
Expand Down Expand Up @@ -92,11 +104,11 @@ function gjk!(cache::CollisionCache,
# in collision
return GJKResult(
simplex,
dot(weights, cache.simplex_points),
linear_combination(weights, cache.simplex_points),
penetration_distance(simplex)
)
end
best_point = dot(weights, simplex)
best_point = linear_combination(weights, simplex)

direction = -best_point
direction_in_A = rotAinv * direction
Expand Down Expand Up @@ -126,7 +138,7 @@ function gjk!(cache::CollisionCache,
if score <= dot(best_point, direction) + atol || iter >= max_iter
return GJKResult(
simplex,
dot(weights, cache.simplex_points),
linear_combination(weights, cache.simplex_points),
norm(best_point)
)
else
Expand All @@ -142,7 +154,7 @@ function penetration_distance(simplex)
_, penetration_distance = gt.argmax(1:length(simplex)) do i
face = simplex_face(simplex, i)
weights = projection_weights(face)
closest_point = dot(weights, face)
closest_point = linear_combination(weights, face)
distance_to_face = norm(closest_point)
-distance_to_face
end
Expand Down
4 changes: 2 additions & 2 deletions src/reference_distance.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module ReferenceDistance

using GeometryTypes
import EnhancedGJK: projection_weights
import EnhancedGJK: projection_weights, linear_combination
import StaticArrays: SVector
using LinearAlgebra

Expand Down Expand Up @@ -33,7 +33,7 @@ end
function exterior_distance(face_points, target)
simplex = convert(SVector, Simplex(face_points)) .- SVector((target,))
weights = projection_weights(simplex)
projected = dot(weights, simplex)
projected = linear_combination(weights, simplex)
norm(projected)
end

Expand Down