Skip to content

Commit

Permalink
guard against NaN rotation and markersize in CairoMakie
Browse files Browse the repository at this point in the history
  • Loading branch information
ffreyer committed Nov 18, 2024
1 parent 3d155d5 commit 36088d4
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
5 changes: 3 additions & 2 deletions CairoMakie/src/primitives.jl
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,7 @@ function draw_atomic_scatter(
markersize, strokecolor, strokewidth, m, mo, rotation

isnan(pos) && return
isnan(rotation) && return # matches GLMakie

scale = project_scale(scene, markerspace, markersize, size_model)
offset = project_scale(scene, markerspace, mo, size_model)
Expand All @@ -372,7 +373,7 @@ function draw_atomic_scatter(
# Setting a markersize of 0.0 somehow seems to break Cairos global state?
# At least it stops drawing any marker afterwards
# TODO, maybe there's something wrong somewhere else?
if !(norm(scale) 0.0)
if !(isnan(scale) || norm(scale) 0.0)
if m isa Char
draw_marker(ctx, m, best_font(m, font), pos, scale, strokecolor, strokewidth, offset, rotation)
else
Expand Down Expand Up @@ -1254,7 +1255,7 @@ function draw_atomic(scene::Scene, screen::Screen, @nospecialize(primitive::Maki
scale = Makie.voxel_size(primitive)
colors = Makie.voxel_colors(primitive)
marker = GeometryBasics.normal_mesh(Rect3f(Point3f(-0.5), Vec3f(1)))

# Face culling
if !isempty(primitive.clip_planes[]) && Makie.is_data_space(primitive.space[])
valid = [is_visible(primitive.clip_planes[], p) for p in pos]
Expand Down
10 changes: 10 additions & 0 deletions ReferenceTests/src/tests/attributes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,13 @@
scatter(fig[1, 2], RNG.randn(20), color=colors, markersize=10, visible=false)
fig
end

@reference_test "(mesh)scatter with NaN rotation and markersize" begin
scene = Scene(size = (150, 300))
xs = [-0.6, 0.0, 0.6]
scatter!(scene, xs, fill( 0.75, 3), marker = :ltriangle, rotation = [0.5, NaN, -0.5], markersize = 50)
scatter!(scene, xs, fill( 0.25, 3), marker = :ltriangle, markersize = [50, NaN, 50])
meshscatter!(scene, xs, fill(-0.25, 3), marker = Rect2f(-0.5,-0.5,1,1), rotation = [0.5, NaN, -0.5], markersize = 0.2)
meshscatter!(scene, xs, fill(-0.75, 3), marker = Rect2f(-0.5,-0.5,1,1), markersize = [0.2, NaN, 0.2])
scene
end
2 changes: 2 additions & 0 deletions src/utilities/quaternions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,8 @@ function quaternion_to_2d_angle(quat::Quaternion)
end

Base.isinf(q::Quaternion) = any(isinf, q.data)
Base.isnan(q::Quaternion) = any(isnan, q.data)
Base.isfinite(q::Quaternion) = all(isfinite, q.data)
Base.abs2(q::Quaternion) = mapreduce(*, +, q.data, q.data)
function Base.inv(q::Quaternion)
if isinf(q)
Expand Down

0 comments on commit 36088d4

Please sign in to comment.