Skip to content

Commit

Permalink
rework angle
Browse files Browse the repository at this point in the history
  • Loading branch information
t-bltg committed Dec 13, 2022
1 parent 5292498 commit 788b028
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/basic_recipes/contours.jl
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ end

nice_label(x) = string(isinteger(x) ? round(Int, x) : x)

angle(p1, p2) = mod(atan(p2[2] - p1[2], p2[1] - p1[1]), -π)

function contourlines(::Type{<: Contour}, contours, cols, labels)
result = Point2f[]
colors = RGBA{Float32}[]
Expand All @@ -61,7 +63,7 @@ function contourlines(::Type{<: Contour}, contours, cols, labels)
push!(result, Point2f(NaN32))
append!(colors, fill(color, length(elem.vertices) + 1))
labels && let p1 = elem.vertices[1], p2 = elem.vertices[2]
push!(str_pos, (nice_label(c.level), p1, atan(p2[2] - p1[2], p2[1] - p1[1])))
push!(str_pos, (nice_label(c.level), p1, angle(p1, p2)))
end
end
end
Expand All @@ -80,7 +82,7 @@ function contourlines(::Type{<: Contour3d}, contours, cols, labels)
push!(result, Point3f(NaN32))
append!(colors, fill(color, length(elem.vertices) + 1))
labels && let p1 = elem.vertices[1], p2 = elem.vertices[2]
push!(str_pos, (nice_label(c.level), Point3f(p1[1], p1[2], c.level), atan(p2[2] - p1[2], p2[1] - p1[1])))
push!(str_pos, (nice_label(c.level), Point3f(p1[1], p1[2], c.level), angle(p1, p2)))
end
end
end
Expand Down Expand Up @@ -196,7 +198,7 @@ function plot!(plot::T) where T <: Union{Contour, Contour3d}
contourlines(T, contours, level_colors, labels)
end

masked_lines = lift(labels, color, result) do labels, color, (segments, _, str_pos_ang)
masked_lines = lift(labels, label_attributes, color, result) do labels, label_attributes, color, (segments, _, str_pos_ang)
labels || return segments # `labels = false`, early return
P = eltype(segments)
masked = sizehint!(P[], length(segments))
Expand Down

0 comments on commit 788b028

Please sign in to comment.