Skip to content

Commit

Permalink
Fix remaining issues (#1503)
Browse files Browse the repository at this point in the history
* change texture_atlas path

* re-organize backends

* add OpenGL troubleshooting to GLMakie docs

* add note about supported OS

* fix rasterizer

* give Axis3 a cameracontrol type, fix cairomakie meshrendering

* cleanup

* clean up testdatabase & add primitive tests

* update test excludes to new format

* fix & comment poly

* allow multi stroke for poly, fix #1514

* maybe that was confusing franklin?
  • Loading branch information
SimonDanisch committed Dec 15, 2021
1 parent d3152d9 commit bb764a4
Show file tree
Hide file tree
Showing 29 changed files with 355 additions and 624 deletions.
8 changes: 4 additions & 4 deletions CairoMakie/test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,13 @@ excludes = Set([
# markers too big, close otherwise, needs to be assimilated with glmakie
"Unicode Marker",
"Depth Shift",
"Order Independent Transparency"
"Order Independent Transparency",
"heatmap transparent colormap"
])
excludes2 = Set(["short_tests_90", "short_tests_111", "short_tests_35", "short_tests_3"])

functions = [:volume, :volume!, :uv_mesh]
database = database_filtered(excludes, excludes2, functions=functions)
database = database_filtered(excludes, functions=functions)

recorded = joinpath(@__DIR__, "recorded")
rm(recorded; force=true, recursive=true); mkdir(recorded)
ReferenceTests.run_reference_tests(database, recorded)
@time ReferenceTests.run_reference_tests(database, recorded)
4 changes: 2 additions & 2 deletions CairoMakie/test/saving.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ savepath(uid, fmt) = joinpath(format_save_path, "$uid.$fmt")
scene = MakieGallery.eval_example(example)
for fmt in ("png", "pdf", "svg")
@test try
save(savepath(example.unique_name, fmt), scene)
save(savepath(example.title, fmt), scene)
true
catch e
@warn "Saving $(example.unique_name) in format `$fmt` failed!" exception=(e, Base.catch_backtrace())
@warn "Saving $(example.title) in format `$fmt` failed!" exception=(e, Base.catch_backtrace())
false
end
end
Expand Down
2 changes: 1 addition & 1 deletion GLMakie/test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ include("unit_tests.jl")
# Run the Makie reference image testsuite
recorded = joinpath(@__DIR__, "recorded")
rm(recorded; force=true, recursive=true); mkdir(recorded)
ReferenceTests.run_reference_tests(ReferenceTests.load_database(), recorded)
@time ReferenceTests.run_reference_tests(ReferenceTests.load_database(), recorded)

# Run the below, to generate a html to view all differences:
# recorded, ref_images, scores = ReferenceTests.reference_tests(recorded)
Expand Down
30 changes: 8 additions & 22 deletions ReferenceTests/src/database.jl
Original file line number Diff line number Diff line change
Expand Up @@ -21,43 +21,29 @@ function Entry(title, source_location, code, func)
return Entry(title, source_location, code, func, used_functions)
end

function unique_name(entry::Entry)
loc = entry.source_location
filename = splitext(basename(string(loc.file)))[1]
sep = isempty(entry.title) ? "" : "_"
return replace(string(filename, "_", loc.line, sep, entry.title), " " => "")
end

function nice_title(entry::Entry)
isempty(entry.title) || return entry.title
return unique_name(entry)
end

const DATABASE = Dict{String, Entry}()

function cell_expr(name, code, source)
key = string(source.file, ":", source.line)
title = string(name)
return quote
closure = () -> $(esc(code))
entry = ReferenceTests.Entry(
$(string(name)),
$(title),
$(QuoteNode(source)),
$(QuoteNode(code)),
closure
)
ReferenceTests.DATABASE[$key] = entry
# display(closure())
if haskey(ReferenceTests.DATABASE, $title)
error("Titles must be unique for tests")
end
ReferenceTests.DATABASE[$title] = entry
end
end

macro cell(name, code)
return cell_expr(name, code, __source__)
end

macro cell(code)
return cell_expr("", code, __source__)
end

"""
save_result(path, object)
Expand All @@ -77,6 +63,7 @@ end

function load_database()
empty!(DATABASE)
include(joinpath(@__DIR__, "tests/primitives.jl"))
include(joinpath(@__DIR__, "tests/text.jl"))
include(joinpath(@__DIR__, "tests/attributes.jl"))
include(joinpath(@__DIR__, "tests/examples2d.jl"))
Expand All @@ -85,11 +72,10 @@ function load_database()
return DATABASE
end

function database_filtered(title_excludes = [], nice_title_excludes = []; functions=[])
function database_filtered(title_excludes = []; functions=[])
database = ReferenceTests.load_database()
return filter(database) do (name, entry)
!(entry.title in title_excludes) &&
!(nice_title(entry) in nice_title_excludes) &&
!any(x-> x in entry.used_functions, functions)
end
end
6 changes: 3 additions & 3 deletions ReferenceTests/src/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -126,15 +126,15 @@ function record_tests(db=load_database(); recording_dir=basedir("recorded"))
RNG.seed_rng!()
result = Base.invokelatest(entry.func)
# only save if we have a backend for saving
uname = unique_name(entry)
uname = entry.title
if !no_backend
save_result(joinpath(recording_dir, uname), result)
end
push!(recorded_files, uname)
@info("Tested: $(nice_title(entry))")
@info("Tested: $(entry.title)")
@test true
catch e
@info("Test: $(nice_title(entry)) didn't pass")
@info("Test: $(entry.title) didn't pass")
@test false
Base.showerror(stderr, e)
Base.show_backtrace(stderr, Base.catch_backtrace())
Expand Down
8 changes: 4 additions & 4 deletions ReferenceTests/src/tests/examples2d.jl
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ end
sf = Observable(Base.Fix2(v, 0e0))
title_str = Observable("t = 0.00")
sp = streamplot(sf, -2..2, -2..2;
linewidth=2, arrow_size=0.09, colormap=:magma, axis=(;title=title_str))
linewidth=2, arrow_size=20, colormap=:magma, axis=(;title=title_str))
Record(sp, LinRange(0, 20, 5)) do i
sf[] = Base.Fix2(v, i)
title_str[] = "t = $(round(i; sigdigits=2))"
Expand All @@ -204,12 +204,12 @@ let
end
@cell "streamplot" begin
P = FitzhughNagumo(0.1, 0.0, 1.5, 0.8)
f(x, P::FitzhughNagumo) = Point2f(
ff(x, P::FitzhughNagumo) = Point2f(
(x[1] - x[2] - x[1]^3 + P.s) / P.ϵ,
P.γ * x[1] - x[2] + P.β
)
f(x) = f(x, P)
streamplot(f, -1.5..1.5, -1.5..1.5, colormap=:magma)
ff(x) = ff(x, P)
streamplot(ff, -1.5..1.5, -1.5..1.5, colormap=:magma)
end
end

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# "lines and linestyles"
begin
# @cell "lines and linestyles" begin
quote
# For now disabled until we fix GLMakie linestyle
s = Scene(resolution = (800, 800), camera = campixel!)
scalar = 30
points = Point2f[(1, 1), (1, 2), (2, 3), (2, 1)]
Expand All @@ -19,8 +20,7 @@ begin
s
end

# "lines with gaps"
begin
@cell "lines with gaps" begin
s = Scene(resolution = (800, 800), camera = campixel!)
points = [
Point2f[(1, 0), (2, 0.5), (NaN, NaN), (4, 0.5), (5, 0)],
Expand All @@ -36,13 +36,12 @@ begin
s
end

# "scatters"
begin
@cell "scatters" begin
s = Scene(resolution = (800, 800), camera = campixel!)

markersizes = 0:2:30
markers = [:circle, :rect, :cross, :utriangle, :dtriangle,
'a', 'x', 'h', 'g', 'Y', 'J', 'α', ''
'a', 'x', 'h', 'g', 'Y', 'J', 'α', ''
]

for (i, ms) in enumerate(markersizes)
Expand All @@ -57,13 +56,12 @@ begin
s
end

# "scatter rotations"
begin
@cell "scatter rotations" begin
s = Scene(resolution = (800, 800), camera = campixel!)

rotations = range(0, 2pi, length = 15)
markers = [:circle, :rect, :cross, :utriangle, :dtriangle,
'a', 'x', 'h', 'g', 'Y', 'J', 'α', ''
'a', 'x', 'h', 'g', 'Y', 'J', 'α', ''
]

for (i, rot) in enumerate(rotations)
Expand All @@ -81,22 +79,11 @@ begin
s
end

# "poly"
begin
s = Scene(resolution = (800, 800), camera = campixel!)

@cell "basic polygon shapes" begin
s = Scene(resolution = (800, 800), camera = campixel!)
scalefactor = 70
Pol = Makie.GeometryBasics.Polygon

translate(pol, p) = Pol(
Ref(p) .+ decompose(Point2f, pol.exterior),
map(x -> decompose(Point2f, x) .+ Ref(p), pol.interiors)
)
scale(pol, sca) = Pol(
sca .* decompose(Point2f, pol.exterior),
map(x -> decompose(Point2f, x) .* sca, pol.interiors)
)

polys = [
# three points
Pol(Point2f[(1, 1), (1, 2), (2, 1)]),
Expand Down Expand Up @@ -132,17 +119,15 @@ begin

for (i, p) in enumerate(polys)
for (j, lw) in enumerate(linewidths)
t = Transformation(scale=Vec3f(scalefactor), translation = Vec3f(1.3 * (i-1), 1.3 * j, 0) .* scalefactor)
poly!(
s,
translate(
scale(p, scalefactor),
scalefactor * Point2f(1.3 * (i-1), 1.3 * j)
),
p,
transformation = t,
color = (:red, 0.5),
strokewidth = lw,
)
end
end

s
end
end
79 changes: 40 additions & 39 deletions ReferenceTests/src/tests/short_tests.jl
Original file line number Diff line number Diff line change
@@ -1,84 +1,79 @@
@cell arc(Point2f(0), 10f0, 0f0, pi, linewidth=20)
@cell "thick arc" arc(Point2f(0), 10f0, 0f0, pi, linewidth=20)

@cell mesh(Recti(0, 0, 200, 200))
@cell "stroked rect poly" poly(Recti(0, 0, 200, 200), strokewidth=20, strokecolor=:red, color=(:black, 0.4))

@cell poly(Recti(0, 0, 200, 200), strokewidth=20, strokecolor=:red, color=(:black, 0.4))

@cell begin
scene = poly([Rect(0, 0, 20, 20)])
@cell "array of rects poly" begin
f, ax, pl = poly([Rect(0, 0, 20, 20)])
scatter!(Rect(0, 0, 20, 20), color=:red, markersize=20)
current_figure()
f
end

@cell begin
lines(Rect(0, 0, 1, 1), linewidth=4)
@cell "char marker scenespace" begin
f, ax, pl = lines(Rect(0, 0, 1, 1), linewidth=4)
scatter!([Point2f(0.5, 0.5)], markersize=1, markerspace=SceneSpace, marker='I')
current_figure()
f
end

@cell lines(RNG.rand(10), RNG.rand(10), color=RNG.rand(10), linewidth=10)
@cell lines(RNG.rand(10), RNG.rand(10), color=RNG.rand(RGBAf, 10), linewidth=10)
@cell scatter(0..1, RNG.rand(10), markersize=RNG.rand(10) .* 20)
@cell scatter(LinRange(0, 1, 10), RNG.rand(10))
@cell scatter(RNG.rand(10), LinRange(0, 1, 10))
@cell "lines number color" lines(RNG.rand(10), RNG.rand(10), color=RNG.rand(10), linewidth=10)
@cell "lines array of colors" lines(RNG.rand(10), RNG.rand(10), color=RNG.rand(RGBAf, 10), linewidth=10)
@cell "scatter interval" scatter(0..1, RNG.rand(10), markersize=RNG.rand(10) .* 20)
@cell "scatter linrange" scatter(LinRange(0, 1, 10), RNG.rand(10))

@cell begin
@cell "scatter rotation" begin
angles = range(0, stop=2pi, length=20)
pos = Point2f.(sin.(angles), cos.(angles))
scatter(pos, markersize=0.2, markerspace=SceneSpace, rotations=-angles, marker='', axis=(;aspect = DataAspect()))
f, ax, pl = scatter(pos, markersize=0.2, markerspace=SceneSpace, rotations=-angles, marker='', axis=(;aspect = DataAspect()))
scatter!(pos, markersize=10, color=:red)
current_figure()
f
end

@cell heatmap(RNG.rand(50, 50), colormap=:RdBu, alpha=0.2)
@cell "heatmap transparent colormap" heatmap(RNG.rand(50, 50), colormap=(:RdBu, 0.2))

@cell "contour small x" contour(RNG.rand(10, 100))
@cell "contour small y" contour(RNG.rand(100, 10))
@cell "contour with levels" contour(RNG.randn(100, 90), levels=3)

@cell contour(RNG.rand(10, 100))
@cell contour(RNG.rand(100, 10))
@cell contour(RNG.randn(100, 90), levels=3)
@cell "contour with levels array" contour(RNG.randn(100, 90), levels=[0.1, 0.5, 0.8])
@cell "contour with color per level" contour(RNG.randn(33, 30), levels=[0.1, 0.5, 0.9], color=[:black, :green, (:blue, 0.4)], linewidth=2)

@cell contour(RNG.randn(100, 90), levels=[0.1, 0.5, 0.8])
@cell contour(RNG.randn(100, 90), levels=[0.1, 0.5, 0.8], color=:black)
@cell contour(RNG.randn(33, 30), levels=[0.1, 0.5, 0.9], color=[:black, :green, (:blue, 0.4)], linewidth=2)
@cell contour(RNG.randn(33, 30), levels=[0.1, 0.5, 0.9], colormap=:Spectral)
@cell contour(
@cell "contour with colorrange" contour(
RNG.rand(33, 30) .* 6 .- 3, levels=[-2.5, 0.4, 0.5, 0.6, 2.5],
colormap=[(:black, 0.2), :red, :blue, :green, (:black, 0.2)],
colorrange=(0.2, 0.8)
)

@cell lines(Circle(Point2f(0), Float32(1)))
@cell "circle line" lines(Circle(Point2f(0), Float32(1)))

@cell begin
@cell "streamplot with func" begin
v(x::Point2{T}) where T = Point2{T}(x[2], 4 * x[1])
streamplot(v, -2..2, -2..2)
streamplot(v, -2..2, -2..2, arrow_size=10)
end

@cell lines(-1..1, x -> x^2)
@cell scatter(-1..1, x -> x^2)
@cell "lines with func" lines(-1..1, x -> x^2)
@cell "scatter with func" scatter(-1..1, x -> x^2)

@cell begin
@cell "volume translated" begin
r = range(-3pi, stop=3pi, length=100)
fig, ax, vplot = Makie.volume(r, r, r, (x, y, z) -> cos(x) + sin(y) + cos(z), algorithm=:iso, isorange=0.1f0, show_axis=false)
v2 = volume!(ax, r, r, r, (x, y, z) -> cos(x) + sin(y) + cos(z), algorithm=:mip,
transformation=(translation=Vec3f(6pi, 0, 0),))
fig
end

@cell meshscatter(RNG.rand(10), RNG.rand(10), RNG.rand(10), color=RNG.rand(10))
@cell meshscatter(RNG.rand(10), RNG.rand(10), RNG.rand(10), color=RNG.rand(RGBAf, 10))
@cell "meshscatter color numbers" meshscatter(RNG.rand(10), RNG.rand(10), RNG.rand(10), color=RNG.rand(10))
@cell "meshscatter color array" meshscatter(RNG.rand(10), RNG.rand(10), RNG.rand(10), color=RNG.rand(RGBAf, 10), transparency=true)

@cell begin
@cell "transparent mesh texture" begin
s1 = uv_mesh(Sphere(Point3f(0), 1f0))
mesh(uv_mesh(Sphere(Point3f(0), 1f0)), color=RNG.rand(50, 50))
f, ax, pl = mesh(uv_mesh(Sphere(Point3f(0), 1f0)), color=RNG.rand(50, 50))
# ugh, bug In GeometryTypes for UVs of non unit spheres.
s2 = uv_mesh(Sphere(Point3f(0), 1f0))
s2.position .= s2.position .+ (Point3f(0, 2, 0),)
mesh!(s2, color=RNG.rand(RGBAf, 50, 50))
current_figure()
f
end

@cell "Unequal x and y sizes in surface" begin
#
NL = 15
NR = 31
function xy_data(x, y)
Expand Down Expand Up @@ -182,3 +177,9 @@ end

s
end

@cell "multipoly with multi strokes" begin
P = Polygon.([Point2f[[0.45, 0.05], [0.64, 0.15], [0.37, 0.62]],
Point2f[[0.32, 0.66], [0.46, 0.59], [0.09, 0.08]]])
poly(P, color = [:red, :green], strokecolor = :blue, strokewidth = 2)
end
5 changes: 2 additions & 3 deletions WGLMakie/test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,8 @@ excludes = Set([
"Record Video"
])

excludes2 = Set(["short_tests_83", "short_tests_78", "short_tests_40", "short_tests_5", "short_tests_41"])
database = database_filtered(excludes, excludes2)
database = database_filtered(excludes)

recorded = joinpath(@__DIR__, "recorded")
rm(recorded; force=true, recursive=true); mkdir(recorded)
ReferenceTests.run_reference_tests(database, recorded; difference=0.032)
@time ReferenceTests.run_reference_tests(database, recorded; difference=0.032)

0 comments on commit bb764a4

Please sign in to comment.