Skip to content

Commit 7456ce2

Browse files
authored
Fix normal orientation in surfaces for OpenPrimitives (#591)
1 parent 3415570 commit 7456ce2

File tree

8 files changed

+31
-78
lines changed

8 files changed

+31
-78
lines changed

src/ConstructiveSolidGeometry/SurfacePrimitives/TorusMantle.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@ end
7979

8080
flip(t::TorusMantle{T,TP,TT,:inwards}) where {T,TP,TT} =
8181
TorusMantle{T,TP,TT,:outwards}(t.r_torus, t.r_tube, t.φ, t.θ, t.origin, t.rotation )
82+
flip(t::TorusMantle{T,TP,TT,:outwards}) where {T,TP,TT} =
83+
TorusMantle{T,TP,TT,:inwards}(t.r_torus, t.r_tube, t.φ, t.θ, t.origin, t.rotation )
8284

8385
get_φ_limits(tm::TorusMantle{T,T}) where {T} = T(0), tm.φ
8486
get_φ_limits(tm::TorusMantle{T,Nothing}) where {T} = T(0), T(2π)

src/ConstructiveSolidGeometry/VolumePrimitives/Box.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ function sample(b::Box{T})::Vector{CartesianPoint{T}} where {T}
158158
[vertices(b)...]
159159
end
160160

161-
function surfaces(b::Box{T}) where {T}
161+
function surfaces(b::Box{T,ClosedPrimitive}) where {T}
162162
vs = vertices(b)
163163
return (
164164
Quadrangle{T}((vs[1], vs[2], vs[3], vs[4])),

src/ConstructiveSolidGeometry/VolumePrimitives/Cone.jl

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ function _in(pt::CartesianPoint, c::Cylinder{T,OpenPrimitive}; csgtol::T = csg_d
147147
abs(pt.z) < c.hZ - csgtol && hypot(pt.x, pt.y) < c.r - csgtol
148148
end
149149

150-
function surfaces(t::Cylinder{T}) where {T}
150+
function surfaces(t::Cylinder{T,ClosedPrimitive}) where {T}
151151
bot_center_pt = _transform_into_global_coordinate_system(CartesianPoint{T}(zero(T), zero(T), -t.hZ), t)
152152
top_center_pt = _transform_into_global_coordinate_system(CartesianPoint{T}(zero(T), zero(T), +t.hZ), t)
153153
mantle = FullConeMantle{T,:inwards}((t.r, t.r), t.φ, t.hZ, t.origin, t.rotation)
@@ -180,7 +180,7 @@ function _in(pt::CartesianPoint, c::PartialCylinder{T,OpenPrimitive}; csgtol::T
180180
abs(pt.z) + csgtol < c.hZ && r < c.r - csgtol && _in_angular_interval_closed(φ, c.φ, csgtol = zero(T)) && r * sin(min(φ, c.φ - φ, T/2))) > csgtol
181181
end
182182

183-
function surfaces(t::PartialCylinder{T}) where {T}
183+
function surfaces(t::PartialCylinder{T,ClosedPrimitive}) where {T}
184184
bot_center_pt = _transform_into_global_coordinate_system(CartesianPoint{T}(zero(T), zero(T), -t.hZ), t)
185185
top_center_pt = _transform_into_global_coordinate_system(CartesianPoint{T}(zero(T), zero(T), +t.hZ), t)
186186
mantle = PartialConeMantle{T,:inwards}((t.r, t.r), t.φ, t.hZ, t.origin, t.rotation)
@@ -200,6 +200,7 @@ function surfaces(t::PartialCylinder{T}) where {T}
200200
(e_top, e_bot, mantle, poly_l, poly_r)
201201
end
202202

203+
203204
####################################################################
204205
####################################################################
205206

@@ -231,7 +232,7 @@ function _in(pt::CartesianPoint, c::VaryingCylinder{T,OpenPrimitive}; csgtol::T
231232
hypot(pt.x, pt.y) < radius_at_z(c.hZ, c.r[1][1], c.r[2][1], pt.z) - csgtol * hypot(2*c.hZ, c.r[2][1] - c.r[1][1]) / (2*c.hZ)
232233
end
233234

234-
function surfaces(t::VaryingCylinder{T}) where {T}
235+
function surfaces(t::VaryingCylinder{T,ClosedPrimitive}) where {T}
235236
bot_center_pt = _transform_into_global_coordinate_system(CartesianPoint{T}(zero(T), zero(T), -t.hZ), t)
236237
top_center_pt = _transform_into_global_coordinate_system(CartesianPoint{T}(zero(T), zero(T), +t.hZ), t)
237238
mantle = FullConeMantle{T,:inwards}((t.r[1][1], t.r[2][1]), t.φ, t.hZ, t.origin, t.rotation)
@@ -277,7 +278,7 @@ function _in(pt::CartesianPoint, c::PartialVaryingCylinder{T,OpenPrimitive}; csg
277278
_in_angular_interval_open(atan(pt.y, pt.x), c.φ, csgtol = zero(T)) && r * sin(min(φ, c.φ - φ, T/2))) > csgtol
278279
end
279280

280-
function surfaces(t::PartialVaryingCylinder{T}) where {T}
281+
function surfaces(t::PartialVaryingCylinder{T,ClosedPrimitive}) where {T}
281282
bot_center_pt = _transform_into_global_coordinate_system(CartesianPoint{T}(zero(T), zero(T), -t.hZ), t)
282283
top_center_pt = _transform_into_global_coordinate_system(CartesianPoint{T}(zero(T), zero(T), +t.hZ), t)
283284
mantle = PartialConeMantle{T,:inwards}((t.r[1][1], t.r[2][1]), t.φ, t.hZ, t.origin, t.rotation)
@@ -338,7 +339,7 @@ function _in(pt::CartesianPoint, c::VaryingTube{T,OpenPrimitive}; csgtol::T = cs
338339
r < radius_at_z(c.hZ, c.r[1][2], c.r[2][2], pt.z) - csgtol * hypot(2*c.hZ, c.r[2][2] - c.r[1][2]) / (2*c.hZ)
339340
end
340341

341-
function surfaces(t::VaryingTube{T}) where {T}
342+
function surfaces(t::VaryingTube{T,ClosedPrimitive}) where {T}
342343
bot_center_pt = _transform_into_global_coordinate_system(CartesianPoint{T}(zero(T), zero(T), -t.hZ), t)
343344
top_center_pt = _transform_into_global_coordinate_system(CartesianPoint{T}(zero(T), zero(T), +t.hZ), t)
344345
inner_mantle = FullConeMantle{T,:outwards}((t.r[1][1], t.r[2][1]), t.φ, t.hZ, t.origin, t.rotation)
@@ -389,7 +390,7 @@ function _in(pt::CartesianPoint, c::PartialVaryingTube{T,OpenPrimitive}; csgtol:
389390
r < radius_at_z(c.hZ, c.r[1][2], c.r[2][2], pt.z) - csgtol * hypot(2c.hZ, c.r[2][2] - c.r[1][2]) / 2c.hZ
390391
end
391392

392-
function surfaces(t::PartialVaryingTube{T}) where {T}
393+
function surfaces(t::PartialVaryingTube{T,ClosedPrimitive}) where {T}
393394
bot_center_pt = _transform_into_global_coordinate_system(CartesianPoint{T}(zero(T), zero(T), -t.hZ), t)
394395
top_center_pt = _transform_into_global_coordinate_system(CartesianPoint{T}(zero(T), zero(T), +t.hZ), t)
395396
inner_mantle = PartialConeMantle{T,:outwards}((t.r[1][1], t.r[2][1]), t.φ, t.hZ, t.origin, t.rotation)
@@ -427,15 +428,15 @@ function _in(pt::CartesianPoint, c::Cone{T,CO,Tuple{Tuple{Nothing,T},Nothing}};
427428
_in(pt, Cone{T,CO}(((c.r[1][2],), (zero(T),)), c.φ, c.hZ, c.origin, c.rotation); csgtol)
428429
end
429430

430-
function surfaces(t::UpwardCone{T}) where {T}
431+
function surfaces(t::UpwardCone{T,ClosedPrimitive}) where {T}
431432
bot_center_pt = _transform_into_global_coordinate_system(CartesianPoint{T}(zero(T), zero(T), -t.hZ), t)
432433
outer_mantle = FullConeMantle{T,:inwards}( (t.r[1][2], zero(T)), t.φ, t.hZ, t.origin, t.rotation)
433434
e_bot = EllipticalSurface{T}(r = t.r[1][2], φ = t.φ, origin = bot_center_pt, rotation = t.rotation)
434435
# normals of the surfaces show inside the volume primitives.
435436
e_bot, outer_mantle
436437
end
437438

438-
function surfaces(t::PartialUpwardCone{T}) where {T}
439+
function surfaces(t::PartialUpwardCone{T,ClosedPrimitive}) where {T}
439440
bot_center_pt = _transform_into_global_coordinate_system(CartesianPoint{T}(zero(T), zero(T), -t.hZ), t)
440441
outer_mantle = PartialConeMantle{T,:inwards}( (t.r[1][2], zero(T)), t.φ, t.hZ, t.origin, t.rotation)
441442
e_bot = EllipticalSurface{T}(r = t.r[1][2], φ = t.φ, origin = bot_center_pt, rotation = t.rotation)
@@ -469,15 +470,15 @@ function _in(pt::CartesianPoint, c::Cone{T,CO,Tuple{Nothing,Tuple{Nothing,T}}};
469470
_in(pt, Cone{T,CO}(((zero(T),), (c.r[2][2],)), c.φ, c.hZ, c.origin, c.rotation); csgtol)
470471
end
471472

472-
function surfaces(t::DownwardCone{T}) where {T}
473+
function surfaces(t::DownwardCone{T,ClosedPrimitive}) where {T}
473474
top_center_pt = _transform_into_global_coordinate_system(CartesianPoint{T}(zero(T), zero(T), +t.hZ), t)
474475
outer_mantle = FullConeMantle{T,:inwards}( (zero(T), t.r[2][2]), t.φ, t.hZ, t.origin, t.rotation)
475476
e_top = EllipticalSurface{T}(r = t.r[2][2], φ = t.φ, origin = top_center_pt, rotation = -t.rotation * RotZ{T}(π))
476477
# normals of the surfaces show inside the volume primitives.
477478
e_top, outer_mantle
478479
end
479480

480-
function surfaces(t::PartialDownwardCone{T}) where {T}
481+
function surfaces(t::PartialDownwardCone{T,ClosedPrimitive}) where {T}
481482
bot_center_pt = _transform_into_global_coordinate_system(CartesianPoint{T}(zero(T), zero(T), -t.hZ), t)
482483
outer_mantle = PartialConeMantle{T,:inwards}( (t.r[2][2], zero(T)), t.φ, t.hZ, t.origin, t.rotation)
483484
e_bot = EllipticalSurface{T}(r = t.r[2][2], φ = t.φ, origin = bot_center_pt, rotation = t.rotation)
@@ -512,7 +513,7 @@ function _in(pt::CartesianPoint, c::Cone{T,CO,Tuple{Tuple{T,T},T}}; csgtol::T =
512513
_in(pt, Cone{T,CO}((c.r[1], (c.r[2], c.r[2])), c.φ, c.hZ, c.origin, c.rotation); csgtol)
513514
end
514515

515-
function surfaces(t::TopClosedTube{T}) where {T}
516+
function surfaces(t::TopClosedTube{T,ClosedPrimitive}) where {T}
516517
bot_center_pt = _transform_into_global_coordinate_system(CartesianPoint{T}(zero(T), zero(T), -t.hZ), t)
517518
# top_center_pt = _transform_into_global_coordinate_system(CartesianPoint{T}(zero(T), zero(T), +t.hZ), t)
518519
inner_mantle = FullConeMantle{T,:outwards}((t.r[1][1], t.r[2]), t.φ, t.hZ, t.origin, t.rotation)
@@ -523,7 +524,7 @@ function surfaces(t::TopClosedTube{T}) where {T}
523524
e_bot, inner_mantle, outer_mantle
524525
end
525526

526-
function surfaces(t::PartialTopClosedTube{T}) where {T}
527+
function surfaces(t::PartialTopClosedTube{T,ClosedPrimitive}) where {T}
527528
bot_center_pt = _transform_into_global_coordinate_system(CartesianPoint{T}(zero(T), zero(T), -t.hZ), t)
528529
# top_center_pt = _transform_into_global_coordinate_system(CartesianPoint{T}(zero(T), zero(T), +t.hZ), t)
529530
inner_mantle = PartialConeMantle{T,:outwards}((t.r[1][1], t.r[2]), t.φ, t.hZ, t.origin, t.rotation)
@@ -562,7 +563,7 @@ function _in(pt::CartesianPoint, c::Cone{T,CO,Tuple{T,Tuple{T,T}}}; csgtol::T =
562563
_in(pt, Cone{T,CO}(((c.r[1], c.r[1]), c.r[2]), c.φ, c.hZ, c.origin, c.rotation); csgtol)
563564
end
564565

565-
function surfaces(t::BottomClosedTube{T}) where {T}
566+
function surfaces(t::BottomClosedTube{T,ClosedPrimitive}) where {T}
566567
# bot_center_pt = _transform_into_global_coordinate_system(CartesianPoint{T}(zero(T), zero(T), -t.hZ), t)
567568
top_center_pt = _transform_into_global_coordinate_system(CartesianPoint{T}(zero(T), zero(T), +t.hZ), t)
568569
inner_mantle = FullConeMantle{T,:outwards}((t.r[1], t.r[2][1]), t.φ, t.hZ, t.origin, t.rotation)
@@ -573,7 +574,7 @@ function surfaces(t::BottomClosedTube{T}) where {T}
573574
e_top, inner_mantle, outer_mantle
574575
end
575576

576-
function surfaces(t::PartialBottomClosedTube{T}) where {T}
577+
function surfaces(t::PartialBottomClosedTube{T,ClosedPrimitive}) where {T}
577578
# bot_center_pt = _transform_into_global_coordinate_system(CartesianPoint{T}(zero(T), zero(T), -t.hZ), t)
578579
top_center_pt = _transform_into_global_coordinate_system(CartesianPoint{T}(zero(T), zero(T), +t.hZ), t)
579580
inner_mantle = PartialConeMantle{T,:outwards}((t.r[1], t.r[2][1]), t.φ, t.hZ, t.origin, t.rotation)

src/ConstructiveSolidGeometry/VolumePrimitives/Ellipsoid.jl

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -146,9 +146,5 @@ function surfaces(e::Ellipsoid{T,ClosedPrimitive}) where {T}
146146
em = EllipsoidMantle{T,typeof(e.r),typeof(e.φ),typeof(e.θ),:inwards}(e.r, e.φ, e.θ, e.origin, e.rotation)
147147
(em,)
148148
end
149-
function surfaces(e::Ellipsoid{T,OpenPrimitive}) where {T}
150-
em = EllipsoidMantle{T,typeof(e.r),typeof(e.φ),typeof(e.θ),:outwards}(e.r, e.φ, e.θ, e.origin, e.rotation)
151-
(em,)
152-
end
153149

154150
extremum(e::Ellipsoid{T}) where {T} = max(e.r...)

src/ConstructiveSolidGeometry/VolumePrimitives/Polycone.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ function _in(pt::CartesianPoint{T}, c::Polycone{<:Any, OpenPrimitive}; csgtol::T
137137
PolygonOps.inpolygon((hypot(pt.x, pt.y), pt.z), tuple.(c.r, c.z), in = true, on = iszero(pt.x) && iszero(pt.y), out = false)
138138
end
139139

140-
function surfaces(c::Polycone{T,<:Any,N,Nothing}) where {T,N}
140+
function surfaces(c::Polycone{T,ClosedPrimitive,N,Nothing}) where {T,N}
141141
s = []
142142
@inbounds for i in Base.OneTo(N-1)
143143
r1::T = c.r[i]

src/ConstructiveSolidGeometry/VolumePrimitives/RegularPrism.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ function vertices(rp::RegularPrism{N,T,OpenPrimitive,T}) where {T,N}
140140
_transform_into_global_coordinate_system(pts, rp)
141141
end
142142

143-
function surfaces(rp::RegularPrism{N,T,<:Any,T}) where {T,N}
143+
function surfaces(rp::RegularPrism{N,T,ClosedPrimitive,T}) where {T,N}
144144
vs = (vertices(rp))
145145
p_bot = Polygon{N,T}(vs[1:N])
146146
p_top = Polygon{N,T}(reverse(vs[N+1:end]))

0 commit comments

Comments
 (0)