ALGO: fix bug when a pointer is between multiple quads
We have to set a priority, otherwise a point might belong to multiple quads (max 4 if it's in the very middle).
This commit is contained in:
parent
60dc8ae535
commit
068ea04d56
@ -18,6 +18,7 @@ module Algorithms.RangeSearch.Core
|
|||||||
import Algebra.VectorTypes
|
import Algebra.VectorTypes
|
||||||
import Algebra.Vector
|
import Algebra.Vector
|
||||||
import Data.Foldable (foldlM)
|
import Data.Foldable (foldlM)
|
||||||
|
import Data.List (partition)
|
||||||
import Data.Maybe (fromJust)
|
import Data.Maybe (fromJust)
|
||||||
import Diagrams.TwoD.Types
|
import Diagrams.TwoD.Types
|
||||||
|
|
||||||
@ -83,12 +84,16 @@ isSEchild _ = False
|
|||||||
quadTree :: [PT] -- ^ the points to divide
|
quadTree :: [PT] -- ^ the points to divide
|
||||||
-> Square -- ^ the initial square around the points
|
-> Square -- ^ the initial square around the points
|
||||||
-> QuadTree PT -- ^ the quad tree
|
-> QuadTree PT -- ^ the quad tree
|
||||||
quadTree pts' sq' = go (flip filter pts' . inRange $ sq') sq'
|
quadTree [] _ = TNil
|
||||||
|
quadTree [pt] _ = TLeaf pt
|
||||||
|
quadTree pts sq = TNode (quadTree nWPT . nwSq $ sq) (quadTree nEPT . neSq $ sq)
|
||||||
|
(quadTree sWPT . swSq $ sq) (quadTree sEPT . seSq $ sq)
|
||||||
where
|
where
|
||||||
go [] _ = TNil
|
-- this sets the priority in case a point is between multiple quads
|
||||||
go [pt] _ = TLeaf pt
|
(sWPT, sWO) = flip partition pts . inRange . swSq $ sq
|
||||||
go pts sq = TNode (quadTree pts . nwSq $ sq) (quadTree pts . neSq $ sq)
|
(nWPT, nWO) = flip partition sWO . inRange . nwSq $ sq
|
||||||
(quadTree pts . swSq $ sq) (quadTree pts . seSq $ sq)
|
(nEPT, nEO) = flip partition nWO . inRange . neSq $ sq
|
||||||
|
sEPT = flip filter nEO . inRange . seSq $ sq
|
||||||
|
|
||||||
|
|
||||||
-- |Get all squares of a quad tree.
|
-- |Get all squares of a quad tree.
|
||||||
|
Loading…
Reference in New Issue
Block a user