Skip to content

Apply batch position updates after angle changes - #322

Merged
viblo merged 1 commit into
viblo:masterfrom
antonsoo:fix/batch-pose-position
Oct 19, 2026
Merged

viblo merged 1 commit into
viblo:masterfrom
antonsoo:fix/batch-pose-position

Conversation

@antonsoo

Copy link
Copy Markdown
Contributor

Setting position and angle together through the batch API can move a body away from the requested position when its center of gravity is offset. For example, saving a pose and restoring it after a change:

import pymunk
import pymunk.batch as batch

space = pymunk.Space()
body = pymunk.Body(2, 3)
body.center_of_gravity = (2, 3)
body.angle = 0.5
body.position = (7, 8)
space.add(body)

fields = batch.BodyFields.POSITION | batch.BodyFields.ANGLE
data = batch.Buffer()
batch.get_space_bodies(space, fields, data)
body.angle = 1.5
body.position = (-10, -20)
batch.set_space_bodies(space, fields, data)
print(tuple(round(value, 6) for value in body.position))
# Before: (3.832101, 6.615603)
# After:  (7.0, 8.0)

Read the position from its existing buffer location, then apply it after the angle. Changing angle rotates an offset body origin around its center of gravity. The buffer layout stays the same.

A separate native simulation compares batch resets with scalar angle/position updates for density-derived offset polygons. All 18 affected configurations now match the scalar reference exactly through 240 subsequent physics steps, including body state and world bounds; all 54 complete controls remain identical. The regression covers both pose-only and all-field updates, multiple bodies and unchanged buffer bytes.

The documented test runner reports 298 tests with two skips. Both unchanged upstream and this branch also print the same three swallowed nan != nan callback assertions in the existing arbiter test; these remain unresolved. The affected batch tests pass, and Black accepts the changed test file.

@viblo

viblo commented Oct 19, 2026

Copy link
Copy Markdown
Owner

Thanks!

@viblo
viblo merged commit 96fcd90 into viblo:master Oct 19, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants