Skip to content

Commit 2b062a5

Browse files
committed
improve utilitiesPairID.jl (of no effect of allocation)
1 parent fbd9a9d commit 2b062a5

File tree

2 files changed

+29
-23
lines changed

2 files changed

+29
-23
lines changed

src/contactDetection/ContactDetectionMPR/handler.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ function computeDistances(scene::Composition.Scene{F}, ch::Composition.ContactDe
145145
n += 1
146146
nextObj = nextSuperObj[j]
147147
nextAABB = nextSuperAABB[j]
148-
pairID = computePairID(scene, actObj, nextObj, is,i,js,j)
148+
pairID::Int64 = computePairID(scene, actObj, nextObj, is,i,js,j)
149149

150150
storeDistancesForSolver!(world, pairID, ch, actObj, nextObj,
151151
actAABB, nextAABB, phase2, hasEvent)

src/contactDetection/ContactDetectionMPR/utilitiesPairID.jl

Lines changed: 28 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,35 +2,35 @@
22
# Copyright 2017-2018, DLR Institute of System Dynamics and Control
33

44

5-
const i16max = Int64(typemax(Int16))
6-
const i32max = Int64(typemax(Int32))
5+
i16max()::Int64 = Int64(typemax(Int16))
6+
i32max()::Int64 = Int64(typemax(Int32))
77

8-
pack16(i1::Integer, i2::Integer)::Integer = Int64(i1) + i16max*Int64(i2)
8+
pack16(i1::Int64, i2::Int64)::Int64 = Int64(i1) + i16max()*Int64(i2)
99

10-
function pack(i1::Integer, i2::Integer,i3::Integer,i4::Integer)::Integer
10+
function pack(i1::Int64, i2::Int64,i3::Int64,i4::Int64)::Int64
1111
@assert(i1 >= 0 && i1 <= typemax(Int16))
1212
@assert(i2 >= 0 && i2 <= typemax(Int16))
1313
@assert(i3 >= 0 && i3 <= typemax(Int16))
1414
@assert(i4 >= 0 && i4 <= typemax(Int16))
15-
return pack16(i1,i2) + i32max*pack16(i3,i4)
15+
return pack16(i1,i2) + i32max()*pack16(i3,i4)
1616
end
1717

1818

19-
function unpack16(i::Int64)
20-
i1 = rem(i,i16max)
21-
i2 = div(i-i1, i16max)
19+
function unpack16(i::Int64)::Tuple{Int64, Int64}
20+
i1 = rem(i,i16max())
21+
i2 = div(i-i1, i16max())
2222
return (i1,i2)
2323
end
2424

2525

26-
function unpack32(i::Int64)
27-
i1 = rem(i,i32max)
28-
i2 = div(i-i1, i32max)
26+
function unpack32(i::Int64)::Tuple{Int64, Int64}
27+
i1 = rem(i,i32max())
28+
i2 = div(i-i1, i32max())
2929
return (i1,i2)
3030
end
3131

3232

33-
function unpack(i::Int64)
33+
function unpack(i::Int64)::Tuple{Int64, Int64, Int64, Int64}
3434
@assert(i >= 0 && i <= typemax(Int64))
3535
(tmp1,tmp2) = unpack32(i)
3636
(i1,i2) = unpack16(tmp1)
@@ -41,14 +41,17 @@ end
4141

4242
### -------------------computation of pairID -----------------------------------
4343
### it returns a unique ID
44-
function orderPositions(is,i,js,j)::Integer
44+
function orderPositions(is::Int64, i::Int64, js::Int64, j::Int64)::Int64
45+
p = 0
4546
if is < js
46-
return pack(is,i,js,j)
47+
p = pack(is,i,js,j)
4748
elseif is > js
48-
return pack(js,j,is,i)
49+
p = pack(js,j,is,i)
4950
else
5051
error("from orderPositions: is == js.")
51-
end; end
52+
end
53+
return p
54+
end
5255

5356
#getPositionsOfObj(scene::Composition.Scene, obj::Composition.Object3D,
5457
# movablePos::Nothing) = (false, 0, 0)
@@ -63,19 +66,22 @@ end
6366

6467
function computePairID(scene::Composition.Scene,
6568
actObj::Composition.Object3D, nextObj::Composition.Object3D,
66-
is, i, js, j)::Integer
69+
is::Int64, i::Int64, js::Int64, j::Int64)::Int64
6770
# is: actual super - object
6871
# js: subsequent super - object
6972
# i: Object3D of is_th super - object
7073
# j: Object3D of js_th super - object
7174
(isSetAct, isPosActSuper, iPosActObj) = getPositionsOfObj(scene, actObj, actObj.interactionManner.movablePos)
7275
(isSetNext, jsPosNextSuper, jPosNextObj) = getPositionsOfObj(scene, nextObj, nextObj.interactionManner.movablePos)
76+
pairID = 0
7377
if isSetAct && isSetNext
74-
return orderPositions(isPosActSuper,iPosActObj,jsPosNextSuper,jPosNextObj)
78+
pairID = orderPositions(isPosActSuper,iPosActObj,jsPosNextSuper,jPosNextObj)
7579
elseif isSetAct && !isSetNext
76-
return orderPositions(isPosActSuper,iPosActObj,js,j)
80+
pairID = orderPositions(isPosActSuper,iPosActObj,js,j)
7781
elseif isSetNext && !isSetAct
78-
return orderPositions(is,i,jsPosNextSuper,jPosNextObj)
82+
pairID = orderPositions(is,i,jsPosNextSuper,jPosNextObj)
7983
else
80-
return orderPositions(is,i,js,j)
81-
end; end
84+
pairID = orderPositions(is,i,js,j)
85+
end
86+
return pairID
87+
end

0 commit comments

Comments
 (0)