Skip to content

Commit

Permalink
Merge pull request #16 from JuliaRobotics/tk/staticarrays-compat
Browse files Browse the repository at this point in the history
Fix #15, error with latest StaticArrays due to dot change.
  • Loading branch information
tkoolen authored Jun 20, 2019
2 parents f6a6553 + 19489ae commit 526f46a
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
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

0 comments on commit 526f46a

Please sign in to comment.