Skip to content

Commit

Permalink
fix bug where dimensions auto-calculation disregards layer offsets
Browse files Browse the repository at this point in the history
  • Loading branch information
FredHappyface committed Mar 30, 2024
1 parent 7782e63 commit 9a3177d
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 7 deletions.
45 changes: 45 additions & 0 deletions .github/workflows/test-lint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: Python Test and Lint

on:
push:
branches:
- '*'
pull_request:
branches:
- main

jobs:
test:
name: Python Test and Lint
runs-on: ubuntu-latest

strategy:
matrix:
python-version:
- '3.9'
- '3.10'
- '3.11'
- '3.12'

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}

- name: Install Poetry
run: |
curl -sSL https://install.python-poetry.org | python3 -
- name: Install dependencies
run: poetry install

- name: Run pytest
run: poetry run pytest

- name: Run ruff
run: poetry run ruff check --output-format=github
continue-on-error: true
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
All major and minor version changes will be documented in this file. Details of
patch-level version changes can be found in [commit messages](../../commits/master).

## 2024.3 - 2024/03/30

- fix bug where dimensions auto-calculation disregards layer offsets https://github.com/FHPythonUtils/LayeredImage/issues/7

## 2024.2.1 - 2024/03/17

- use absolute imports
Expand Down
9 changes: 5 additions & 4 deletions layeredimage/layeredimage.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,14 @@ def __init__(
self.groups = self.extractGroups()
self.layers = self.extractLayers()
# If the user does not specify the dimensions use the largest x and y of
# the layers and groups
# the layers and groups, include offsets
self.dimensions = dimensions or (0, 0)
lyrOrGrpX = [lyrOrGrp.dimensions[0] + lyrOrGrp.offsets[0] for lyrOrGrp in layersAndGroups]
lyrOrGrpY = [lyrOrGrp.dimensions[1] + lyrOrGrp.offsets[1] for lyrOrGrp in layersAndGroups]
if dimensions is None:
layerDimens = [layerOrGroup.dimensions for layerOrGroup in layersAndGroups]
self.dimensions = (
max(layerDimen[0] for layerDimen in layerDimens),
max(layerDimen[1] for layerDimen in layerDimens),
max(lyrOrGrpX or [0]),
max(lyrOrGrpY or [0]),
)
self.extras = kwargs

Expand Down
5 changes: 2 additions & 3 deletions layeredimage/layergroup.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,10 +164,9 @@ def __init__(
# the layers
self.dimensions = dimensions or (0, 0)
if dimensions is None:
layerDimens = [layer.dimensions for layer in layers]
self.dimensions = (
max(dimensions[0] for dimensions in layerDimens),
max(dimensions[1] for dimensions in layerDimens),
max(layer.dimensions[0] + layer.offsets[0] for layer in layers),
max(layer.dimensions[1] + layer.offsets[1] for layer in layers),
)

def json(self) -> dict[str, Any]:
Expand Down

0 comments on commit 9a3177d

Please sign in to comment.