toDir4

fun toDir4(dirRotate: DirRotate): 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:

  1. Determine the base Dir4 value: The function maps each Dir8 value to a base Dir4 value.

  2. 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 and UP_RIGHT both map to UP.

  • RIGHT and DOWN_RIGHT both map to RIGHT.

  • DOWN and DOWN_LEFT both map to DOWN.

  • LEFT and UP_LEFT both map to LEFT.

  • Counterclockwise Rotation:

  • UP and UP_LEFT both map to UP.

  • RIGHT and UP_RIGHT both map to RIGHT.

  • DOWN and DOWN_RIGHT both map to DOWN.

  • LEFT and DOWN_LEFT both map to LEFT.

Return

The corresponding Dir4 value.

Parameters

dirRotate

The direction to rotate (CLOCKWISE or COUNTERCLOCKWISE).