Work on grid point creation

This commit is contained in:
2025-10-27 11:50:18 +00:00
parent c676005219
commit 437f5d44d8
2 changed files with 38 additions and 10 deletions
+32 -7
View File
@@ -1,11 +1,14 @@
module Grid where
module Grid (
makeGrid,
gridInPolygon,
shiftedGrid,
gridPoints,
gridPoints'',
) where
import Bound
--import Data.Function (on)
import Data.Bifunctor
import Control.Lens
import Data.List
--import Data.Maybe
import qualified Data.Tuple.Extra as Tup
import Geometry
@@ -41,8 +44,14 @@ shiftedGrid xmin xmax ymin ymax = grid
shift p = bimap (p +.+) (p +.+)
grid = map (shift (V2 (xmin + 20) (ymin + 20))) $ makeGrid 60 xsteps 60 ysteps
-- creates a rectangular grid starting at (0,0) in the positive orthant
-- needs fixing in degenerate (xstep or ystep == 0) cases
-- creates a DAG
gridXsYs :: [Float] -> [Float] -> [(Point2, Point2)]
gridXsYs xs ys =
foldMap (\y -> mkpairs xs & each . each %~ (`V2` y)) ys
<> foldMap (\x -> mkpairs ys & each . each %~ V2 x) xs
where
mkpairs zs = zip zs $ tail zs
makeGrid ::
-- | horizontal step size
Float ->
@@ -54,6 +63,22 @@ makeGrid ::
Int ->
[(Point2, Point2)]
makeGrid x nx y ny =
foldMap doublePair $
gridXsYs (take (nx + 1) [0, x ..]) (take (ny + 1) [0, y ..])
-- creates a rectangular grid starting at (0,0) in the positive orthant
-- needs fixing in degenerate (xstep or ystep == 0) cases
makeGrid' ::
-- | horizontal step size
Float ->
-- | number of horizontal steps
Int ->
-- | vertical step size
Float ->
-- | number of vertical steps
Int ->
[(Point2, Point2)]
makeGrid' x nx y ny =
nub
. concatMap doublePair
. concatMap (\p -> map (Tup.both (p +.+)) $ makeRect x y)