Skip to content

Commit

Permalink
Use csgtol in _in(::CartesianPoint{T}, ::Polycone{T})
Browse files Browse the repository at this point in the history
so far for the ClosedPrimitive
  • Loading branch information
fhagemann committed Jan 23, 2025
1 parent 806ee59 commit b92f3e2
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
20 changes: 19 additions & 1 deletion src/ConstructiveSolidGeometry/VolumePrimitives/Polycone.jl
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,27 @@ Polycone{T,CO,N,TP}( c::Polycone{T,CO,N,TP}; COT = CO,
####################################################################


function _inpolygon(pt::Tuple{T,T}, polygon::NTuple{N,Tuple{T,T}}; csgtol::T = csg_default_tol(T)) where {N,T <: Real}
# use the normal PolygonOps.inpolygon method to check if the point is inside
PolygonOps.inpolygon(pt, polygon, in = true, on = true, out = false) && return true
# if it is flagged as outside, check if the distance to any of the edges is smaller than csgtol
rp,zp = pt
@inbounds for i in Base.OneTo(N-1)
r1,z1 = polygon[i]
r2,z2 = polygon[i+1]
r1 == r2 && z1 == z2 && continue
s = clamp(((zp - z1) * (z2 - z1) + (rp - r1) * (r2 - r1)) / ((z2 - z1)^2 + (r2 - r1)^2), zero(T), one(T))
if hypot(rp - r1 - s * (r2 - r1), zp - z1 - s * (z2 - z1)) <= csgtol
return true
end
end
# if not, then it is really outside
return false
end

function _in(pt::CartesianPoint{T}, c::Polycone{<:Any, ClosedPrimitive}; csgtol::T = csg_default_tol(T)) where {T}
return (isnothing(c.φ) || _in_angular_interval_closed(atan(pt.y, pt.x), c.φ, csgtol = csgtol / r)) &&
PolygonOps.inpolygon((hypot(pt.x, pt.y), pt.z), tuple.(c.r, c.z), in = true, on = true, out = false)
_inpolygon((hypot(pt.x, pt.y), pt.z), tuple.(c.r, c.z); csgtol)
end

function _in(pt::CartesianPoint{T}, c::Polycone{<:Any, OpenPrimitive}; csgtol::T = csg_default_tol(T)) where {T}
Expand Down
2 changes: 1 addition & 1 deletion test/test_geant4.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ using RadiationDetectorSignals
using TypedTables
using Unitful

T = Float64
T = Float32

@testset "Parse materials in Geant4 extension" begin
parse_material = Base.get_extension(SolidStateDetectors, :SolidStateDetectorsGeant4Ext).parse_material
Expand Down

0 comments on commit b92f3e2

Please sign in to comment.