glitchybunny / Drawry

Web based multiplayer drawing game, built with socket.io and fabric.js
MIT License
4 stars 0 forks source link

Angle difference breaks when angle is close to 0 [shader-renderer branch] #22

Closed glitchybunny closed 3 years ago

glitchybunny commented 3 years ago

I'm not sure why, but corners aren't being generated properly on lines heading towards 0 degrees that suddenly swap direction and go backwards, as seen here: image

I've been able to successfully replicate this, but only at that specific angle. It doesn't occur at any other angles. It's either related to imprecision of atan2 in angle.directionI(), or an issue with how I'm calculating angle.difference().

Code below: https://github.com/darkrilin/open-picturephone/blob/ec4fcbd2c8306071344f60511610cd81f88e2a4f/static/js/fabric-regl.js#L17-L34

glitchybunny commented 3 years ago

After way too much unnecessary agony, I've discovered the issue wasn't with the angle code at all, and was actually just an extremely dumb logic error.

https://github.com/darkrilin/open-picturephone/blob/ec4fcbd2c8306071344f60511610cd81f88e2a4f/static/js/fabric-regl.js#L99

this line was intended to ensure that dirPrev isn't equal to undefined, but I failed to consider that angles can be equal to 0, which would also return false

it's such a simple fix

screams