Prozi / detect-collisions

Detect collisions between different shapes such as Points, Lines, Boxes, Polygons (including concave), Ellipses, and Circles. Features include RayCasting and support for offsets, rotation, scaling, bounding box padding, with options for static and trigger bodies (non-colliding).
https://prozi.github.io/detect-collisions/
MIT License
202 stars 21 forks source link

Setting width or height of a Box does not respect isCentered property #70

Closed joeynenni closed 6 months ago

joeynenni commented 7 months ago

If you create a Box with isCentered: true option and then adjust the width or height the Box is repositions itself as if isCentered was false.

In order to preserve the isCentered property of the box you currently need to do the following:

const box = new Box({ x: 10, y: 10 }, 5, 5, { isCentered: true })

box.width = 8
box.height = 8

// extra hack to preserve isCentered property
const centroid = box.getCentroidWithoutRotation()
const x = centroid.x * (box.isCentered ? 1 : -1)
const y = centroid.y * (box.isCentered ? 1 : -1)
box.translate(-x, -y)
Prozi commented 6 months ago

@joeynenni thank you very much for this bug report

I will check this and fix in upcoming days

thank you <3

Prozi commented 6 months ago

fixed in ^9.4.1 thanks

joeynenni commented 6 months ago

I tested the fix and it works great, thank you!