more efficient math

/!\ this is only correct if x is always comprised between 0 and width, and y between 0 and height

(if this is not certain to be the case, tell me, there could still be ways to make the math more efficient)