Skip to content

Commit 91bcd6e

Browse files
committed
Generalize plot recipe of AbstractParticleSource
1 parent def57dc commit 91bcd6e

File tree

1 file changed

+24
-22
lines changed

1 file changed

+24
-22
lines changed

src/PlotRecipes/ChargeCloudModels.jl

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -291,29 +291,31 @@ end
291291

292292
@recipe function f(m::AbstractParticleSource; length = 0.01)
293293

294-
if iszero(m.opening_angle)
295-
v = m.position
296-
vnew = m.position + length * normalize(m.direction)
297-
@series begin
298-
linewidth --> 2
299-
color --> :green
300-
label := ""
301-
[v.x, vnew.x], [v.y, vnew.y], [v.z, vnew.z]
302-
end
303-
elseif m.opening_angle <= 90u"°"
304-
d = normalize(m.direction)
305-
a = normalize(d × (abs(d.x) == 1 ? CartesianVector(0,1,0) : CartesianVector(1,0,0)))
306-
b = normalize(a × d)
307-
rot = hcat(a,b,d)
308-
cone = SolidStateDetectors.ConstructiveSolidGeometry.Cone(r = ((0,0),(0,length*sin(m.opening_angle))), hZ = length*cos(m.opening_angle)/2,
309-
origin = rot * [0,0,length*cos(m.opening_angle)/2] + m.position,
310-
rotation = rot)
294+
if hasproperty(m, :opening_angle)
295+
if iszero(m.opening_angle)
296+
v = m.position
297+
vnew = m.position + length * normalize(m.direction)
298+
@series begin
299+
linewidth --> 2
300+
color --> :green
301+
label := ""
302+
[v.x, vnew.x], [v.y, vnew.y], [v.z, vnew.z]
303+
end
304+
elseif m.opening_angle <= 90u"°"
305+
d = normalize(m.direction)
306+
a = normalize(d × (abs(d.x) == 1 ? CartesianVector(0,1,0) : CartesianVector(1,0,0)))
307+
b = normalize(a × d)
308+
rot = hcat(a,b,d)
309+
cone = SolidStateDetectors.ConstructiveSolidGeometry.Cone(r = ((0,0),(0,length*sin(m.opening_angle))), hZ = length*cos(m.opening_angle)/2,
310+
origin = rot * [0,0,length*cos(m.opening_angle)/2] + m.position,
311+
rotation = rot)
311312

312-
@series begin
313-
linewidth := 0
314-
color --> :green
315-
label := ""
316-
cone
313+
@series begin
314+
linewidth := 0
315+
color --> :green
316+
label := ""
317+
cone
318+
end
317319
end
318320
end
319321

0 commit comments

Comments
 (0)