@@ -5,58 +5,58 @@ function distanceToIn_booleanunion(shape::BooleanUnion{T, SL, SR}, point::Point3
55 distB = distanceToIn (right, transformation * point, transformation * dir)
66 return min (distA, distB)
77end
8- # function distanceToIn_booleanintersection(shape::BooleanIntersection{T, SL, SR}, point::Point3{T}, dir::Vector3{T})::T where {T,SL,SR}
9- # (; left, right, transformation) = shape
10-
11- # positionA = inside(left, point)
12- # lpoint = transformation * point
13- # positionB = inside(right, lpoint)
14-
15- # inLeft = positionA == kInside
16- # inRight = positionB == kInside
17-
18- # inLeft && inRight && return T(-1)
19-
20- # dist = T(0)
21- # npoint = point
22- # ldir = transformation * dir
23- # # main loop
24- # while true
25- # d1 = d2 = 0
26- # if !inLeft
27- # d1 = distanceToIn(left, npoint, dir)
28- # d1 = max(d1, kTolerance(T))
29- # d1 == T(Inf) && return T(Inf)
30- # end
31- # if !inRight
32- # d2 = distanceToIn(right, lpoint, ldir)
33- # d2 = max(d2, kTolerance(T))
34- # d2 == T(Inf) && return T(Inf)
35- # end
36- # if d1 > d2
37- # # propagate to left shape
38- # dist += d1
39- # inleft = true
40- # npoint += d1 * dir
41- # lpoint = transformation * npoint
42- # # check if propagated point is inside right shape, check is done with a little push
43- # inRight = inside(right, lpoint + kTolerance(T) * ldir) == kInside
44- # inRight && return dist
45- # # here inleft=true, inright=false
46- # else
47- # # propagate to right shape
48- # dist += d2
49- # inright = true
50- # # check if propagated point is inside left shape, check is done with a little push
51- # npoint += d2 * dir
52- # lpoint = transformation * npoint
53- # inLeft = inside(left, npoint + kTolerance(T) * dir) == kInside
54- # inLeft && return dist
55- # end
56- # end
57- # return dist
58- # end
59- function distanceToIn_booleansubtraction (shape, point:: Point3{T} , dir) where T
8+ function distanceToIn_booleanintersection (shape:: BooleanIntersection{T, SL, SR} , point:: Point3{T} , dir:: Vector3{T} ):: T where {T,SL,SR}
9+ (; left, right, transformation) = shape
10+
11+ positionA = inside (left, point)
12+ lpoint = transformation * point
13+ positionB = inside (right, lpoint)
14+
15+ inLeft = positionA == kInside
16+ inRight = positionB == kInside
17+
18+ inLeft && inRight && return T (- 1 )
19+
20+ dist = T (0 )
21+ npoint = point
22+ ldir = transformation * dir
23+ # main loop
24+ while true
25+ d1 = d2 = 0
26+ if ! inLeft
27+ d1 = distanceToIn (left, npoint, dir)
28+ d1 = max (d1, kTolerance (T))
29+ d1 == T (Inf ) && return T (Inf )
30+ end
31+ if ! inRight
32+ d2 = distanceToIn (right, lpoint, ldir)
33+ d2 = max (d2, kTolerance (T))
34+ d2 == T (Inf ) && return T (Inf )
35+ end
36+ if d1 > d2
37+ # propagate to left shape
38+ dist += d1
39+ inleft = true
40+ npoint += d1 * dir
41+ lpoint = transformation * npoint
42+ # check if propagated point is inside right shape, check is done with a little push
43+ inRight = inside (right, lpoint + kTolerance (T) * ldir) == kInside
44+ inRight && return dist
45+ # here inleft=true, inright=false
46+ else
47+ # propagate to right shape
48+ dist += d2
49+ inright = true
50+ # check if propagated point is inside left shape, check is done with a little push
51+ npoint += d2 * dir
52+ lpoint = transformation * npoint
53+ inLeft = inside (left, npoint + kTolerance (T) * dir) == kInside
54+ inLeft && return dist
55+ end
56+ end
57+ return dist
58+ end
59+ function distanceToIn_booleansubtraction (shape:: BooleanSubtraction{T, SL, SR} , point:: Point3{T} , dir:: Vector3{T} ) :: T where {T,SL,SR}
6060 (; left, right, transformation) = shape
6161
6262 lpoint = transformation * point
0 commit comments