1
1
const ϵrel = Base. rtoldefault (Float64) # machine epsilon
2
- const N_PLOT_SAMPLING_POINTS = 101
3
2
4
3
# Define drawshape() and drawshape!() functions.
5
4
@recipe (DrawShape) do scene
6
- Attributes ()
7
- Theme ()
5
+ Attributes (vres= 100 , hres= 100 )
8
6
end
9
7
10
8
# Implement drawshape!() for 2D shapes.
11
9
function Makie. plot! (ds:: DrawShape{<:Tuple{Shape{2}}} )
12
10
shp = ds[1 ]
13
- contour! (ds, shp, levels= SVector (0.0 ); ds. attributes... ) # Makie.convert_arguments() below handles this new signature
11
+ res = (ds. vres. val, ds. hres. val) # found by examining typeof(ds) and fieldnames(typeof(ds)), etc
12
+
13
+ # Makie.convert_arguments() defined below handles this new signature.
14
+ contour! (ds, shp, res, levels= SVector (0.0 ); ds. attributes... )
14
15
15
16
return ds
16
17
end
19
20
function Makie. plot! (ds:: DrawShape{<:Tuple{Shape{3},Tuple{Symbol,Real}}} )
20
21
shp = ds[1 ]
21
22
cs = ds[2 ]
22
- contour! (ds, shp, cs, levels= SVector (0.0 ); ds. attributes... ) # Makie.convert_arguments() below handles this new signature
23
+ res = (ds. vres. val, ds. hres. val) # found by examining typeof(ds) and fieldnames(typeof(ds)), etc
24
+
25
+ # Makie.convert_arguments() defined below handles this new signature.
26
+ contour! (ds, shp, cs, res, levels= SVector (0.0 ); ds. attributes... )
23
27
24
28
return ds
25
29
end
26
30
27
31
# Define the new signature of contour!() used in drawshape!() for 2D shapes.
28
- function Makie. convert_arguments (P:: SurfaceLike , shp:: Shape{2} )
32
+ function Makie. convert_arguments (P:: SurfaceLike , shp:: Shape{2} , res :: Tuple{Integer,Integer} )
29
33
lower, upper = bounds (shp)
30
34
∆ = upper - lower
31
35
32
- nw = 1 ; xs = range (lower[nw] - ϵrel* ∆[nw], upper[nw] + ϵrel* ∆[nw], length= N_PLOT_SAMPLING_POINTS )
33
- nw = 2 ; ys = range (lower[nw] - ϵrel* ∆[nw], upper[nw] + ϵrel* ∆[nw], length= N_PLOT_SAMPLING_POINTS )
36
+ nw = 1 ; xs = range (lower[nw] - ϵrel* ∆[nw], upper[nw] + ϵrel* ∆[nw], length= res[nw] + 1 )
37
+ nw = 2 ; ys = range (lower[nw] - ϵrel* ∆[nw], upper[nw] + ϵrel* ∆[nw], length= res[nw] + 2 )
34
38
35
39
lvs = [level (@SVector ([x,y]), shp) for x = xs, y = ys]
36
40
39
43
40
44
# Define the new signature of contour!() used in drawshape!() for 3D shapes.
41
45
function Makie. convert_arguments (P:: SurfaceLike , shp:: Shape{3} ,
42
- cs:: Tuple{Symbol,Real} ) # (:x or :y or :z, intercept): cross section spec
46
+ cs:: Tuple{Symbol,Real} , # (:x or :y or :z, intercept): cross section spec
47
+ res:: Tuple{Integer,Integer} )
43
48
ax, cept = cs # axis normal to cross section, intercept
44
49
45
50
ax== :x || ax== :y || ax== :z || @error " cs[1] = $(cs[1 ]) should be :x or :y or :z."
@@ -54,8 +59,8 @@ function Makie.convert_arguments(P::SurfaceLike, shp::Shape{3},
54
59
lower, upper = bounds (shp)
55
60
∆ = upper - lower
56
61
57
- us = range (lower[nu] - ϵrel* ∆[nu], upper[nu] + ϵrel* ∆[nu], length= N_PLOT_SAMPLING_POINTS )
58
- vs = range (lower[nv] - ϵrel* ∆[nv], upper[nv] + ϵrel* ∆[nv], length= N_PLOT_SAMPLING_POINTS )
62
+ us = range (lower[nu] - ϵrel* ∆[nu], upper[nu] + ϵrel* ∆[nu], length= res[ 1 ] + 1 )
63
+ vs = range (lower[nv] - ϵrel* ∆[nv], upper[nv] + ϵrel* ∆[nv], length= res[ 2 ] + 1 )
59
64
60
65
lvs = [level (u* û + v* v̂ + cept* ŵ, shp) for u = us, v = vs]
61
66
0 commit comments