DIAG: add kdSquares to draw kd-tree sections
This commit is contained in:
parent
d195d3f11d
commit
0b36b4acb9
@ -5,6 +5,7 @@ module Graphics.Diagram.Plotter where
|
|||||||
import Algebra.VectorTypes
|
import Algebra.VectorTypes
|
||||||
import Algorithms.ConvexHull.GrahamScan
|
import Algorithms.ConvexHull.GrahamScan
|
||||||
import Algorithms.QuadTree.QuadTree
|
import Algorithms.QuadTree.QuadTree
|
||||||
|
import Algorithms.KDTree.KDTree
|
||||||
import Algorithms.PolygonIntersection.Core
|
import Algorithms.PolygonIntersection.Core
|
||||||
import Data.Maybe
|
import Data.Maybe
|
||||||
import Data.Monoid
|
import Data.Monoid
|
||||||
@ -180,6 +181,34 @@ squares = Diag f
|
|||||||
f _ _ = mempty
|
f _ _ = mempty
|
||||||
|
|
||||||
|
|
||||||
|
-- |Draw the squares of the kd-tree.
|
||||||
|
kdSquares:: Diag
|
||||||
|
kdSquares = Diag f
|
||||||
|
where
|
||||||
|
f _ (Object []) = mempty
|
||||||
|
f p (Object vt) =
|
||||||
|
mconcat
|
||||||
|
. fmap fromVertices
|
||||||
|
$ drawAll (kdTree vt Horizontal) (xDimension p, yDimension p)
|
||||||
|
where
|
||||||
|
drawAll :: KDTree PT -> Square -> [[PT]]
|
||||||
|
drawAll (KTNode ln pt Horizontal rn) ((xmin, xmax), (ymin, ymax)) =
|
||||||
|
(\(x, _) -> [[p2 (x, ymin), p2 (x, ymax)]])
|
||||||
|
(unp2 pt)
|
||||||
|
++ drawAll ln ((xmin, x'), (ymin, ymax))
|
||||||
|
++ drawAll rn ((x', xmax), (ymin, ymax))
|
||||||
|
where
|
||||||
|
(x', _) = unp2 pt
|
||||||
|
drawAll (KTNode ln pt Vertical rn) ((xmin, xmax), (ymin, ymax)) =
|
||||||
|
(\(_, y) -> [[p2 (xmin, y), p2 (xmax, y)]])
|
||||||
|
(unp2 pt)
|
||||||
|
++ drawAll ln ((xmin, xmax), (ymin, y'))
|
||||||
|
++ drawAll rn ((xmin, xmax), (y', ymax))
|
||||||
|
where
|
||||||
|
(_, y') = unp2 pt
|
||||||
|
drawAll _ _ = [[]]
|
||||||
|
f _ _ = mempty
|
||||||
|
|
||||||
|
|
||||||
-- |Get the quad tree corresponding to the given points and diagram properties.
|
-- |Get the quad tree corresponding to the given points and diagram properties.
|
||||||
qt :: [PT] -> DiagProp -> QuadTree PT
|
qt :: [PT] -> DiagProp -> QuadTree PT
|
||||||
|
Loading…
Reference in New Issue
Block a user