Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix CairoMakie not being able to plot exotic point arrays in lines #4668

Merged
merged 7 commits into from
Dec 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
- Added `transform_marker` attribute to meshscatter and changed the default behavior to not transform marker/mesh vertices [#4606](https://github.com/MakieOrg/Makie.jl/pull/4606)
- Fixed some issues with meshscatter not correctly transforming with transform functions and float32 rescaling [#4606](https://github.com/MakieOrg/Makie.jl/pull/4606)
- Fixed `poly` pipeline for 3D and/or Float64 polygons that begin from an empty vector [#4615](https://github.com/MakieOrg/Makie.jl/pull/4615).
- Fixed an issue where `reinterpret`ed arrays of line points were not handled correctly in CairoMakie [#4668](https://github.com/MakieOrg/Makie.jl/pull/4668).

## [0.21.18] - 2024-12-12

Expand Down
15 changes: 12 additions & 3 deletions CairoMakie/src/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -193,16 +193,25 @@ end



function project_line_points(scene, plot::T, positions, colors, linewidths) where {T <: Union{Lines, LineSegments}}
function project_line_points(scene, plot::T, positions::AbstractArray{<: Makie.VecTypes{N, FT}}, colors, linewidths) where {T <: Union{Lines, LineSegments}, N, FT <: Real}

# Standard transform from input space to clip space
# Note that this is type unstable, so there is a function barrier in place.
space = (plot.space[])::Symbol
points = Makie.apply_transform(transform_func(plot), positions, space)

return project_transformed_line_points(scene, plot, points, colors, linewidths)
end

function project_transformed_line_points(scene, plot::T, points::AbstractArray{<: Makie.VecTypes{N, FT}}, colors, linewidths) where {T <: Union{Lines, LineSegments}, N, FT <: Real}
# Note that here, `points` has already had `transform_func` applied.
# If colors are defined per point they need to be interpolated like positions
# at clip planes
per_point_colors = colors isa AbstractArray
per_point_linewidths = (T <: Lines) && (linewidths isa AbstractArray)

space = (plot.space[])::Symbol
model = (plot.model[])::Mat4d
# Standard transform from input space to clip space
points = Makie.apply_transform(transform_func(plot), positions, space)::typeof(positions)
f32convert = Makie.f32_convert_matrix(scene.float32convert, space)
transform = Makie.space_to_clip(scene.camera, space) * f32convert * model
clip_points = map(points) do point
Expand Down
11 changes: 11 additions & 0 deletions CairoMakie/test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -304,4 +304,15 @@ end
ps, _, _ = CairoMakie.project_line_points(a.scene, ls, ls_points, nothing, nothing)
@test length(ps) >= 6 # at least 6 points: [2,3,3,4,4,5]
@test all(ref -> findfirst(p -> isapprox(p, ref, atol = 1e-4), ps) !== nothing, necessary_points)

# Check that `reinterpret`ed arrays of points are handled correctly
# ref. https://github.com/MakieOrg/Makie.jl/issues/4661

data = reinterpret(Point2f, rand(Point2f, 10) .=> rand(Point2f, 10))

f, a, p = lines(data)
Makie.update_state_before_display!(f)
ps, _, _ = @test_nowarn CairoMakie.project_line_points(a.scene, p, data, nothing, nothing)
@test length(ps) == length(data) # this should never clip!

end
Loading