Use grid when creating block debris

This commit is contained in:
2022-07-13 10:44:18 +01:00
parent 1ccb87ff13
commit 6c50021f04
12 changed files with 139 additions and 65 deletions
+10 -1
View File
@@ -3,9 +3,10 @@ module Geometry.Polygon where
import Geometry.Data
import Geometry.LHS
import Geometry.Vector
import ListHelp
import Data.Maybe
import Data.List
--import Data.List
import qualified Control.Foldl as L
-- | Draw an anticlockwise rectangle based on maximal N E S W values.
@@ -111,3 +112,11 @@ grahamEliminate xs = xs
centroid :: Foldable t => t Point2 -> Point2
centroid = L.fold $ (/) <$> L.Fold (+.+) (V2 0 0) id <*> L.genericLength
shrinkPolyOnEdges :: Float -> [Point2] -> [Point2]
shrinkPolyOnEdges x (p:q:ps) = map (shrinkVert x) . slideWindow 3 $ (p:q:ps) ++ [p,q]
shrinkPolyOnEdges _ _ = error "too few vertices in polygon"
shrinkVert :: Float -> [Point2] -> Point2
shrinkVert d (x:y:z:[]) = x +.+ (d *.* (normalizeV (x -.- y))) +.+ (d *.* (normalizeV (z -.- y)))
shrinkVert _ _ = error "wrong number of vertices"