swarm/scripts
Karl Ostmo c2a3220f62
Fix growable structure grids for multiple children with negative coordinates (#2127)
Fixes a bug from #1826.

## Background

Structure definitions can be nested, in that a structure can reference and place multiple "substructures", each with an "offset", to compose something more complicated.  Each placement onto a particular "base" structure is a "child".  Multiple child placements atop the same base structure are "siblings".

It so happened that if a child placement with a "negative" horizontal offset preceded a sibling with non-negative offset, this would result in miscalculated placements.  This had to do with the fact that "growing" the "base grid" in the negative direction means that the original "origin" (that the "offset" of subsequent placements are made with respect to) of the base grid must be shifted further right (to somewhere in the middle of the grid), rather than lying on the left edge.

Conversely, if negative offsets occurred as later siblings, then the placement would be correct (the bug would not be triggered).

## The fix

This fix ensures that sibling placements can be re-ordered without affecting the end result.  There were actually two bugs:
* changes to the origin offset were not propagated between sibling placements (i.e. across iterations of [`foldlM`](ab13170f4c/src/swarm-topography/Swarm/Game/Scenario/Topography/Structure/Assembly.hs (L84)))
* the math for computing combined offset (`originDelta` in the `Semigroup` instance of `PositionedGrid`) was incorrect.

## Other changes
Also implements a `--refresh` option to the `standalone-topography` test for updating image-based test fixtures.

## Bug repro
```
scripts/play.sh -i data/scenarios/Testing/1780-structure-merge-expansion/sequential-placement.yaml
```
| Before (incorrect) | After (correct) |
| --- | --- |
| ![broken](https://github.com/user-attachments/assets/47952f83-b877-4fc2-b6b7-8ceb495e8ba0)| ![fixed](https://github.com/user-attachments/assets/907d8872-bff0-4c41-b1c4-8561bf206b4a) |

# Refreshing test images
```
scripts/test/run-tests.sh standalone-topography --test-options '--refresh'
```
2024-09-16 20:14:44 +00:00
..
gen Minor script fixes (#2048) 2024-08-05 16:21:33 +00:00
normalize Minor script fixes (#2048) 2024-08-05 16:21:33 +00:00
test Minor script fixes (#2048) 2024-08-05 16:21:33 +00:00
validate Fix growable structure grids for multiple children with negative coordinates (#2127) 2024-09-16 20:14:44 +00:00
autoplay-tutorials.sh Minor script fixes (#2048) 2024-08-05 16:21:33 +00:00
build-game.sh Recommend cabal (#1822) 2024-05-06 00:09:33 +00:00
play.sh Recommend cabal (#1822) 2024-05-06 00:09:33 +00:00
remote-repl.sh Reply to Web API run with result (#2108) 2024-08-15 17:54:21 +00:00