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