lambdabot

Untitled

May 10th, 2016
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. {-# LANGUAGE ParallelArrays #-}
  2. {-# OPTIONS -fvectorise #-}
  3.  
  4. module Vectorised (quickhullPA) where
  5. import Points2D.Types
  6. import Data.Array.Parallel
  7. import Data.Array.Parallel.Prelude.Bool
  8. import Data.Array.Parallel.Prelude.Double        as D
  9. import qualified Data.Array.Parallel.Prelude.Int as I
  10. import qualified Prelude as P
  11.  
  12.  
  13. distance :: Point -> Line -> Double
  14. distance (xo, yo) ((x1, y1), (x2, y2))
  15.   = (x1 D.- xo) D.* (y2 D.- yo) D.- (y1 D.- yo) D.* (x2 D.- xo)
  16.  
  17.  
  18. hsplit :: [:Point:] -> Line -> [:Point:]
  19. hsplit points line@(p1, p2)
  20.   | lengthP packed I.== 0 = [:p1:]
  21.   | otherwise
  22.   = concatP [: hsplit packed ends | ends <- [:(p1, pm), (pm, p2):] :]
  23.   where
  24.     cross  = [: distance p line | p <- points :]
  25.     packed = [: p | (p,c) <- zipP points cross, c D.> 0.0 :]
  26.     pm     = points !: maxIndexP cross
  27.  
  28.  
  29. quickHull :: [:Point:] -> [:Point:]
  30. quickHull points
  31.   | lengthP points I.== 0 = points
  32.   | otherwise
  33.   = concatP [: hsplit points ends | ends <- [: (minx, maxx), (maxx, minx) :] :]
  34.   where
  35.     xs   = [: x | (x, y) <- points :]
  36.     minx = points !: minIndexP xs
  37.     maxx = points !: maxIndexP xs
  38.  
  39.  
  40. quickhullPA :: PArray Point -> PArray Point
  41. quickhullPA ps = toPArrayP (quickHull (fromPArrayP ps))
  42. {-# NOINLINE quickhullPA #-}
Advertisement
Add Comment
Please, Sign In to add comment