Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some minor bug fixes and some cleaning #96

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 3 additions & 10 deletions src/Geometries/VolumePrimitives/Cone.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,19 @@ struct Cone{T} <: AbstractVolumePrimitive{T, 3} ## Only upright Cones at the mom
zStart::T
zStop::T
translate::Union{CartesianVector{T},Missing}
rotate::SMatrix{3,3,T}
rotate::Rotations.RotXYZ{T}
end



function Cone{T}( rStart1::T, rStop1::T, rStart2::T, rStop2::T, φStart::T, φStop::T, zStart::T, zStop::T, translate::Union{CartesianVector{T},Missing}, rotX::T, rotY::T, rotZ::T) where {T}
rotationMatrix::SMatrix{3,3,T} = SMatrix{3,3,T}([1 0 0;
0 cos(rotX) -sin(rotX);
0 sin(rotX) cos(rotX)]) *
SMatrix{3,3,T}([cos(rotY) 0 sin(rotY);
0 1 0;
-sin(rotY) 0 cos(rotY)]) *
SMatrix{3,3,T}([cos(rotZ) -sin(rotZ) 0;
sin(rotZ) cos(rotZ) 0;
0 0 1])
rotationMatrix::Rotations.RotXYZ{T} = RotXYZ(rotX, rotY, rotZ)

Cone{T}(rStart1, rStop1, rStart2, rStop2, φStart, φStop, zStart, zStop, translate, rotationMatrix)
end

function in(point::CylindricalPoint{T}, cone::Cone{T}) where T
(ismissing(cone.translate) || cone.translate == CartesianVector{T}(0.0, 0.0, 0.0)) ? nothing : point = CylindricalPoint(CartesianPoint(point) - cone.translate)
if ( point.z in ClosedInterval{T}(cone.zStart,cone.zStop) ) && ( point.φ in ClosedInterval{T}(cone.φStart,cone.φStop) ) && ( point.r in ClosedInterval{T}(minimum([cone.rStart1,cone.rStart2,cone.rStop1,cone.rStop2]), maximum([cone.rStart1,cone.rStart2,cone.rStop1,cone.rStop2])) )

r1,r2 = get_intersection_rs_for_given_z(point.z,cone)
Expand Down
22 changes: 8 additions & 14 deletions src/Geometries/VolumePrimitives/Tube.jl
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@ function Tube{T}(dict::Dict{Any, Any}, inputunit_dict::Dict{String,Unitful.Units
else
@warn "please specify a height of the Tube 'h'"
end
phi_interval = if haskey(dict, "phi")

phi_interval = if haskey(dict, "phi")
Interval(geom_round(T(deg2rad(dict["phi"]["from"]))), geom_round(T(deg2rad(dict["phi"]["to"]))))
else
Interval(geom_round(T(deg2rad(0))), geom_round(T(deg2rad(360))))
end

r_interval = if haskey(dict["r"], "from")
r_interval = if haskey(dict["r"], "from")
Interval(geom_round(ustrip(uconvert(u"m", T(dict["r"]["from"]) * inputunit_dict["length"] ))), geom_round(ustrip(uconvert(u"m", T(dict["r"]["to"]) * inputunit_dict["length"]))))
else
Interval(geom_round(0), geom_round(ustrip(uconvert(u"m", T(dict["r"]) * inputunit_dict["length"]))))
Expand All @@ -47,7 +47,7 @@ function Tube{T}(dict::Dict{Any, Any}, inputunit_dict::Dict{String,Unitful.Units
r_interval,
phi_interval,
Interval(zStart, zStop),
translate
translate
)
end

Expand All @@ -56,20 +56,14 @@ function Geometry(T::DataType, t::Val{:tube}, dict::Dict{Union{Any,String}, Any}
end

function in(point::CartesianPoint{T}, tube::Tube{T}) where T
ismissing(tube.translate) ? nothing : point -= tube.translate
(ismissing(tube.translate) || tube.translate == CartesianVector{T}(0.0,0.0,0.0)) ? nothing : point -= tube.translate
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tube.translate should never be zero

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, we have to change the general struct of our primitives anyhow when we add Rotations.
This if ismissing should never appear. I guess we will use parametric types to handle this on compilation level.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For both, translation and rotation.

point = convert(CylindricalPoint,point)
if point.r in tube.r_interval && point.φ in tube.φ_interval && point.z in tube.z_interval
return true
end
return false
return (point.r in tube.r_interval && point.φ in tube.φ_interval && point.z in tube.z_interval)
end

function in(point::CylindricalPoint{T}, tube::Tube{T}) where T
ismissing(tube.translate) ? nothing : point = CylindricalPoint(CartesianPoint(point)-tube.translate)
if point.r in tube.r_interval && point.φ in tube.φ_interval && point.z in tube.z_interval
return true
end
return false
(ismissing(tube.translate) || tube.translate == CartesianVector{T}(0.0,0.0,0.0)) ? nothing : point = CylindricalPoint(CartesianPoint(point)-tube.translate)
return (point.r in tube.r_interval && point.φ in tube.φ_interval && point.z in tube.z_interval)
end


Expand Down