packages feed

Octree 0.4 → 0.5

raw patch · 4 files changed

+39/−8 lines, 4 filesdep +markdown-unlitPVP ok

version bump matches the API change (PVP)

Dependencies added: markdown-unlit

API changes (from Hackage documentation)

- Data.Octree: withinRange :: Scalar -> Vector3 -> Octree a -> [(Vector3, a)]
+ Data.Octree: withinRange :: Octree a -> Scalar -> Vector3 -> [(Vector3, a)]

Files

Data/Octree/Internal.hs view
@@ -234,7 +234,7 @@  -- | Inserts a point into an Octree. -- | NOTE: insert accepts duplicate points, but lookup would not find them - use withinRange in such case.-insert ::  (Vector3, a) -> Octree a -> Octree a+insert :: (Vector3, a) -> Octree a -> Octree a insert (pt, dat) ot = applyByPath insert' path ot   where path             = pathTo pt ot         insert' (Leaf l) = fromList ((pt, dat) : l)@@ -286,14 +286,15 @@                                         else vb  -- | Returns all points within Octree that are within a given distance from argument.-withinRange ::  Scalar -> Vector3 -> Octree a -> [(Vector3, a)]-withinRange r pt (Leaf l) = filter (\(lpt, _) -> dist pt lpt <= r) l-withinRange r pt node     = concatMap recurseOctant           . -- recurse over remaining octants, and merge results+withinRange :: Octree a -> Scalar -> Vector3 -> [(Vector3, a)]+withinRange (Leaf l) r pt = filter (\(lpt, _) -> dist pt lpt <= r) l+withinRange node     r pt = concatMap recurseOctant           . -- recurse over remaining octants, and merge results                             filter ((<=r) . snd)              . -- discard octants that are out of range                             octantDistances $ pt - split node   -- find octant distances   where-    recurseOctant (octant, _d) = withinRange r pt . octreeStep node $ octant+    recurseOctant (octant, _d) = (\o -> withinRange o r pt) . octreeStep node $ octant +subnodes :: Octree a -> [Octree a] subnodes (Leaf _) = [] subnodes node     = map (octreeStep node) allOctants 
Octree.cabal view
@@ -1,5 +1,5 @@ name:                Octree-version:             0.4+version:             0.5 stability:           beta homepage:            https://github.com/mgajda/octree package-url:         http://hackage.haskell.org/package/octree@@ -30,8 +30,15 @@    exposed:          True    extensions:       ScopedTypeVariables --- I do not know how to make it work. To test use: runghc tests/test_Octree.hs Test-suite test_Octree   Type:              exitcode-stdio-1.0   Build-depends:     base>=4.0 && < 4.7, AC-Vector >= 2.3.0, QuickCheck >= 2.4.0   Main-is:           tests/test_Octree.hs++Test-suite readme+  type:           exitcode-stdio-1.0+  -- We have a symlink: README.lhs -> README.md+  main-is:        README.lhs+  Build-depends:  base>=4.0 && < 4.7, AC-Vector >= 2.3.0, QuickCheck >= 2.4.0, markdown-unlit+  ghc-options:    -pgmL markdown-unlit+
+ README.lhs view
@@ -0,0 +1,23 @@+This is a simple Octree implementation in Haskell.++To use simply:++~~~ {.haskell}+module Main where++import Data.Octree as O++import Data.Vector.V3++main = do let oct = fromList [(Vector3 1 2 3, "a"),+                              (Vector3 3 4 5, "b"),+                              (Vector3 8 8 8, "c")]+              report msg elt = putStrLn $ msg ++ show elt+          report "Nearest     :" $ O.nearest     oct     $ Vector3 2 2 3+          report "Within range:" $ O.withinRange oct 5.0 $ Vector3 2 2 3+          return ()+~~~++*For now it uses AC-Vector package for vectors, but I may change it to use Tensor package used by OpenGL package, if there is interest.*+*So far I still wait for package with vector operations (like dot, cross producton, vector projection and rejection) on Tensor types.*+
tests/test_Octree.hs view
@@ -84,7 +84,7 @@ prop_fromToList         l = sort l == (sort . toList . fromList $ l) prop_insertionPreserved l = sort l == (sort . toList . foldr insert (Leaf []) $ l) prop_nearest            l pt = nearest (fromList l) pt == naiveNearest pt l-prop_naiveWithinRange   r l pt = naiveWithinRange r pt l == (sort . map fst . withinRange r pt . fromList . tuplify pt $ l)+prop_naiveWithinRange   r l pt = naiveWithinRange r pt l == (sort . map fst . (\o -> withinRange o r pt) . fromList . tuplify pt $ l)  tuplify pt = map (\a -> (a, dist pt a))