55 lines
1.7 KiB
C
55 lines
1.7 KiB
C
/* ************************************************************************** */
|
|
/* */
|
|
/* ::: :::::::: */
|
|
/* rotate.h :+: :+: :+: */
|
|
/* +:+ +:+ +:+ */
|
|
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
|
/* +#+#+#+#+#+ +#+ */
|
|
/* Created: 2024/01/29 19:00:18 by maiboyer #+# #+# */
|
|
/* Updated: 2024/01/29 19:27:19 by maiboyer ### ########.fr */
|
|
/* */
|
|
/* ************************************************************************** */
|
|
|
|
#ifndef ROTATE_H
|
|
#define ROTATE_H
|
|
|
|
#include "me/types.h"
|
|
|
|
enum e_rotation_direction
|
|
{
|
|
FORWARD,
|
|
REVERSE,
|
|
};
|
|
typedef struct s_rotation
|
|
{
|
|
t_usize value;
|
|
t_usize ring_size;
|
|
enum e_rotation_direction direction;
|
|
} t_rotation;
|
|
|
|
static inline t_rotation forward(t_usize by, t_usize ring_size)
|
|
{
|
|
return ((t_rotation){
|
|
.value = by % ring_size, .ring_size = ring_size, .direction = FORWARD});
|
|
}
|
|
|
|
static inline t_rotation reverse(t_usize by, t_usize ring_size)
|
|
{
|
|
return ((t_rotation){
|
|
.value = by % ring_size, .ring_size = ring_size, .direction = REVERSE});
|
|
}
|
|
|
|
static inline t_rotation flip(t_rotation rot)
|
|
{
|
|
enum e_rotation_direction flipped;
|
|
|
|
flipped = FORWARD;
|
|
if (rot.direction == FORWARD)
|
|
flipped = REVERSE;
|
|
|
|
return ((t_rotation){.value = rot.ring_size - rot.value,
|
|
.ring_size = rot.ring_size,
|
|
.direction = flipped});
|
|
}
|
|
|
|
#endif /* ROTATE_H */
|