Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

structure grid expansion #1826

Merged
merged 3 commits into from
May 26, 2024
Merged

structure grid expansion #1826

merged 3 commits into from
May 26, 2024

Conversation

kostmo
Copy link
Member

@kostmo kostmo commented May 7, 2024

Closes #1780.

This change allows "child" structures to be placed outside of the bounds of their "parent" map. Until now, any child structures that exceed the bounds of their parent were simply truncated.

Demo

scripts/play.sh -i data/scenarios/Testing/1780-structure-merge-expansion/structure-composition.yaml

@kostmo kostmo force-pushed the feature/structure-grid-expansion branch 3 times, most recently from 336c132 to 8cd5634 Compare May 10, 2024 08:25
mergify bot pushed a commit that referenced this pull request May 10, 2024
This does two main things to simplify the review of #1826:
* Add the `truncate` option to structure placement.  By default it shall be `true` to maintain the status quo behavior
* Extract a `validatePlacement` function to improve readability
mergify bot pushed a commit that referenced this pull request May 10, 2024
@kostmo kostmo force-pushed the feature/structure-grid-expansion branch 5 times, most recently from f7ae3b6 to 66c9faa Compare May 11, 2024 00:59
@kostmo kostmo marked this pull request as ready for review May 11, 2024 02:00
@kostmo kostmo changed the title [WIP] structure grid expansion structure grid expansion May 11, 2024
@kostmo kostmo force-pushed the feature/structure-grid-expansion branch 2 times, most recently from f227516 to d7ec853 Compare May 12, 2024 03:32
@kostmo kostmo force-pushed the feature/structure-grid-expansion branch from d7ec853 to 4632462 Compare May 12, 2024 03:43
@byorgey
Copy link
Member

byorgey commented May 13, 2024

@kostmo Starting to take a look at this; can you fill in the description with an elevator-pitch version of what this PR is doing?

@kostmo kostmo force-pushed the feature/structure-grid-expansion branch from 4632462 to 9649d74 Compare May 25, 2024 23:01
@kostmo kostmo marked this pull request as draft May 25, 2024 23:02
@kostmo kostmo marked this pull request as ready for review May 26, 2024 00:02
Copy link
Member

@byorgey byorgey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great!

@kostmo kostmo added the merge me Trigger the merge process of the Pull request. label May 26, 2024
@mergify mergify bot merged commit d9b639a into main May 26, 2024
13 checks passed
mergify bot pushed a commit that referenced this pull request Jun 27, 2024
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.
mergify bot pushed a commit that referenced this pull request Sep 16, 2024
…dinates (#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`](https://github.com/swarm-game/swarm/blob/ab13170f4c3d47e6fb3e44d3ec1c86aa91451575/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'
```
mergify bot pushed a commit that referenced this pull request Sep 23, 2024
Builds upon #2127 to fix the remaining issues with #1826.

If a structure incorporates sub-placements entailing northwesterly offsets, its "coordinate origin" will be shifted relative to the top-left cell in the grid.  This updated coordinate origin should be propagated to parent structures for use when placing it.  This includes placement of the main "area" onto the toplevel world map.  This is essential when composing a large scene that needs to line up with features generated by the DSL.

Another bug fixed in this PR involved incorrect "area" computation within sibling placements when both a "northward" and "westward" offset were used; existing tests only covered each of these directions separately.

## Changes in this PR

* Refactoring for readability
* Improved naming
    * Fixed typo `padSouthwest` -> `padNorthwest`
* Export some functions for unit tests
* Utilize propagated coordinate offset in `WorldDescription`

## Testing

### Unit tests

```
scripts/test/run-tests.sh swarm-unit --test-options '--pattern "Overlay"'
```

### Scenarios

```
scripts/play.sh -i data/scenarios/Testing/1780-structure-merge-expansion/coordinate-offset-propagation.yaml --hide-goal
```
| Before | After |
| --- | --- |
| ![Screenshot from 2024-09-22 19-54-13](https://github.com/user-attachments/assets/b7d79232-7435-4cdf-a586-4df4df5cd978) | ![Screenshot from 2024-09-22 19-50-10](https://github.com/user-attachments/assets/4c6a248c-153c-4461-9012-526f59d1ce35) |

```
scripts/play.sh -i data/scenarios/Testing/1780-structure-merge-expansion/simultaneous-north-and-west-offset.yaml --hide-goal
```


| Before | After |
| --- | --- |
| ![Screenshot from 2024-09-22 19-53-50](https://github.com/user-attachments/assets/2049c905-c283-4c43-adc2-f355ea055ada) | ![Screenshot from 2024-09-22 19-53-07](https://github.com/user-attachments/assets/d120d084-31c6-4a67-855d-e08043a93891) |
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merge me Trigger the merge process of the Pull request.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Grow map bounds to accommodate placed structures
2 participants