to Dir4
Converts the current Dir8 value to the corresponding Dir4 value based on the given rotation direction.
The toDir4
function maps each Dir8
value to a base Dir4
value and adjusts the mapping based on the specified rotation direction.
How it works:
Determine the base Dir4 value: The function maps each
Dir8
value to a baseDir4
value.Adjust based on rotation direction: Depending on whether the rotation is clockwise or counterclockwise, the function adjusts the mapping to include the next or previous
Dir8
value.
Examples:
Clockwise Rotation:
UP
andUP_RIGHT
both map toUP
.RIGHT
andDOWN_RIGHT
both map toRIGHT
.DOWN
andDOWN_LEFT
both map toDOWN
.LEFT
andUP_LEFT
both map toLEFT
.Counterclockwise Rotation:
UP
andUP_LEFT
both map toUP
.RIGHT
andUP_RIGHT
both map toRIGHT
.DOWN
andDOWN_RIGHT
both map toDOWN
.LEFT
andDOWN_LEFT
both map toLEFT
.
Return
The corresponding Dir4 value.
Parameters
The direction to rotate (CLOCKWISE or COUNTERCLOCKWISE).