Skip to content

Commit 2f2a458

Browse files
committed
retain original performance
1 parent 13d2fab commit 2f2a458

File tree

3 files changed

+55
-148
lines changed

3 files changed

+55
-148
lines changed

src/Boolean.jl

Lines changed: 0 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -162,96 +162,3 @@ end
162162
function safetyToIn(shape::BooleanIntersection{T, SL, SR}, point::Point3{T})::T where {T,SL,SR}
163163
return 0
164164
end
165-
166-
function distanceToIn(shape::BooleanIntersection{T, SL, SR}, point::Point3{T}, dir::Vector3{T})::T where {T,SL,SR}
167-
(; left, right, transformation) = shape
168-
169-
positionA = inside(left, point)
170-
lpoint = transformation * point
171-
positionB = inside(right, lpoint)
172-
173-
inLeft = positionA == kInside
174-
inRight = positionB == kInside
175-
176-
inLeft && inRight && return T(-1)
177-
178-
dist = T(0)
179-
npoint = point
180-
ldir = transformation * dir
181-
# main loop
182-
while true
183-
d1 = d2 = 0
184-
if !inLeft
185-
d1 = distanceToIn(left, npoint, dir)
186-
d1 = max(d1, kTolerance(T))
187-
d1 == T(Inf) && return T(Inf)
188-
end
189-
if !inRight
190-
d2 = distanceToIn(right, lpoint, ldir)
191-
d2 = max(d2, kTolerance(T))
192-
d2 == T(Inf) && return T(Inf)
193-
end
194-
if d1 > d2
195-
# propagate to left shape
196-
dist += d1
197-
inleft = true
198-
npoint += d1 * dir
199-
lpoint = transformation * npoint
200-
# check if propagated point is inside right shape, check is done with a little push
201-
inRight = inside(right, lpoint + kTolerance(T) * ldir) == kInside
202-
inRight && return dist
203-
# here inleft=true, inright=false
204-
else
205-
# propagate to right shape
206-
dist += d2
207-
inright = true
208-
# check if propagated point is inside left shape, check is done with a little push
209-
npoint += d2 * dir
210-
lpoint = transformation * npoint
211-
inLeft = inside(left, npoint + kTolerance(T) * dir) == kInside
212-
inLeft && return dist
213-
end
214-
end
215-
return dist
216-
end
217-
218-
function distanceToIn(shape::BooleanSubtraction{T, SL, SR}, point::Point3{T}, dir::Vector3{T})::T where {T,SL,SR}
219-
(; left, right, transformation) = shape
220-
221-
lpoint = transformation * point
222-
ldir = transformation * dir
223-
positionB = inside(left, lpoint)
224-
inRight = positionB == kInside
225-
226-
npoint = point
227-
dist = T(0)
228-
229-
while true
230-
if inRight
231-
# propagate to outside of '- / RightShape'
232-
d1 = distanceToOut(right, lpoint, ldir)
233-
dist += (d1 >= 0 && d1 < Inf) ? d1 + kPushTolerance(T) : 0
234-
npoint = point + (dist + kPushTolerance(T)) * dir
235-
lpoint = transformation * npoint
236-
# now master outside 'B'; check if inside 'A'
237-
inside(left, npoint) == kInside && distanceToOut(left, npoint, dir) > kPushTolerance(T) && return dist
238-
end
239-
240-
# if outside of both we do a max operation master outside '-' and outside '+' ; find distances to both
241-
d2 = distanceToIn(left, npoint, dir)
242-
d2 = max(d2, 0)
243-
d2 == T(Inf) && return T(Inf)
244-
245-
d1 = distanceToIn(right, lpoint, ldir)
246-
if d2 < d1 - kTolerance(T)
247-
dist += d2 + kPushTolerance(T)
248-
return dist
249-
end
250-
251-
# propagate to '-'
252-
dist += (d1 >= 0 && d1 < Inf) ? d1 : 0
253-
npoint = point + (dist + kPushTolerance(T)) * dir
254-
lpoint = transformation * npoint
255-
inRight = true
256-
end
257-
end

src/DistanceIn.jl

Lines changed: 52 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -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)
77
end
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

src/DistanceOut.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#Boolean
2-
function distanceToOut_booleanunion(shape, point, dir::Vector3{T})::T where T
2+
function distanceToOut_booleanunion(shape::BooleanUnion{T, SL, SR}, point::Point3{T}, dir::Vector3{T})::T where {T,SL,SR}
33
(; left, right, transformation) = shape
44
dist = T(0)
55
positionA = inside(left, point)
@@ -54,13 +54,13 @@ function distanceToOut_booleanunion(shape, point, dir::Vector3{T})::T where T
5454
end
5555
end
5656
end
57-
function distanceToOut_booleanintersection(shape, point, dir::Vector3{T})::T where T
57+
function distanceToOut_booleanintersection(shape::BooleanIntersection{T, SL, SR}, point::Point3{T}, dir::Vector3{T})::T where {T,SL,SR}
5858
(; left, right, transformation) = shape
5959
distA = distanceToOut(left, point, dir)
6060
distB = distanceToOut(right, transformation * point, transformation * dir)
6161
return min(distA, distB)
6262
end
63-
function distanceToOut_booleansubtraction(shape, point, dir::Vector3{T})::T where T
63+
function distanceToOut_booleansubtraction(shape::BooleanSubtraction{T, SL, SR}, point::Point3{T}, dir::Vector3{T})::T where {T,SL,SR}
6464
(; left, right, transformation) = shape
6565
distA = distanceToOut(left, point, dir)
6666
distB = distanceToIn(right, transformation * point, transformation * dir)

0 commit comments

Comments
 (0)