Skip to content

Commit 03100fa

Browse files
committed
Add vres and hres attributes to drawshape!()
1 parent 1493603 commit 03100fa

File tree

1 file changed

+16
-11
lines changed

1 file changed

+16
-11
lines changed

src/util/plotting.jl

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
const ϵrel = Base.rtoldefault(Float64) # machine epsilon
2-
const N_PLOT_SAMPLING_POINTS = 101
32

43
# Define drawshape() and drawshape!() functions.
54
@recipe(DrawShape) do scene
6-
Attributes()
7-
Theme()
5+
Attributes(vres=100, hres=100)
86
end
97

108
# Implement drawshape!() for 2D shapes.
119
function Makie.plot!(ds::DrawShape{<:Tuple{Shape{2}}})
1210
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...)
1415

1516
return ds
1617
end
@@ -19,18 +20,21 @@ end
1920
function Makie.plot!(ds::DrawShape{<:Tuple{Shape{3},Tuple{Symbol,Real}}})
2021
shp = ds[1]
2122
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...)
2327

2428
return ds
2529
end
2630

2731
# 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})
2933
lower, upper = bounds(shp)
3034
= upper - lower
3135

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)
3438

3539
lvs = [level(@SVector([x,y]), shp) for x = xs, y = ys]
3640

@@ -39,7 +43,8 @@ end
3943

4044
# Define the new signature of contour!() used in drawshape!() for 3D shapes.
4145
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})
4348
ax, cept = cs # axis normal to cross section, intercept
4449

4550
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},
5459
lower, upper = bounds(shp)
5560
= upper - lower
5661

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)
5964

6065
lvs = [level(u*+ v*+ cept*ŵ, shp) for u = us, v = vs]
6166

0 commit comments

Comments
 (0)