Skip to content

Commit d63fee3

Browse files
committed
introduce MPRFloatType for ContactDetectionMPR_handler
1 parent 735e716 commit d63fee3

File tree

3 files changed

+31
-36
lines changed

3 files changed

+31
-36
lines changed

src/Modia3D.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,8 @@ convertAndStripUnit(TargetType, requiredUnit, value) =
9494
numberType(value) <: Unitful.AbstractQuantity && unit.(value) != Unitful.NoUnits ?
9595
convert(TargetType, ustrip.( uconvert.(requiredUnit, value))) : convert(TargetType, value)
9696

97-
97+
# MPRFloatType is used to change betweeen Double64 and Float64 for mpr calculations
98+
const MPRFloatType = Float64
9899

99100
# Include sub-modules
100101
include(joinpath("Frames" , "_module.jl"))

src/contactDetection/ContactDetectionMPR/ContactDetectionMPR_handler.jl

Lines changed: 27 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -108,37 +108,31 @@ about the contact situation.
108108
- `neps`: Small number used to check whether a floating number is close to zero (> 0.0).
109109
110110
"""
111-
mutable struct ContactDetectionMPR_handler <: Modia3D.AbstractContactDetection
112-
contactPairs::Composition.ContactPairs
113-
distanceComputed::Bool
114-
115-
lastContactDict::Dict{PairID,ContactPair}
116-
contactDict::Dict{ PairID,ContactPair}
117-
noContactMinVal::Float64
118-
119-
tol_rel::Float64
120-
niter_max::Int
121-
neps::Float64
122-
123-
# Visualization options
124-
visualizeContactPoints::Bool
125-
visualizeSupportPoints::Bool
126-
defaultContactSphereDiameter::Float64
127-
128-
function ContactDetectionMPR_handler(;tol_rel = 1.0e-7,
129-
niter_max = 100 ,
130-
neps = sqrt(eps()))
131-
@assert(tol_rel > 0.0)
132-
@assert(niter_max > 0)
133-
@assert(neps > 0.0)
134-
handler = new()
135-
handler.distanceComputed = false
136-
handler.lastContactDict = Dict{PairID,ContactPair}()
137-
handler.contactDict = Dict{PairID,ContactPair}()
138-
handler.noContactMinVal = 42.0
139-
handler.tol_rel = tol_rel
140-
handler.niter_max = niter_max
141-
handler.neps = neps
142-
return handler
143-
end
111+
mutable struct ContactDetectionMPR_handler{T} <: Modia3D.AbstractContactDetection
112+
distanceComputed::Bool
113+
114+
lastContactDict::Dict{PairID,ContactPair}
115+
contactDict::Dict{ PairID,ContactPair}
116+
noContactMinVal::Float64
117+
118+
tol_rel::T
119+
niter_max::Int
120+
neps::T
121+
122+
contactPairs::Composition.ContactPairs
123+
124+
# Visualization options
125+
visualizeContactPoints::Bool
126+
visualizeSupportPoints::Bool
127+
defaultContactSphereDiameter::Float64
128+
129+
function ContactDetectionMPR_handler{T}(;tol_rel = 1.0e-7,
130+
niter_max = 100 ,
131+
neps = sqrt(eps(T))) where {T}
132+
@assert(tol_rel > 0.0)
133+
@assert(niter_max > 0)
134+
@assert(neps > 0.0)
135+
new(false, Dict{PairID,ContactPair}(), Dict{PairID,ContactPair}(), 42.0, tol_rel, niter_max, neps)
136+
end
144137
end
138+
ContactDetectionMPR_handler() = ContactDetectionMPR_handler{Modia3D.MPRFloatType}()

src/contactDetection/ContactDetectionMPR/handler.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ AABB_touching(aabb1::Basics.BoundingBox, aabb2::Basics.BoundingBox) = aabb1.x_ma
1212

1313

1414
function Composition.initializeContactDetection!(world::Composition.Object3D, scene::Composition.Scene)::Nothing
15-
if typeof(scene.options.contactDetection) == Modia3D.ContactDetectionMPR_handler
16-
ch::Modia3D.ContactDetectionMPR_handler = scene.options.contactDetection
15+
if typeof(scene.options.contactDetection) == Modia3D.ContactDetectionMPR_handler{Modia3D.MPRFloatType}
16+
ch = scene.options.contactDetection
1717
ch.contactPairs = Composition.ContactPairs(world, scene, ch.visualizeContactPoints,
1818
ch.visualizeSupportPoints, ch.defaultContactSphereDiameter)
1919
if ch.contactPairs.nz == 0

0 commit comments

Comments
 (0)