detect-collisions icon indicating copy to clipboard operation
detect-collisions copied to clipboard

Offset not exposed on Circle, though present on SAT implementation

Open BobGneu opened this issue 3 years ago • 2 comments

Good day,

I have recently been working with the Circle bodies and have a case where the offset value would be very helpful.

https://github.com/jriecken/sat-js/blob/master/SAT.js#L291-L294

I can have a PR in for this over the weekend, just checking to see if there was a philosophical difference in goals or any other impediment in exposing it prior.

BobGneu avatar Sep 09 '22 21:09 BobGneu

Good day,

I have recently been working with the Circle bodies and have a case where the offset value would be very helpful.

https://github.com/jriecken/sat-js/blob/master/SAT.js#L291-L294

I can have a PR in for this over the weekend, just checking to see if there was a philosophical difference in goals or any other impediment in exposing it prior.

hello

strange since Circle extends SAT.Circle

no philosophical reason of not exposing it

if you have pr with a fix feel free to submit it

thank you

nenjack avatar Sep 10 '22 10:09 nenjack

It looks like it is rooted in the typedef upstream, SATs signatures don't reflect the fact that its exposed.

I have validated tests, build, and local execution with start. Looks good to me. May play around in the local execution to include an offset circle in the test cases there.

Is there any documentation that would be helpful?

BobGneu avatar Sep 12 '22 22:09 BobGneu

Quick update

So, looks like the calculations for the aabb of the circle are not taking the offset value into account. I am still debugging, More details to follow.

BobGneu avatar Sep 19 '22 16:09 BobGneu

Quick update

So, looks like the calculations for the aabb of the circle are not taking the offset value into account. I am still debugging, More details to follow.

this looks like it's because

https://github.com/Prozi/detect-collisions/blob/master/src/bodies/circle.ts#L160-L167

please try overriding this function and adding offset to pos then it should work

don't know about rotation though

nenjack avatar Sep 19 '22 16:09 nenjack

I've created a branch for test purpouses of this issue

https://github.com/Prozi/detect-collisions/tree/issue-36

please check it out @BobGneu it seems if you run

yarn build
yarn demo

and open the tank demo http://localhost:4200/

if tank loads as box (50% chance) it has correct collisions

if it loads as circle (50% chance) seems like it should work, but doesnt, maybe the sat:

import {
  testCircleCircle,
  testCirclePolygon,
  testPolygonCircle,
} from "sat";

don't take offset of circle into account.

i am to tired to check today.

have a nice day

nenjack avatar Sep 20 '22 16:09 nenjack

I managed to implement offset for circles

@BobGneu please check v6.6.0

nenjack avatar Nov 09 '22 19:11 nenjack

Thank you for getting it in there, will check bright and early tomorrow. Very appreciated.

BobGneu avatar Nov 14 '22 05:11 BobGneu

Looks like the signature for setOffset is not exactly correct, SAT appears to expose setOffset such that it should return a Circle.

Something like this may be in order:

  setOffset(offset: Vector): Circle {
	// ...

    return this;
  }

Thoughts?

BobGneu avatar Nov 14 '22 06:11 BobGneu

Looks like the signature for setOffset is not exactly correct, SAT appears to expose setOffset such that it should return a Circle.

Something like this may be in order:

  setOffset(offset: Vector): Circle {
	// ...

    return this;
  }

Thoughts?

will fix this now

thanks

nenjack avatar Nov 15 '22 22:11 nenjack

please try v6.6.1 where I did as you mentioned above

nenjack avatar Nov 15 '22 22:11 nenjack

closing until something else wrong with offset on circle :)

feel free to reopen if something wrong

nenjack avatar Nov 17 '22 16:11 nenjack