Skip to content

Commit

Permalink
split computation
Browse files Browse the repository at this point in the history
  • Loading branch information
t-bltg committed Dec 14, 2022
1 parent 612c8df commit 2571c43
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/basic_recipes/contours.jl
Original file line number Diff line number Diff line change
Expand Up @@ -198,26 +198,30 @@ function plot!(plot::T) where T <: Union{Contour, Contour3d}
contours = Contours.contours(xv, yv, z, convert(Vector{eltype(z)}, levels))
contourlines(T, contours, level_colors, labels)
end
scene = parent_scene(plot)

masked_lines = lift(labels, label_attributes, color, result) do labels, label_attributes, color, (segments, _, str_pos)
labels || return segments # `labels = false`, early return
scene = parent_scene(plot)
bboxes = map(str_pos) do (str, (p1, p2, p3))
bboxes = lift(labels, label_attributes, color, result) do labels, label_attributes, color, (_, _, str_pos)
labels || return
map(str_pos) do (str, (p1, p2, p3))
ang = angle(project(scene, p1), project(scene, p2))
# transition from an angle from horizontal axis in [-π; π]
# to a readable text with a rotation from vertical axis in [-π / 2; π / 2]
rotation = abs(ang) > π / 2 ? ang - copysign(π, ang) : ang
text!(scene, [(str, p1)]; rotation, color, align = (:center, :center), label_attributes...) |> boundingbox
end
end

masked_lines = lift(scene.camera.projectionview, scene.px_area, bboxes, labels, result) do _, _, bboxes, labels, (segments, _, _)
labels || return segments # `labels = false`, early return
n = 1
bb = bboxes[n]
nlab = length(str_pos)
nlab = length(bboxes)
masked = copy(segments)
P = eltype(segments)
for (i, p) in enumerate(segments)
if isnan(p) && n < nlab
bb = bboxes[n += 1] # next segment is materialized by a NaN, thus consider next label
# wireframe!(plot, bb, space = :pixel) # debug 2D - fails 3D ?
end
if project(scene.camera, plot.space[], :pixel, p) in bb
masked[i] = P(NaN32)
Expand Down

0 comments on commit 2571c43

Please sign in to comment.