MCPcopy Index your code
hub / github.com/KilledByAPixel/LittleJS / setDirection

Method setDirection

src/engineMath.js:761–772  ·  view source on GitHub ↗

Sets this this vector to point in the specified integer direction (0-3), corresponding to multiples of 90 degree rotation * @param {number} [direction] * @param {number} [length] * @return {Vector2}

(direction, length=1)

Source from the content-addressed store, hash-verified

759 * @param {number} [length]
760 * @return {Vector2} */
761 setDirection(direction, length=1)
762 {
763 ASSERT_NUMBER_VALID(direction);
764 ASSERT_NUMBER_VALID(length);
765 direction = mod(direction, 4);
766 ASSERT(direction===0 || direction===1 || direction===2 || direction===3,
767 'Vector2.setDirection() direction must be an integer between 0 and 3.');
768
769 this.x = direction%2 ? direction-1 ? -length : length : 0;
770 this.y = direction%2 ? 0 : direction ? -length : length;
771 return this;
772 }
773
774 /** Returns the integer direction of this vector, corresponding to multiples of 90 degree rotation (0-3)
775 * @return {number} */

Callers 3

math.test.mjsFile · 0.80
touchGamepadRenderFunction · 0.80
decorateTileFunction · 0.80

Calls 3

ASSERT_NUMBER_VALIDFunction · 0.85
modFunction · 0.85
ASSERTFunction · 0.70

Tested by

no test coverage detected