|
2 | 2 | # Copyright 2017-2018, DLR Institute of System Dynamics and Control |
3 | 3 |
|
4 | 4 |
|
5 | | -const i16max = Int64(typemax(Int16)) |
6 | | -const i32max = Int64(typemax(Int32)) |
| 5 | +i16max()::Int64 = Int64(typemax(Int16)) |
| 6 | +i32max()::Int64 = Int64(typemax(Int32)) |
7 | 7 |
|
8 | | -pack16(i1::Integer, i2::Integer)::Integer = Int64(i1) + i16max*Int64(i2) |
| 8 | +pack16(i1::Int64, i2::Int64)::Int64 = Int64(i1) + i16max()*Int64(i2) |
9 | 9 |
|
10 | | -function pack(i1::Integer, i2::Integer,i3::Integer,i4::Integer)::Integer |
| 10 | +function pack(i1::Int64, i2::Int64,i3::Int64,i4::Int64)::Int64 |
11 | 11 | @assert(i1 >= 0 && i1 <= typemax(Int16)) |
12 | 12 | @assert(i2 >= 0 && i2 <= typemax(Int16)) |
13 | 13 | @assert(i3 >= 0 && i3 <= typemax(Int16)) |
14 | 14 | @assert(i4 >= 0 && i4 <= typemax(Int16)) |
15 | | - return pack16(i1,i2) + i32max*pack16(i3,i4) |
| 15 | + return pack16(i1,i2) + i32max()*pack16(i3,i4) |
16 | 16 | end |
17 | 17 |
|
18 | 18 |
|
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()) |
22 | 22 | return (i1,i2) |
23 | 23 | end |
24 | 24 |
|
25 | 25 |
|
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()) |
29 | 29 | return (i1,i2) |
30 | 30 | end |
31 | 31 |
|
32 | 32 |
|
33 | | -function unpack(i::Int64) |
| 33 | +function unpack(i::Int64)::Tuple{Int64, Int64, Int64, Int64} |
34 | 34 | @assert(i >= 0 && i <= typemax(Int64)) |
35 | 35 | (tmp1,tmp2) = unpack32(i) |
36 | 36 | (i1,i2) = unpack16(tmp1) |
|
41 | 41 |
|
42 | 42 | ### -------------------computation of pairID ----------------------------------- |
43 | 43 | ### 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 |
45 | 46 | if is < js |
46 | | - return pack(is,i,js,j) |
| 47 | + p = pack(is,i,js,j) |
47 | 48 | elseif is > js |
48 | | - return pack(js,j,is,i) |
| 49 | + p = pack(js,j,is,i) |
49 | 50 | else |
50 | 51 | error("from orderPositions: is == js.") |
51 | | -end; end |
| 52 | + end |
| 53 | + return p |
| 54 | +end |
52 | 55 |
|
53 | 56 | #getPositionsOfObj(scene::Composition.Scene, obj::Composition.Object3D, |
54 | 57 | # movablePos::Nothing) = (false, 0, 0) |
|
63 | 66 |
|
64 | 67 | function computePairID(scene::Composition.Scene, |
65 | 68 | actObj::Composition.Object3D, nextObj::Composition.Object3D, |
66 | | - is, i, js, j)::Integer |
| 69 | + is::Int64, i::Int64, js::Int64, j::Int64)::Int64 |
67 | 70 | # is: actual super - object |
68 | 71 | # js: subsequent super - object |
69 | 72 | # i: Object3D of is_th super - object |
70 | 73 | # j: Object3D of js_th super - object |
71 | 74 | (isSetAct, isPosActSuper, iPosActObj) = getPositionsOfObj(scene, actObj, actObj.interactionManner.movablePos) |
72 | 75 | (isSetNext, jsPosNextSuper, jPosNextObj) = getPositionsOfObj(scene, nextObj, nextObj.interactionManner.movablePos) |
| 76 | + pairID = 0 |
73 | 77 | if isSetAct && isSetNext |
74 | | - return orderPositions(isPosActSuper,iPosActObj,jsPosNextSuper,jPosNextObj) |
| 78 | + pairID = orderPositions(isPosActSuper,iPosActObj,jsPosNextSuper,jPosNextObj) |
75 | 79 | elseif isSetAct && !isSetNext |
76 | | - return orderPositions(isPosActSuper,iPosActObj,js,j) |
| 80 | + pairID = orderPositions(isPosActSuper,iPosActObj,js,j) |
77 | 81 | elseif isSetNext && !isSetAct |
78 | | - return orderPositions(is,i,jsPosNextSuper,jPosNextObj) |
| 82 | + pairID = orderPositions(is,i,jsPosNextSuper,jPosNextObj) |
79 | 83 | 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