mercredi 21 juin 2017

Refactor if else maths operations with Clamp/Max/Min

basically i want to know how to refactor this:

if (newPos.x >= MAX_X)
     newPos.x = 0;
else if (newPos.x < 0)
     newPos.x = MAX_X - 1;

using Math.Clamp or Math.Min or Math.Max

Basically I have to go through an "array" in two direction, right and left, and when it reaches its max o min element, i want it to go to the other side.

Simulation

Thank you in advance.

Aucun commentaire:

Enregistrer un commentaire