Prozi / detect-collisions

Points, Lines, Boxes, Polygons (also hollow), Ellipses, Circles. RayCasting, offsets, rotation, scaling, bounding box padding, flags for static and ghost/trigger bodies
https://prozi.github.io/detect-collisions/
MIT License
207 stars 22 forks source link

Fix: circleOutsidePolygon #52

Closed MeroVinggen closed 1 year ago

MeroVinggen commented 1 year ago

I used circleOutsidePolygon function to detec box is not collided to circle and I'm getting false

1

My code:

/* --------------------------------- canvas --------------------------------- */

const canvas = document.querySelector('canvas')!;
const context = canvas.getContext("2d")!;

canvas.height = 700;
canvas.width = 700;

context.strokeStyle = "#ffaa33";
context.fillStyle = "#aa3388";

/* --------------------------------- system --------------------------------- */

const system = new System();
const box1 = new Box({ x: 115, y: 152 }, 100, 100);
const circle1 = new Circle({ x: 100, y: 100 }, 50);
system.insert(box1);
system.insert(circle1);

/* --------------------------------- launch --------------------------------- */

system.draw(context);
context.stroke();

console.log('box1 & circle1: ', circleOutsidePolygon(circle1, box1)); // -> false

Also need functions to detect collision on each Body type, like there is intersectLineCircle & intersectLinePolygon that returns array, but if needed only to detec fact of collision, not making extra operations to gather all collision points, this functions are not the best variant.

Prozi commented 1 year ago

that is good observation and true, but I didnt intend to use utils function for the end-user

might have to rethink that

Prozi commented 1 year ago

still, you've found a bug

Prozi commented 1 year ago

fixed here https://github.com/Prozi/detect-collisions/commit/a71ea395720c52a16277bec3c807b5d344bfc53b

will be added to 7.0