Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
46ea52a
automatic formatting
ffreyer Feb 3, 2025
9c97cf9
add tests for Rect constructors and refactor constructors
ffreyer Feb 3, 2025
2b62573
test the rest of Rect
ffreyer Feb 3, 2025
47d943b
Merge branch 'master' into ff/test-coverage
ffreyer Feb 3, 2025
2140dde
more tests for basic_types.jl
ffreyer Feb 4, 2025
558b364
add triangulation tests
ffreyer Feb 4, 2025
7782992
treat float precision error, add isapprox for Rects
ffreyer Feb 4, 2025
73aedef
test split_mesh
ffreyer Feb 4, 2025
744c51b
improve meshes.jl coverage
ffreyer Feb 4, 2025
89b9921
refactor boundingboxes, add tests
ffreyer Feb 4, 2025
ca807f2
test and clean up line intersection code
ffreyer Feb 5, 2025
fb756da
fix docs
ffreyer Feb 5, 2025
95ea715
improve Sphere test coverage
ffreyer Feb 5, 2025
23b2346
fix Rect dim truncation
ffreyer Feb 5, 2025
b951535
a few more tests for OffsetIntegers & FixedArrays
ffreyer Feb 5, 2025
34795e3
add basic docs for bounding boxes
ffreyer Feb 5, 2025
bae73b3
add deprecation warning for developers
ffreyer Feb 5, 2025
dc17a63
nvm, doesn't work
ffreyer Feb 5, 2025
e33ff0c
fix docs
ffreyer Feb 5, 2025
358d4d1
explicitly test Rect getters/utility functions
ffreyer Feb 6, 2025
b1ae5f5
add poly promotion for MultiPolygon
ffreyer Feb 7, 2025
1915d31
fix type targeting in connect
ffreyer Feb 7, 2025
f179ff0
fix test failure
ffreyer Feb 7, 2025
e330dec
fix 32Bit, 1.6
ffreyer Feb 7, 2025
50c3abc
add more connect tests
ffreyer Feb 7, 2025
99a3e20
make line intersection changes not breaking
ffreyer Feb 11, 2025
5c248f0
fix and test single-face mesh constructor
ffreyer Feb 11, 2025
e544dd0
fix tests
ffreyer Feb 11, 2025
1be5f72
test Rect union, update
ffreyer Feb 11, 2025
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
Prev Previous commit
Next Next commit
add poly promotion for MultiPolygon
  • Loading branch information
ffreyer committed Feb 7, 2025
commit b1ae5f5f60d002ff44fb6aab0e9f76b3f3e38871
15 changes: 15 additions & 0 deletions src/basic_types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,17 @@ function coordinates(polygon::Polygon{N,T}) where {N,T}
end
end

function Base.promote_rule(::Type{Polygon{N, T1}}, ::Type{Polygon{N, T2}}) where {N, T1, T2}
return Polygon{N, promote_rule(T1, T2)}
end

function Base.convert(::Type{Polygon{N, T}}, poly::Polygon{N}) where {N, T}
return Polygon(
convert(Vector{Point{N, T}}, poly.exterior),
convert(Vector{Vector{Point{N, T}}}, poly.interiors),
)
end

"""
MultiPolygon(polygons::AbstractPolygon)

Expand All @@ -333,6 +344,10 @@ end
function MultiPolygon(polygons::AbstractVector{<:AbstractPolygon{Dim,T}}) where {Dim,T}
return MultiPolygon(convert(Vector{eltype(polygons)}, polygons))
end
function MultiPolygon(polygons::AbstractVector{<:AbstractPolygon{Dim}}) where {Dim}
T = reduce(promote_type, typeof.(polygons), init = eltype(polygons))
return MultiPolygon(convert(Vector{T}, polygons))
end

Base.getindex(mp::MultiPolygon, i) = mp.polygons[i]
Base.size(mp::MultiPolygon) = size(mp.polygons)
Expand Down
5 changes: 3 additions & 2 deletions test/polygons.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,16 @@
p2 = Polygon(OffsetArray(exterior, 0), interiors)
@test p2 == p1

# TODO: promote polygon type automatically when creating MultiPolygon
polygon = Polygon(Point2f.(points))
polygon = Polygon(points)
mp = MultiPolygon([polygon, p1, p2])
@test mp.polygons == [polygon, p1, p2]
@test mp[1] == polygon
@test mp[2] == p1
@test size(mp) == (3,) # TODO: What does size even mean here?
@test length(mp) == 3
@test MultiPolygon(OffsetArray([polygon, p1, p2], 0)) == mp
mp = MultiPolygon([Polygon(Point2f.()), p1, p2])

end

rect = Rect2f(0, 0, 1, 1)
Expand Down