Skip to content

Commit fe01ebe

Browse files
committed
add similar(tree) method
1 parent 57f34bd commit fe01ebe

2 files changed

Lines changed: 18 additions & 0 deletions

File tree

src/rtree/rtree.jl

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,19 @@ RTree{T,N}(::Type{V}; kwargs...) where {T,N,V} =
131131
RTree{T,N}(::Type{K}, ::Type{V}; kwargs...) where {T,N,K,V} =
132132
RTree{T,N,SpatialElem{T,N,K,V}}(; kwargs...)
133133

134+
# create an empty R-tree of the same type and with the same settings as `tree`
135+
Base.similar(tree::RTree) =
136+
typeof(tree)(variant=tree.variant,
137+
tight_mbrs=tree.tight_mbrs,
138+
branch_capacity=capacity(Branch, tree),
139+
leaf_capacity=capacity(Leaf, tree),
140+
leafpool_capacity=capacity(tree.leafpool),
141+
branchpool_capacity=capacity(tree.branchpool),
142+
nearmin_overlap=tree.nearmin_overlap,
143+
fill_factor=tree.fill_factor,
144+
splitdistribution_factor=tree.splitdistribution_factor,
145+
reinsert_factor=tree.reinsert_factor)
146+
134147
mbrtype(::Type{<:RTree{T,N}}) where {T,N} = Rect{T,N}
135148
mbrtype(tree::RTree) = mbrtype(typeof(tree))
136149
regiontype(R::Type{<:RTree}) = mbrtype(R)

test/rtree.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,11 @@ end
8585
@test length(collect(contained_in(tree, SI.Rect((0.0, 0.0), (0.55, 0.55))))) == 1 # a only
8686
@test length(collect(intersects_with(tree, SI.Rect((0.0, 0.0), (0.55, 0.55))))) == 2 # a and c
8787

88+
tree2 = similar(tree)
89+
@test typeof(tree2) === typeof(tree)
90+
@test tree2 !== tree
91+
@test isempty(tree2)
92+
8893
@testset "findfirst()" begin
8994
@test findfirst(tree, ambr, 2) === nothing
9095
@test_throws MethodError findfirst(tree, ambr, "1") # wrong key type

0 commit comments

Comments
 (0)