From d9382ad21e02d6190d4b8bcc24d2733c0fc5771c Mon Sep 17 00:00:00 2001 From: Karl Ostmo Date: Wed, 26 Jun 2024 18:42:34 -0700 Subject: [PATCH] Remove grid overlay truncation behavior (#1995) In the implementation of #1826, I decided to preserve the old truncating behavior as the default. But after some consideration, there's no real use case for the old behavior, so let's take it out to simplify the code. --- .../nonoverlapping-structure-merge.yaml | 2 - .../root-map-expansion.yaml | 1 - .../structure-composition.yaml | 10 ---- .../standalone-topography/checkerboard.yaml | 10 ---- .../circle-and-crosses.yaml | 7 --- .../Game/Scenario/Topography/Placement.hs | 2 - .../Scenario/Topography/Structure/Assembly.hs | 47 ++----------------- 7 files changed, 4 insertions(+), 75 deletions(-) diff --git a/data/scenarios/Testing/1780-structure-merge-expansion/nonoverlapping-structure-merge.yaml b/data/scenarios/Testing/1780-structure-merge-expansion/nonoverlapping-structure-merge.yaml index 3a9dac3d8..ab52dbb73 100644 --- a/data/scenarios/Testing/1780-structure-merge-expansion/nonoverlapping-structure-merge.yaml +++ b/data/scenarios/Testing/1780-structure-merge-expansion/nonoverlapping-structure-merge.yaml @@ -37,10 +37,8 @@ world: xx placements: - src: vertical rectangle - truncate: false offset: [-7, 7] - src: horizontal rectangle - truncate: false offset: [7, -7] placements: - src: disjoint rectangles diff --git a/data/scenarios/Testing/1780-structure-merge-expansion/root-map-expansion.yaml b/data/scenarios/Testing/1780-structure-merge-expansion/root-map-expansion.yaml index b98764ff5..84ee605bf 100644 --- a/data/scenarios/Testing/1780-structure-merge-expansion/root-map-expansion.yaml +++ b/data/scenarios/Testing/1780-structure-merge-expansion/root-map-expansion.yaml @@ -24,7 +24,6 @@ world: x placements: - src: single tree - truncate: false offset: [-2, -4] map: | i. diff --git a/data/scenarios/Testing/1780-structure-merge-expansion/structure-composition.yaml b/data/scenarios/Testing/1780-structure-merge-expansion/structure-composition.yaml index 9ee2f24bc..de0dc79f1 100644 --- a/data/scenarios/Testing/1780-structure-merge-expansion/structure-composition.yaml +++ b/data/scenarios/Testing/1780-structure-merge-expansion/structure-composition.yaml @@ -45,9 +45,7 @@ world: map: "" placements: - src: vertical rectangle - truncate: false - src: horizontal rectangle - truncate: false - name: combined rectangles single cell base structure: palette: @@ -56,9 +54,7 @@ world: x placements: - src: vertical rectangle - truncate: false - src: horizontal rectangle - truncate: false - name: multi overlap structure: palette: @@ -68,19 +64,14 @@ world: placements: - src: vertical rectangle offset: [1, 0] - truncate: false - src: horizontal rectangle - truncate: false offset: [0, -2] - src: vertical rectangle offset: [3, -2] - truncate: false - src: horizontal rectangle - truncate: false offset: [3, -4] - src: vertical rectangle offset: [5, -4] - truncate: false placements: - src: vertical rectangle offset: [1, -1] @@ -88,7 +79,6 @@ world: offset: [1, -1] - src: multi overlap offset: [1, -6] - truncate: false - src: combined rectangles blank base offset: [6, -1] - src: combined rectangles empty base diff --git a/data/test/standalone-topography/checkerboard.yaml b/data/test/standalone-topography/checkerboard.yaml index a9dfac695..23118a148 100644 --- a/data/test/standalone-topography/checkerboard.yaml +++ b/data/test/standalone-topography/checkerboard.yaml @@ -15,10 +15,8 @@ structures: placements: - src: checker pair offset: [0, 0] - truncate: false - src: checker pair offset: [0, -4] - truncate: false orient: up: south - name: checker octo @@ -27,27 +25,19 @@ structures: placements: - src: checker quad offset: [0, 0] - truncate: false - src: checker quad offset: [8, 0] - truncate: false - src: checker quad offset: [0, -8] - truncate: false - src: checker quad offset: [8, -8] - truncate: false placements: - src: checker octo offset: [0, 0] - truncate: false - src: checker octo offset: [16, 0] - truncate: false - src: checker octo offset: [0, -16] - truncate: false - src: checker octo offset: [16, -16] - truncate: false map: "" diff --git a/data/test/standalone-topography/circle-and-crosses.yaml b/data/test/standalone-topography/circle-and-crosses.yaml index 052f4daf3..e5f650bd1 100644 --- a/data/test/standalone-topography/circle-and-crosses.yaml +++ b/data/test/standalone-topography/circle-and-crosses.yaml @@ -20,10 +20,8 @@ structures: placements: - src: beam offset: [0, 3] - truncate: false - src: beam offset: [-3, -3] - truncate: false orient: up: east map: "" @@ -44,23 +42,18 @@ structures: placements: - src: cross offset: [0, -15] - truncate: false - src: cross offset: [0, 0] - truncate: false orient: up: east - src: cross offset: [15, 0] - truncate: false orient: up: south - src: cross offset: [15, -15] - truncate: false orient: up: west - src: disc offset: [8, -8] - truncate: false map: "" diff --git a/src/swarm-topography/Swarm/Game/Scenario/Topography/Placement.hs b/src/swarm-topography/Swarm/Game/Scenario/Topography/Placement.hs index 8a7fdc977..c9faa6a83 100644 --- a/src/swarm-topography/Swarm/Game/Scenario/Topography/Placement.hs +++ b/src/swarm-topography/Swarm/Game/Scenario/Topography/Placement.hs @@ -76,7 +76,6 @@ data Pose = Pose data Placement = Placement { src :: StructureName - , truncateOverlay :: Bool , structurePose :: Pose } deriving (Eq, Show) @@ -84,7 +83,6 @@ data Placement = Placement instance FromJSON Placement where parseJSON = withObject "structure placement" $ \v -> do src <- v .: "src" - truncateOverlay <- v .:? "truncate" .!= True offset <- v .:? "offset" .!= origin orient <- v .:? "orient" .!= defaultOrientation let structurePose = Pose offset orient diff --git a/src/swarm-topography/Swarm/Game/Scenario/Topography/Structure/Assembly.hs b/src/swarm-topography/Swarm/Game/Scenario/Topography/Structure/Assembly.hs index a58648482..b10703c5f 100644 --- a/src/swarm-topography/Swarm/Game/Scenario/Topography/Structure/Assembly.hs +++ b/src/swarm-topography/Swarm/Game/Scenario/Topography/Structure/Assembly.hs @@ -10,7 +10,6 @@ module Swarm.Game.Scenario.Topography.Structure.Assembly ( ) where -import Control.Applicative ((<|>)) import Control.Arrow (left, (&&&)) import Control.Monad (when) import Data.Coerce @@ -40,22 +39,17 @@ overlaySingleStructure :: Either Text (MergedStructure (Maybe a)) overlaySingleStructure inheritedStrucDefs - (Placed p@(Placement _ shouldTruncate pose@(Pose loc orientation)) ns) + (Placed p@(Placement _ pose@(Pose loc orientation)) ns) (MergedStructure inputArea inputPlacements inputWaypoints) = do MergedStructure overlayArea overlayPlacements overlayWaypoints <- mergeStructures inheritedStrucDefs (WithParent p) $ structure ns let mergedWaypoints = inputWaypoints <> map (fmap $ placeOnArea overlayArea) overlayWaypoints mergedPlacements = inputPlacements <> map (placeOnArea overlayArea) overlayPlacements - mergedArea = mergeFunc (gridContent inputArea) pose overlayArea + mergedArea = overlayGridExpanded (gridContent inputArea) pose overlayArea return $ MergedStructure mergedArea mergedPlacements mergedWaypoints where - mergeFunc = - if shouldTruncate - then overlayGridTruncated - else overlayGridExpanded - placeOnArea (PositionedGrid _ overArea) = offsetLoc (coerce loc) . modifyLoc (reorientLandmark orientation $ getGridDimensions overArea) @@ -113,39 +107,6 @@ overlayGridExpanded reorientedOverlayCells = Grid $ applyOrientationTransform orientation overlayArea positionedOverlay = PositionedGrid loc reorientedOverlayCells --- | NOTE: This ignores the 'loc' parameter of 'PositionedGrid'. -overlayGridTruncated :: - Grid (Maybe a) -> - Pose -> - PositionedGrid (Maybe a) -> - PositionedGrid (Maybe a) -overlayGridTruncated - (Grid inputArea) - (Pose (Location colOffset rowOffset) orientation) - (PositionedGrid _ (Grid overlayArea)) = - PositionedGrid origin - . Grid - . zipWithPad mergeSingleRow inputArea - $ paddedOverlayRows overlayArea - where - zipWithPad f a b = zipWith f a $ b <> repeat Nothing - - mergeSingleRow inputRow maybeOverlayRow = - zipWithPad (flip (<|>)) inputRow paddedSingleOverlayRow - where - paddedSingleOverlayRow = maybe [] (applyOffset colOffset) maybeOverlayRow - - affineTransformedOverlay = applyOrientationTransform orientation - - paddedOverlayRows = applyOffset (negate rowOffset) . map Just . affineTransformedOverlay - applyOffset offsetNum = modifyFront - where - integralOffset = fromIntegral offsetNum - modifyFront = - if integralOffset >= 0 - then (replicate integralOffset Nothing <>) - else drop $ abs integralOffset - -- * Validation elaboratePlacement :: Parentage Placement -> Text @@ -158,7 +119,7 @@ elaboratePlacement p = where pTxt = case p of Root -> "root placement" - WithParent (Placement (StructureName sn) _shouldTruncate (Pose loc _)) -> + WithParent (Placement (StructureName sn) (Pose loc _)) -> T.unwords [ "placement of" , quote sn @@ -172,7 +133,7 @@ validatePlacement :: Either Text (Placed (Maybe a)) validatePlacement structureMap - placement@(Placement sName@(StructureName n) _shouldTruncate (Pose _ orientation)) = do + placement@(Placement sName@(StructureName n) (Pose _ orientation)) = do t@(_, ns) <- maybeToEither (T.unwords ["Could not look up structure", quote n])