packages feed

grid 7.5 → 7.6

raw patch · 3 files changed

+33/−4 lines, 3 filesdep ~cereal

Dependency ranges changed: cereal

Files

grid.cabal view
@@ -1,5 +1,5 @@ name:           grid-version:        7.5+version:        7.6 synopsis:       Tools for working with regular grids (graphs, lattices). description:    Provides tools for working with regular arrangements                 of tiles, such as might be used in a board game or some@@ -22,7 +22,7 @@   hs-source-dirs:  src   build-depends:   base ==4.*,                    base-unicode-symbols ==0.2.*,-                   cereal ==0.4.*,+                   cereal ==0.3.* || ==0.4.*,                    containers ==0.4.2.* || ==0.5.*   ghc-options:     -Wall   exposed-modules: Math.Geometry.Grid,
src/Math/Geometry/GridInternal.hs view
@@ -18,7 +18,7 @@ import Prelude hiding (null)  import Data.Function (on)-import Data.List (groupBy, nub, nubBy, sortBy)+import Data.List ((\\), groupBy, nub, nubBy, sortBy) import Data.Ord (comparing)  -- | A regular arrangement of tiles.@@ -52,6 +52,12 @@   neighbours :: Eq (Index g) => g -> Index g -> [Index g]   neighbours = defaultNeighbours +  -- | @'neighboursOfSet' g as@ returns the indices of the tiles in the+  --   grid @g@ which are adjacent to any of the tiles with index in+  --   @as@.+  neighboursOfSet :: Eq (Index g) => g -> [Index g] -> [Index g]+  neighboursOfSet = defaultNeighboursOfSet+   -- | @'neighbour' g d a@ returns the indices of the tile in the grid   --   @g@ which is adjacent to the tile with index @a@, in the   --   direction @d@.@@ -142,6 +148,11 @@   -- WARNING: this implementation won't work for wrapped grids   defaultNeighbours :: g -> Index g -> [Index g]   defaultNeighbours g a = filter (\b -> distance g a b == 1 ) $ indices g++  -- This should work for wrapped grids, though.+  defaultNeighboursOfSet :: Eq (Index g) => g -> [Index g] -> [Index g]+  defaultNeighboursOfSet g as = ns \\ as+    where ns = nub . concatMap (neighbours g) $ as    -- WARNING: this implementation won't work for wrapped grids   defaultNeighbour :: (Eq (Index g), Eq (Direction g))
test/Math/Geometry/GridQC.hs view
@@ -186,6 +186,22 @@   where g = grid t         (a:b:_) = points t +prop_custom_neighboursOfSet_eq_default+  :: (TestData t, Grid (BaseGrid t), Ord (Index (BaseGrid t)))+    => t -> Property+prop_custom_neighboursOfSet_eq_default t = nonNull g ==>+  neighboursOfSet g as == defaultNeighboursOfSet g as+  where g = grid t+        as = points t++prop_custom_neighboursOfSet_cw_minDistance+  :: (TestData t, Grid (BaseGrid t), Ord (Index (BaseGrid t)))+    => t -> Property+prop_custom_neighboursOfSet_cw_minDistance t = nonNull g ==>+  a `elem` (neighboursOfSet g bs) || minDistance g bs a /= 1 +  where g = grid t+        (a:bs) = points t+ gridProperties    :: (TestData t, Grid (BaseGrid t), Arbitrary t,      Eq (Index (BaseGrid t)), Ord (Index (BaseGrid t)), @@ -204,7 +220,9 @@     ("prop_minimal_paths_have_min_length: " ++ s, prop_minimal_paths_have_min_length),     ("prop_minimal_paths_are_valid: " ++ s, prop_minimal_paths_are_valid),     ("prop_neighbour_cw_directionTo: " ++ s, prop_neighbour_cw_directionTo),-    ("prop_custom_adjacentTilesToward_eq_default: " ++ s, prop_custom_adjacentTilesToward_eq_default)+    ("prop_custom_adjacentTilesToward_eq_default: " ++ s, prop_custom_adjacentTilesToward_eq_default),+    ("prop_custom_neighboursOfSet_eq_default: " ++ s, prop_custom_neighboursOfSet_eq_default),+    ("prop_custom_neighboursOfSet_cw_minDistance: " ++ s, prop_custom_neighboursOfSet_cw_minDistance)   ]  --