Skip to content

Commit c1a557b

Browse files
committed
Calculate margin of drawshape!() as relative quantity
1 parent 620499b commit c1a557b

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

src/util/plotting.jl

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
const ϵmach = eps() # machine epsilon
2-
const N_PLOT_SAMPLING_POINTS = 100
1+
const ϵrel = Base.rtoldefault(Float64) # machine epsilon
2+
const N_PLOT_SAMPLING_POINTS = 101
33

44
# Define drawshape() and drawshape!() functions.
55
@recipe(DrawShape) do scene
@@ -27,9 +27,10 @@ end
2727
# Define the new signature of contour!() used in drawshape!() for 2D shapes.
2828
function Makie.convert_arguments(P::SurfaceLike, shp::Shape{2})
2929
lower, upper = bounds(shp)
30+
= upper - lower
3031

31-
xs = range(lower[1]-ϵmach, upper[1]+ϵmach, length=N_PLOT_SAMPLING_POINTS)
32-
ys = range(lower[2]-ϵmach, upper[2]+ϵmach, length=N_PLOT_SAMPLING_POINTS)
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)
3334

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

@@ -51,9 +52,10 @@ function Makie.convert_arguments(P::SurfaceLike, shp::Shape{3},
5152
= SVector(ntuple(identity,Val(3))) .== nw
5253

5354
lower, upper = bounds(shp)
55+
= upper - lower
5456

55-
us = range(lower[nu]-ϵmach, upper[nu]+ϵmach, length=N_PLOT_SAMPLING_POINTS)
56-
vs = range(lower[nv]-ϵmach, upper[nv]+ϵmach, length=N_PLOT_SAMPLING_POINTS)
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)
5759

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

0 commit comments

Comments
 (0)