Skip to content

Commit

Permalink
Fix Float32 constraints in poly pipeline
Browse files Browse the repository at this point in the history
Also fix dimensionality constraints
  • Loading branch information
asinghvi17 committed Nov 21, 2024
1 parent 252d40e commit ba53c40
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/basic_recipes/poly.jl
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,12 @@ end

poly_convert(meshes::AbstractVector{<:AbstractMesh}, transform_func=identity) = poly_convert.(meshes, (transform_func,))

function poly_convert(polys::AbstractVector{<:Polygon}, transform_func=identity)

function poly_convert(polys::AbstractVector{<:Polygon{N, T}}, transform_func=identity) where {N, T}
# GLPlainMesh2D is not concrete?
# TODO is this a problem with Float64 meshes?
T = GeometryBasics.Mesh{2, Float32, GeometryBasics.Ngon{2, Float32, 3, Point2f}, SimpleFaceView{2, Float32, 3, GLIndex, Point2f, GLTriangleFace}}
return isempty(polys) ? T[] : poly_convert.(polys, (transform_func,))
MeshType = GeometryBasics.Mesh{N, T, GeometryBasics.Ngon{N, T, 3, Point{N, T}}, SimpleFaceView{N, T, 3, GLIndex, Point{N, T}, GLTriangleFace}}
return isempty(polys) ? MeshType[] : poly_convert.(polys, (transform_func,))
end

function poly_convert(multipolygons::AbstractVector{<:MultiPolygon}, transform_func=identity)
Expand Down Expand Up @@ -194,7 +195,9 @@ function plot!(plot::Poly{<: Tuple{<: Union{Polygon, AbstractVector{<: PolyEleme
)
end

function plot!(plot::Mesh{<: Tuple{<: AbstractVector{P}}}) where P <: Union{AbstractMesh, Polygon}
# TODO: for Makie v0.22, GeometryBasics v0.5,
# switch from AbstractMesh{Polytope{N, T}} to AbstractMesh{N, T}
function plot!(plot::Mesh{<: Tuple{<: AbstractVector{P}}}) where P <: Union{<: AbstractMesh{<: Polytope{N, T}}, Polygon{N, T}} where {N, T}
meshes = plot[1]
attrs = Attributes(
visible = plot.visible, shading = plot.shading, fxaa = plot.fxaa,
Expand Down Expand Up @@ -244,7 +247,7 @@ function plot!(plot::Mesh{<: Tuple{<: AbstractVector{P}}}) where P <: Union{Abst
bigmesh = lift(plot, meshes, transform_func) do meshes, tf
if isempty(meshes)
# TODO: Float64
return GeometryBasics.Mesh(Point2f[], GLTriangleFace[])
return GeometryBasics.Mesh(Point{N, T}[], GLTriangleFace[])
else
triangle_meshes = map(mesh -> poly_convert(mesh, tf), meshes)
return merge(triangle_meshes)
Expand Down
17 changes: 17 additions & 0 deletions test/poly.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using Makie
using Makie.GeometryBasics

@testset "poly_convert with empty Float64 polygon vector" begin
polygons = Observable(Polygon{2,Float64}[])

@testset "Unit test: poly_convert" begin
@test Makie.poly_convert(Polygon{2,Float64}[], identity) isa Vector{<: GeometryBasics.Mesh{2,Float64}}
end

@testset "Integration test: do this with `poly`" begin
poly(polygons)
@test_nowarn push!(polygons[], Polygon([Point(1.0, 2.0), Point(2.0, 3.0), Point(3.0, 2.0)]))
@test_nowarn notify(polygons)

end
end
1 change: 1 addition & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ using Makie: volume
include("barplot.jl")
include("bezier.jl")
include("hist.jl")
include("poly.jl")
include("cameras.jl")

# for short tests of resolved issues
Expand Down

0 comments on commit ba53c40

Please sign in to comment.