Skip to content

Commit 46696a6

Browse files
committed
better docs: don't use import
1 parent a0ad057 commit 46696a6

File tree

2 files changed

+17
-22
lines changed

2 files changed

+17
-22
lines changed

Project.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "DynamicalBilliards"
22
uuid = "4986ee89-4ee5-5cef-b6b8-e49ba721d7a5"
33
repo = "https://github.com/JuliaDynamics/DynamicalBilliards.jl.git"
4-
version = "3.11.3"
4+
version = "3.11.4"
55

66
[deps]
77
Distributed = "8ba89e20-285c-5b6f-9357-94700520ee1b"

docs/src/tutorials/own_obstacle.md

+16-21
Original file line numberDiff line numberDiff line change
@@ -55,14 +55,11 @@ to define a method for [`DynamicalBilliards.specular!`](@ref). You can however d
5555
custom methods for [`DynamicalBilliards.specular!`](@ref), which is what we have done e.g.
5656
for [`RandomDisk`](@ref).
5757

58-
!!! note "Use `import`!"
59-
Notice that you have to properly `import` the methods to extend them. For example,
60-
do `import DynamicalBilliards: normalvec, distance, collision` time.
6158

62-
The first method is very simple, just do:
59+
60+
The first method is very simple. *(Remember that in Julia to extend a function with a new method you must preface it with the parent module)*
6361
```julia
64-
import DynamicalBilliards: normalvec, distance, collision
65-
normalvec(d::Semicircle, pos) = normalize(d.c - pos)
62+
DynamicalBilliards.normalvec(d::Semicircle, pos) = normalize(d.c - pos)
6663
```
6764
Since the function is only used during `distance` and
6865
[`DynamicalBilliards.resolvecollision!`](@ref) and since we will be writing explicit methods for the first,
@@ -79,7 +76,7 @@ expanded. That is because when the particle is on the "open" half of the
7976
disk, the distance is not correct. We write:
8077
```julia
8178
SV = SVector{2} #convenience
82-
function distance(pos::AbstractVector{T}, s::Semicircle{T}) where {T}
79+
function DynamicalBilliards.distance(pos::AbstractVector{T}, s::Semicircle{T}) where {T}
8380
# Check on which half of circle is the particle
8481
v1 = pos .- s.c
8582
nn = dot(v1, s.facedir)
@@ -98,14 +95,14 @@ the "other side".
9895
Finally, the method for [`collision`](@ref) is by far the most *trickiest*. But,
9996
with pen, paper and a significant amount of patience, one can find a way:
10097
```julia
101-
function collision(p::Particle{T}, d::Semicircle{T})::T where {T}
98+
function DynamicalBilliards.collision(p::Particle{T}, d::Semicircle{T})::T where {T}
10299

103100
dc = p.pos - d.c
104101
B = dot(p.vel, dc) #velocity towards circle center: B > 0
105102
C = dot(dc, dc) - d.r*d.r #being outside of circle: C > 0
106103
Δ = B^2 - C
107104

108-
Δ 0 && return nocollision(T)
105+
Δ 0 && return DynamicalBilliards.nocollision(T)
109106
sqrtD = sqrt(Δ)
110107

111108
nn = dot(dc, d.facedir)
@@ -122,10 +119,10 @@ function collision(p::Particle{T}, d::Semicircle{T})::T where {T}
122119
# This check is necessary to not collide with the non-existing side
123120
newpos = p.pos + p.vel * t
124121
if dot(newpos - d.c, d.facedir) 0 # collision point on BAD HALF;
125-
return nocollision(T)
122+
return DynamicalBilliards.nocollision(T)
126123
end
127124
# If collision time is negative, return Inf:
128-
t 0.0 ? nocollision(T) : (t, p.pos + t*p.vel)
125+
t 0.0 ? DynamicalBilliards.nocollision(T) : (t, p.pos + t*p.vel)
129126
end
130127
```
131128

@@ -138,16 +135,14 @@ And that is all. The obstacle now works perfectly fine for straight propagation.
138135

139136
1. [`DynamicalBilliards.cellsize`](@ref) : Enables [`randominside`](@ref) with this obstacle.
140137
1. [`collision`](@ref) with [`MagneticParticle`](@ref) : enables magnetic propagation
141-
2. [`plot`](@ref) with `obstacle` : enables plotting
138+
2. [`plot`](@ref) with `obstacle` : enables plotting and animating
142139
3. [`DynamicalBilliards.specular!`](@ref) with `offset` : Allows [`lyapunovspectrum`](@ref) to be computed.
143140
4. [`to_bcoords`](@ref) : Allows the [`boundarymap`](@ref) and [`boundarymap_portion`](@ref) to be computed.
144141
5. [`from_bcoords`](@ref) : Allows [`phasespace_portion`](@ref) to be computed.
145142

146143
The [`DynamicalBilliards.cellsize`](@ref) method is kinda trivial:
147144
```julia
148-
import DynamicalBilliards: cellsize, plot, to_bcoords, from_bcoords
149-
150-
function cellsize(a::Semicircle{T}) where {T}
145+
function DynamicalBilliards.cellsize(a::Semicircle{T}) where {T}
151146
xmin, ymin = a.c - a.r
152147
xmax, ymax = a.c + a.r
153148
return xmin, ymin, xmax, ymax
@@ -157,7 +152,7 @@ end
157152

158153
The [`collision`](@ref) method for [`MagneticParticle`](@ref) is also tricky, however it is almost identical with the method for the general `Circular` obstacle:
159154
```julia
160-
function collision(p::MagneticParticle{T}, o::Semicircle{T})::T where {T}
155+
function DynamicalBilliards.collision(p::MagneticParticle{T}, o::Semicircle{T})::T where {T}
161156
ω = p.omega
162157
pc, rc = cyclotron(p)
163158
p1 = o.c
@@ -200,9 +195,9 @@ end
200195
Then, we add swag by writing a method for [`plot`](@ref):
201196

202197
```julia
203-
using PyPlot
198+
using PyPlot # brings plot(::Obstacle; kwargs...) into scope
204199

205-
function plot(d::Semicircle; kwargs...)
200+
function DynamicalBilliards.plot(d::Semicircle; kwargs...)
206201
theta1 = atan(d.facedir[2], d.facedir[1])*180/π + 90
207202
theta2 = theta1 + 180
208203
edgecolor = DynamicalBilliards.obcolor(d)
@@ -226,7 +221,7 @@ were already determined by Dellago, Posch and Hoover [1] – we just have to
226221
implement them.
227222

228223
```julia
229-
function specular!(p::Particle{T}, o::Circular{T},
224+
function DynamicalBilliards.specular!(p::Particle{T}, o::Circular{T},
230225
offset::Vector{SVector{4, T}}) where {T<:AbstractFloat}
231226

232227
n = normalvec(o, p.pos)
@@ -258,9 +253,9 @@ Note that calculating Lyapunov exponents for magnetic particles requires a
258253
separate method, as the formulas are different for magnetic propagation.
259254

260255
Finally, we also add a methods for [`to_bcoords`](@ref) and [`from_bcoords`](@ref).
261-
For them, see the relevant source file (use `@which`).
256+
For them, see the relevant source file (use `@edit`).
262257

263258

264259
**References**
265260

266-
[1] : Ch. Dellago et al., Phys. Rev. E 53, 1485 (1996).
261+
[1]: Dellago et al., Phys. Rev. E 53, 1485 (1996).

0 commit comments

Comments
 (0)