windfish-studio / ddrt Goto Github PK
View Code? Open in Web Editor NEWAn elixir implementation of Rtree, optimized for fast updates.
License: GNU Lesser General Public License v2.1
An elixir implementation of Rtree, optimized for fast updates.
License: GNU Lesser General Public License v2.1
I've been using this lib with great success but recently I've been hitting a bug with small bounding boxes crashing DDRT.
Isolating the issue from the stacktrace and getting to a minimal repro was pretty hard but after some debugging time I got there:
This is fine:
DynamicRtree.new(type: MerkleMap)
{:ok, t} = DynamicRtree.insert({0, [{9, 10}, {9, 10}]})
{:ok, t} = DynamicRtree.insert({1, [{9, 9}, {9, 9.1}]})
fine as well:
DynamicRtree.new(type: MerkleMap)
{:ok, t} = DynamicRtree.insert({0, [{9, 9.1}, {9, 9.1}]})
but this crashes (notice the bounding box is a really small triangle):
DynamicRtree.new(type: MerkleMap)
{:ok, t} = DynamicRtree.insert({1, [{9, 9}, {9, 9.1}]})
and this crashes as well (the bounding box has an area of 0):
DynamicRtree.new(type: MerkleMap)
{:ok, t} = DynamicRtree.insert({1, [{9, 9}, {9, 9}]})
The crash looks like this:
17:46:17.597 [error] GenServer DDRT terminating
** (ArgumentError) argument error
:erlang.tl([])
(ddrt 0.2.1) lib/ddrt/dynamic_rtree_impl/utils.ex:44: DDRT.DynamicRtreeImpl.Utils.combine_multiple/1
(ddrt 0.2.1) lib/ddrt/dynamic_rtree_impl.ex:263: anonymous fn/3 in DDRT.DynamicRtreeImpl.add_entry/3
(elixir 1.11.2) lib/map.ex:818: Map.update!/3
(merkle_map 0.2.0) lib/merkle_map.ex:221: MerkleMap.update!/3
(ddrt 0.2.1) lib/ddrt/dynamic_rtree_impl.ex:262: DDRT.DynamicRtreeImpl.add_entry/3
(ddrt 0.2.1) lib/ddrt/dynamic_rtree_impl.ex:246: DDRT.DynamicRtreeImpl.insertion/3
(ddrt 0.2.1) lib/ddrt/dynamic_rtree_impl.ex:79: DDRT.DynamicRtreeImpl.tree_insert/2
(ddrt 0.2.1) lib/ddrt/dynamic_rtree.ex:506: DDRT.DynamicRtree.handle_call/3
(stdlib 3.13.2) gen_server.erl:706: :gen_server.try_handle_call/4
(stdlib 3.13.2) gen_server.erl:735: :gen_server.handle_msg/6
(stdlib 3.13.2) proc_lib.erl:226: :proc_lib.init_p_do_apply/3
It only seems to appear when (1) the tree is empty, and (2) the bounding box is either a triangle or has a 0 area.
I gave solving this a few attempts but without success.
Here are two failing tests reproducing the issue:
test "MerkleMap inserts a triangular bounding box without crash" do
DynamicRtree.new(type: MerkleMap)
{:ok, t} = DynamicRtree.insert({1, [{9, 9}, {9, 9.1}]})
assert t == DynamicRtree.tree()
root = t |> MerkleMap.get(:root)
{ch, _root_ptr, root_box} = t |> MerkleMap.get(root)
assert t |> Enum.to_list() |> length == t |> Enum.uniq() |> length
assert length(ch) == 1
assert root_box == [{9, 9}, {9, 9.1}]
end
test "MerkleMap inserts a zero area bounding box without crash" do
DynamicRtree.new(type: MerkleMap)
{:ok, t} = DynamicRtree.insert({1, [{9, 9}, {9, 9}]})
assert t == DynamicRtree.tree()
root = t |> MerkleMap.get(:root)
{ch, _root_ptr, root_box} = t |> MerkleMap.get(root)
assert t |> Enum.to_list() |> length == t |> Enum.uniq() |> length
assert length(ch) == 1
assert root_box == [{9, 9}, {9, 9}]
end
We would really like to extend the library in such a way that the end-user can choose between an RTree or a QuadTree for the underlying data structure, while maintaining the distributed nature of the library.
It's not entirely clear when we'll have the time to make this change, but we would appreciate anybody willing to work with us to integrate this functionality into our library via a pull-request.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.