diff --git a/CHANGELOG.md b/CHANGELOG.md index bdfe0a97768..da6ca7d4c11 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/CairoMakie/src/utils.jl b/CairoMakie/src/utils.jl index bc99af64138..766d9c2a2c1 100644 --- a/CairoMakie/src/utils.jl +++ b/CairoMakie/src/utils.jl @@ -193,7 +193,18 @@ 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 @@ -201,8 +212,6 @@ function project_line_points(scene, plot::T, positions, colors, linewidths) wher 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 diff --git a/CairoMakie/test/runtests.jl b/CairoMakie/test/runtests.jl index a506645e4e3..0813c6d337e 100644 --- a/CairoMakie/test/runtests.jl +++ b/CairoMakie/test/runtests.jl @@ -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 \ No newline at end of file