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

Fix growable structure grids for multiple children with negative coordinates #2127

Merged
merged 5 commits into from
Sep 16, 2024

Conversation

kostmo
Copy link
Member

@kostmo kostmo commented Aug 19, 2024

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)
  • 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 fixed

Refreshing test images

scripts/test/run-tests.sh standalone-topography --test-options '--refresh'

@kostmo kostmo added the Bug The observed behaviour is incorrect or unexpected. label Aug 19, 2024
@kostmo kostmo force-pushed the testing/structure-expansion branch from 7bf111e to 477b93d Compare August 24, 2024 04:43
@kostmo kostmo force-pushed the testing/structure-expansion branch from 477b93d to 8df7dea Compare August 25, 2024 00:21
@kostmo kostmo added the T-Testing Involves the testing suite - unit and integration tests, also benchmarks. label Sep 14, 2024
@kostmo kostmo changed the title [WIP] another test case for structure placement another test case for structure placement Sep 16, 2024
@kostmo kostmo changed the title another test case for structure placement Fix growable structure grids for multiple children with negative coordinates Sep 16, 2024
@kostmo kostmo marked this pull request as ready for review September 16, 2024 16:46
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.

So what exactly was the bug, and what was the fix? Can you add a summary to the PR description, so a high-level summary of the bug and the fix end up in the commit history once we merge?

test/integration/Main.hs Show resolved Hide resolved
@kostmo kostmo requested a review from byorgey September 16, 2024 19:48
@kostmo kostmo added the merge me Trigger the merge process of the Pull request. label Sep 16, 2024
@mergify mergify bot merged commit c2a3220 into main Sep 16, 2024
14 checks passed
@mergify mergify bot deleted the testing/structure-expansion branch September 16, 2024 20:15
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
Bug The observed behaviour is incorrect or unexpected. merge me Trigger the merge process of the Pull request. T-Testing Involves the testing suite - unit and integration tests, also benchmarks.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants