├── .editorconfig ├── .gitignore ├── Makefile ├── README.md ├── auteur ├── includes ├── camera.h ├── interpreter.h ├── keyboard.h ├── light.h ├── matrix.h ├── mouse.h ├── object.h ├── parser.h ├── ray.h ├── rt.h ├── scene.h └── tests.h ├── libft ├── .gitignore ├── LICENSE ├── Makefile ├── README.md ├── includes │ ├── ft_colors.h │ ├── ft_convert.h │ ├── ft_hashmap.h │ ├── ft_input.h │ ├── ft_lists.h │ ├── ft_math.h │ ├── ft_memory.h │ ├── ft_print.h │ ├── ft_strings.h │ └── libft.h ├── objects │ └── .gitignore └── sources │ ├── colors │ ├── blend_colors.c │ ├── color_blend_add.c │ ├── color_blend_over.c │ ├── color_blend_sub.c │ └── fade_color.c │ ├── convert │ ├── ft_abs.c │ ├── ft_atoi.c │ ├── ft_itoa.c │ ├── ft_tolower.c │ ├── ft_toupper.c │ └── hash.c │ ├── hashmap │ └── hashmap.c │ ├── input │ ├── ft_getchar.c │ ├── get_next_line.c │ └── get_stdin_next_line.c │ ├── lists │ ├── ft_lstadd.c │ ├── ft_lstdel.c │ ├── ft_lstdelone.c │ ├── ft_lstfreeto.c │ ├── ft_lstiter.c │ ├── ft_lstmap.c │ ├── ft_lstnew.c │ ├── ft_lstqueueadd.c │ └── ft_lstrev.c │ ├── math │ ├── ft_cossin.c │ ├── ft_sqrt.c │ ├── infin_add.c │ ├── infin_number_gt.c │ ├── load_infin_number.c │ ├── print_infin_number.c │ ├── vector_operations.c │ ├── vector_properties.c │ └── vector_transformations.c │ ├── memory │ ├── ft_bzero.c │ ├── ft_memalloc.c │ ├── ft_memccpy.c │ ├── ft_memchr.c │ ├── ft_memcmp.c │ ├── ft_memcpy.c │ ├── ft_memdel.c │ ├── ft_memdup.c │ ├── ft_memmove.c │ └── ft_memset.c │ ├── print │ ├── exit_with_error.c │ ├── ft_putchar.c │ ├── ft_putchar_fd.c │ ├── ft_putendl.c │ ├── ft_putendl_fd.c │ ├── ft_putlnbr.c │ ├── ft_putnbr.c │ ├── ft_putnbr_fd.c │ ├── ft_putnbrb.c │ ├── ft_putstr.c │ ├── ft_putstr_fd.c │ ├── ft_putunbr.c │ └── ft_putunbr_fd.c │ └── strings │ ├── ft_isalnum.c │ ├── ft_isalpha.c │ ├── ft_isascii.c │ ├── ft_isdigit.c │ ├── ft_isprint.c │ ├── ft_strbeginwith.c │ ├── ft_strcat.c │ ├── ft_strchr.c │ ├── ft_strclr.c │ ├── ft_strcmp.c │ ├── ft_strcpy.c │ ├── ft_strdel.c │ ├── ft_strdup.c │ ├── ft_strequ.c │ ├── ft_strinarray.c │ ├── ft_strisinarray.c │ ├── ft_strisnum.c │ ├── ft_striter.c │ ├── ft_striteri.c │ ├── ft_strjoin.c │ ├── ft_strlcat.c │ ├── ft_strlen.c │ ├── ft_strmap.c │ ├── ft_strmapi.c │ ├── ft_strncat.c │ ├── ft_strncmp.c │ ├── ft_strncpy.c │ ├── ft_strnequ.c │ ├── ft_strnew.c │ ├── ft_strnstr.c │ ├── ft_strrchr.c │ ├── ft_strsplit.c │ ├── ft_strstr.c │ ├── ft_strsub.c │ └── ft_strtrim.c ├── objects └── .gitignore ├── scenes ├── box.scene ├── couteau.scene └── multilight.scene └── sources ├── camera ├── camera_init.c └── camera_transformations.c ├── equations ├── change_ray.c ├── equation_cone.c ├── equation_cylinder.c ├── equation_plane.c ├── equation_sphere.c ├── get_normal.c ├── matrix.c └── positive_smallest.c ├── export ├── export_image.c └── export_scene.c ├── interpreter ├── command_add.c ├── command_antialias.c ├── command_editmode.c ├── command_export.c ├── command_list.c ├── command_recursivity.c ├── command_remove.c ├── command_render.c ├── command_unblock.c ├── init_interpreter.c └── interpreter.c ├── keyboard.c ├── keyboard ├── check_pressed_keys.c ├── keyboard.c ├── keypress_hook.c └── keyrelease_hook.c ├── light_diaphragm.c ├── mouse ├── motion_notify.c └── mouse.c ├── object └── creation.c ├── phong_shading.c ├── pixel.c ├── ray_throw.c ├── render_thread.c ├── render_to_image.c ├── rt.c └── scene_parser ├── command_add_cone.c ├── command_add_cylinder.c ├── command_add_light.c ├── command_add_plane.c ├── command_add_sphere.c ├── command_camera.c ├── command_define_ambient.c ├── command_define_antialias.c ├── command_define_axisx.c ├── command_define_axisy.c ├── command_define_axisz.c ├── command_define_color.c ├── command_define_diaphragm.c ├── command_define_diffuse.c ├── command_define_height.c ├── command_define_intensity.c ├── command_define_normxyz.c ├── command_define_opacity.c ├── command_define_radius.c ├── command_define_recursivity.c ├── command_define_reflection.c ├── command_define_refraction.c ├── command_define_rgb.c ├── command_define_rotxyz.c ├── command_define_specular.c ├── command_define_width.c ├── command_define_xyz.c ├── init_parser.c └── parser.c /.editorconfig: -------------------------------------------------------------------------------- 1 | [*] 2 | indent_size = 4 3 | indent_style = tab 4 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.o 2 | *.a 3 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | RT 2 | == 3 | 4 | > A Simple RayTracer written in C with Live-Edition capability. 5 | 6 | Check demo on YouTube: 7 | 8 | [![42 Raytracer demo](https://img.youtube.com/vi/1JoTZg4Ulo0/0.jpg)](https://www.youtube.com/watch?v=1JoTZg4Ulo0) 9 | 10 | -------------------------------------------------------------------------------- /auteur: -------------------------------------------------------------------------------- 1 | lbinet 2 | acollin 3 | cfeijoo 4 | ikerkeb 5 | -------------------------------------------------------------------------------- /includes/camera.h: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* camera.h :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: cfeijoo +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2014/03/02 17:42:56 by cfeijoo #+# #+# */ 9 | /* Updated: 2014/03/18 16:41:48 by cfeijoo ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #ifndef CAMERA_H 14 | # define CAMERA_H 15 | # include 16 | 17 | typedef struct s_camera 18 | { 19 | t_point origin; 20 | t_vector x_axis; 21 | t_vector y_axis; 22 | t_vector z_axis; 23 | } t_camera; 24 | 25 | void cam_rot_z(t_camera *camera, float angle); 26 | void cam_rot_x(t_camera *camera, float angle); 27 | void cam_rot_y(t_camera *camera, float angle); 28 | void cam_translate(t_camera *camera, float x, float y, float z); 29 | void cam_translate_vector(t_camera *camera, t_vector *v, float coeff); 30 | void cam_move_to(t_camera *camera, float x, float y, float z); 31 | 32 | void init_cam(t_camera *cam, float x, float y, float z); 33 | void init_cam_angle(t_camera *cam, float y, float z); 34 | void update_render_cam(t_camera *render_cam, t_camera *camera); 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /includes/interpreter.h: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* interpreter.h :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: cfeijoo +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2014/03/17 00:50:04 by cfeijoo #+# #+# */ 9 | /* Updated: 2014/03/27 18:14:25 by cfeijoo ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #ifndef INTERPRETER_H 14 | # define INTERPRETER_H 15 | 16 | typedef struct s_interpreter 17 | { 18 | char **last_command; 19 | struct s_command *commands; 20 | } t_interpreter; 21 | 22 | typedef struct s_command 23 | { 24 | char *token; 25 | void (*callback)(char**); 26 | struct s_command *next; 27 | } t_command; 28 | 29 | int create_interpreter_thread(); 30 | void interpreter_init_commands(t_interpreter *interpreter); 31 | void cmd_list(char **line); 32 | void cmd_remove(char **line); 33 | void cmd_add(char **line); 34 | void cmd_export(char **line); 35 | void cmd_antialias(char **line); 36 | void cmd_render(char **line); 37 | void cmd_editmode(char **line); 38 | void cmd_recursivity(char **line); 39 | void cmd_unblock(char **line); 40 | 41 | void export_image(int file); 42 | void export_scene(int file); 43 | 44 | #endif 45 | -------------------------------------------------------------------------------- /includes/keyboard.h: -------------------------------------------------------------------------------- 1 | #ifndef KEYBOARD_H 2 | # define KEYBOARD_H 3 | # include 4 | 5 | # define KEYBOARD_ROT_PLOT M_PI / 200 6 | # define KEYBOARD_MOV_PLOT 0.045 7 | 8 | typedef struct s_pressedkeys 9 | { 10 | int up; 11 | int down; 12 | int left; 13 | int right; 14 | int p_up; 15 | int p_down; 16 | int num_plus; 17 | int num_minus; 18 | int w; 19 | int a; 20 | int s; 21 | int d; 22 | int del; 23 | int shift; 24 | int ctrl; 25 | int alt; 26 | int tab; 27 | int space; 28 | } t_pressedkeys; 29 | 30 | int is_one_key_pressed(t_pressedkeys *keys); 31 | void init_pressed_keys(t_pressedkeys *keys); 32 | int keypress_hook(int keycode, t_pressedkeys *keys); 33 | void check_pressed_keys(t_pressedkeys *keys); 34 | int keyrelease_hook(int keycode, t_pressedkeys *keys); 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /includes/light.h: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* light.h :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: cfeijoo +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2014/03/18 23:53:24 by cfeijoo #+# #+# */ 9 | /* Updated: 2014/03/19 23:03:41 by cfeijoo ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #ifndef LIGHT_H 14 | # define LIGHT_H 15 | # include 16 | 17 | # define LIGHT_DOT 0 18 | # define LIGHT_SPHERE 1 19 | 20 | typedef union u_light_color 21 | { 22 | struct 23 | { 24 | float red; 25 | float green; 26 | float blue; 27 | }; 28 | struct 29 | { 30 | float r; 31 | float g; 32 | float b; 33 | }; 34 | } t_light_color; 35 | 36 | typedef struct s_light 37 | { 38 | char *light; 39 | int type; 40 | t_point origin; 41 | float intensity; 42 | t_vector direction; 43 | t_object *object; 44 | float aperture; 45 | t_light_color color; 46 | struct s_light *next; 47 | } t_light; 48 | 49 | void remove_light(t_scene *scene, t_light *light); 50 | 51 | #endif 52 | -------------------------------------------------------------------------------- /includes/matrix.h: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* matrix.h :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: cfeijoo +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2014/03/26 18:47:14 by cfeijoo #+# #+# */ 9 | /* Updated: 2014/03/26 18:51:34 by cfeijoo ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #ifndef MATRIX_H 14 | # define MATRIX_H 15 | 16 | t_vector matrix_vector_product(float matrix[9], t_vector *a); 17 | t_point matrix_point_product(float matrix[9], t_point *a); 18 | void transformation_matrix(float matrix[9], t_vector *x, 19 | t_vector *y, t_vector *z); 20 | void invert_matrix(float matrix[9], float inverted_matrix[9]); 21 | 22 | #endif 23 | -------------------------------------------------------------------------------- /includes/mouse.h: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* mouse.h :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: cfeijoo +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2014/03/13 02:32:09 by cfeijoo #+# #+# */ 9 | /* Updated: 2014/03/19 22:22:41 by cfeijoo ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #ifndef MOUSE_H 14 | # define MOUSE_H 15 | 16 | int mousepress_ev(int button, int x, int y); 17 | int mouserelease_ev(int button, int x, int y); 18 | int motionnotify_ev(int x, int y, t_env *env); 19 | 20 | #endif 21 | -------------------------------------------------------------------------------- /includes/object.h: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* object.h :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: cfeijoo +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2014/03/05 18:01:22 by lbinet #+# #+# */ 9 | /* Updated: 2014/03/25 16:04:54 by cfeijoo ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #ifndef OBJECT_H 14 | # define OBJECT_H 15 | # include 16 | # include 17 | # include 18 | 19 | # define OBJ_SPHERE 0 20 | # define OBJ_PLANE 1 21 | # define OBJ_CYLINDER 2 22 | # define OBJ_CONE 3 23 | 24 | typedef struct s_object 25 | { 26 | char *name; 27 | int type; 28 | t_point origin; 29 | union 30 | { 31 | struct 32 | { 33 | float rotX; 34 | float rotY; 35 | float rotZ; 36 | }; 37 | t_vector normal; 38 | }; 39 | t_color color; 40 | float opacity; 41 | float ambient; 42 | float diffuse; 43 | float specular; 44 | float reflection; 45 | float refraction; 46 | float refract_index; 47 | union 48 | { 49 | float radius; 50 | float aperture; 51 | }; 52 | struct s_object *next; 53 | } t_object; 54 | 55 | t_object *new_object(int type); 56 | void add_object(t_scene *scene, t_object *object); 57 | void duplicate_object(t_object *object); 58 | void remove_object(t_scene *scene, t_object *object); 59 | 60 | #endif 61 | -------------------------------------------------------------------------------- /includes/ray.h: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ray.h :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: cfeijoo +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2014/03/07 16:30:00 by lbinet #+# #+# */ 9 | /* Updated: 2014/03/27 20:18:44 by cfeijoo ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #ifndef RAY_H 14 | # define RAY_H 15 | # include 16 | # include 17 | 18 | typedef struct s_ray 19 | { 20 | t_point origin; 21 | t_vector direction; 22 | float intensity; 23 | t_light_color color; 24 | t_object *closest; 25 | float inter_t; 26 | } t_ray; 27 | 28 | t_ray get_ray_from_point(float i, float j); 29 | void throw_ray(t_ray *ray, int calculate_light, 30 | t_object *to_ignore, int recursivity); 31 | void throw_ray_predefined(t_ray *ray, int calculate_light, 32 | t_object *obj); 33 | void change_ray(t_ray *ray, t_ray *new_ray, t_object *obj, 34 | t_object *new_obj); 35 | void phong_shading(t_ray *ray); 36 | float sphere_equation(t_object *sphere, t_ray *ray); 37 | float plane_equation(t_object *plane, t_ray *ray); 38 | float cylinder_equation(t_object *cylinder, t_ray *ray); 39 | float cone_equation(t_object *cone, t_ray *ray); 40 | float positive_smallest(float a, float b); 41 | void get_cylinder_normal(t_vector *normal, 42 | t_object *cylinder, t_point *intersection); 43 | void get_cone_normal(t_vector *normal, t_object *cone, 44 | t_point *intersection); 45 | 46 | #endif 47 | -------------------------------------------------------------------------------- /includes/scene.h: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* scene.h :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: cfeijoo +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2014/03/19 23:03:03 by cfeijoo #+# #+# */ 9 | /* Updated: 2014/03/27 17:09:54 by cfeijoo ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #ifndef SCENE_H 14 | # define SCENE_H 15 | 16 | typedef struct s_scene 17 | { 18 | struct s_camera camera; 19 | struct s_camera render_cam; 20 | unsigned int view_width; 21 | unsigned int view_height; 22 | struct s_object *objects; 23 | struct s_light *lights; 24 | float diaphragm; 25 | int recursivity; 26 | unsigned int antialias; 27 | } t_scene; 28 | 29 | #endif 30 | -------------------------------------------------------------------------------- /includes/tests.h: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* tests.h :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: cfeijoo +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2014/03/17 20:34:48 by cfeijoo #+# #+# */ 9 | /* Updated: 2014/03/17 20:42:41 by cfeijoo ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #ifndef TESTS_H 14 | # define TESTS_H 15 | 16 | void create_test_objects(t_scene *scene); 17 | 18 | #endif 19 | -------------------------------------------------------------------------------- /libft/.gitignore: -------------------------------------------------------------------------------- 1 | *.o 2 | *.a 3 | -------------------------------------------------------------------------------- /libft/LICENSE: -------------------------------------------------------------------------------- 1 | This is free and unencumbered software released into the public domain. 2 | 3 | Anyone is free to copy, modify, publish, use, compile, sell, or 4 | distribute this software, either in source code form or as a compiled 5 | binary, for any purpose, commercial or non-commercial, and by any 6 | means. 7 | 8 | In jurisdictions that recognize copyright laws, the author or authors 9 | of this software dedicate any and all copyright interest in the 10 | software to the public domain. We make this dedication for the benefit 11 | of the public at large and to the detriment of our heirs and 12 | successors. We intend this dedication to be an overt act of 13 | relinquishment in perpetuity of all present and future rights to this 14 | software under copyright law. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 19 | IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR 20 | OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 21 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 22 | OTHER DEALINGS IN THE SOFTWARE. 23 | 24 | For more information, please refer to 25 | -------------------------------------------------------------------------------- /libft/includes/ft_colors.h: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_colors.h :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: cfeijoo +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2014/03/02 17:54:50 by cfeijoo #+# #+# */ 9 | /* Updated: 2014/03/02 20:50:29 by cfeijoo ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #ifndef FT_COLORS_H 14 | # define FT_COLORS_H 15 | 16 | # define COLOR_BLEND_OVER 0 17 | # define COLOR_BLEND_ADD 1 18 | # define COLOR_BLEND_SUB 2 19 | # define COLOR_BLEND_MUL 3 20 | # define COLOR_BLEND_DIV 4 21 | # define COLOR_BLEND_HARD_LIGHT 5 22 | # define COLOR_BLEND_SOFT_LIGHT 6 23 | 24 | typedef union u_color 25 | { 26 | struct 27 | { 28 | unsigned char b; 29 | unsigned char g; 30 | unsigned char r; 31 | unsigned char a; 32 | }; 33 | struct 34 | { 35 | unsigned char blue; 36 | unsigned char green; 37 | unsigned char red; 38 | unsigned char alpha; 39 | }; 40 | int color; 41 | } t_color; 42 | 43 | t_color fade_color(t_color a, float opacity); 44 | int blend_colors(int color1, int color2, float coeff, int type); 45 | 46 | t_color color_blend_over(t_color a, t_color b); 47 | t_color color_blend_add(t_color a, t_color b); 48 | t_color color_blend_sub(t_color a, t_color b); 49 | 50 | #endif 51 | -------------------------------------------------------------------------------- /libft/includes/ft_convert.h: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_convert.h :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: cfeijoo +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2014/02/17 19:54:45 by cfeijoo #+# #+# */ 9 | /* Updated: 2014/02/19 19:47:48 by cfeijoo ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #ifndef FT_CONVERT_H 14 | # define FT_CONVERT_H 15 | 16 | int ft_toupper(int c); 17 | int ft_tolower(int c); 18 | int ft_abs(int nb); 19 | int ft_atoi(const char *str); 20 | char *ft_itoa(int n); 21 | unsigned int basic_hash(char *str); 22 | 23 | #endif 24 | -------------------------------------------------------------------------------- /libft/includes/ft_hashmap.h: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_hashmap.h :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: cfeijoo +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2014/02/19 23:41:10 by cfeijoo #+# #+# */ 9 | /* Updated: 2014/02/20 00:27:01 by cfeijoo ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #ifndef FT_HASHMAP_H 14 | # define FT_HASHMAP_H 15 | # include 16 | 17 | typedef struct s_hashmap_var 18 | { 19 | unsigned int hash; 20 | char *name; 21 | void *object; 22 | struct s_hashmap_var *next; 23 | } t_hashmap_var; 24 | 25 | typedef struct s_hashmap 26 | { 27 | unsigned int size; 28 | t_hashmap_var **vars; 29 | } t_hashmap; 30 | 31 | #endif 32 | -------------------------------------------------------------------------------- /libft/includes/ft_input.h: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_input.h :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: kube +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2014/02/17 19:39:39 by cfeijoo #+# #+# */ 9 | /* Updated: 2014/03/11 01:05:55 by kube ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #ifndef FT_INPUT_H 14 | # define FT_INPUT_H 15 | # define GNL_BUFF_SIZE 128000 16 | 17 | typedef struct s_read 18 | { 19 | int size; 20 | int index; 21 | char *read; 22 | struct s_read *next; 23 | } t_read; 24 | 25 | int get_next_line(int file, char **line); 26 | int get_stdin_next_line(char **line); 27 | char ft_getchar(void); 28 | 29 | #endif 30 | -------------------------------------------------------------------------------- /libft/includes/ft_lists.h: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_lists.h :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: cfeijoo +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2014/02/17 19:39:44 by cfeijoo #+# #+# */ 9 | /* Updated: 2014/02/17 20:02:09 by cfeijoo ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #ifndef FT_LISTS_H 14 | # define FT_LISTS_H 15 | # include 16 | 17 | typedef struct s_list 18 | { 19 | void *content; 20 | size_t content_size; 21 | struct s_list *next; 22 | } t_list; 23 | 24 | t_list *ft_lstnew(void const *content, size_t content_size); 25 | void ft_lstdelone(t_list **alst, void (*del)(void *, size_t)); 26 | void ft_lstdel(t_list **alst, void (*del)(void *, size_t)); 27 | void ft_lstadd(t_list **alst, t_list *new); 28 | void ft_lstiter(t_list *lst, void (*f)(t_list *elem)); 29 | t_list *ft_lstmap(t_list *lst, t_list *(*f)(t_list *elem)); 30 | void ft_lstrev(t_list **alst); 31 | void ft_lstqueueadd(t_list **alst, t_list *new); 32 | void ft_lstfreeto(t_list **alst, t_list *to); 33 | 34 | #endif -------------------------------------------------------------------------------- /libft/includes/ft_memory.h: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_memory.h :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: cfeijoo +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2014/02/17 19:39:37 by cfeijoo #+# #+# */ 9 | /* Updated: 2014/02/17 20:09:45 by cfeijoo ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #ifndef FT_MEMORY_H 14 | # define FT_MEMORY_H 15 | # include 16 | 17 | void *ft_memccpy(void *s1, const void *s2, int c, size_t n); 18 | void *ft_memchr(const void *s, int c, size_t n); 19 | int ft_memcmp(const void *s1, const void *s2, size_t n); 20 | void *ft_memcpy(void *s1, const void *s2, size_t n); 21 | void *ft_memmove(void *s1, const void *s2, size_t n); 22 | void *ft_memset(void *b, int c, size_t len); 23 | void *ft_memalloc(size_t size); 24 | void ft_memdel(void **ap); 25 | void *ft_memdup(const void *oldmem, size_t size); 26 | void ft_bzero(void *s, size_t n); 27 | 28 | #endif 29 | -------------------------------------------------------------------------------- /libft/includes/ft_print.h: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_print.h :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: cfeijoo +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2014/02/17 19:57:42 by cfeijoo #+# #+# */ 9 | /* Updated: 2014/03/17 22:17:07 by cfeijoo ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #ifndef FT_PRINT_H 14 | # define FT_PRINT_H 15 | 16 | void ft_putchar(char c); 17 | void ft_putendl(char const *s); 18 | void ft_putnbr(int n); 19 | void ft_putunbr(unsigned int n); 20 | void ft_putchar_fd(char c, int fd); 21 | void ft_putendl_fd(char const *s, int fd); 22 | void ft_putnbr_fd(int n, int fd); 23 | void ft_putunbr_fd(unsigned int n, int fd); 24 | void ft_putnbrb(long int n, unsigned int base); 25 | void ft_putlnbr(long int n); 26 | void ft_putstr(char const *s); 27 | void ft_putstr_fd(char const *s, int fd); 28 | void exit_with_error(char *message, int error); 29 | 30 | #endif 31 | -------------------------------------------------------------------------------- /libft/includes/libft.h: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* libft.h :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: cfeijoo +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2013/11/23 22:05:41 by cfeijoo #+# #+# */ 9 | /* Updated: 2014/03/27 20:12:43 by cfeijoo ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #ifndef LIBFT_H 14 | # define LIBFT_H 15 | 16 | # include "ft_math.h" 17 | # include "ft_lists.h" 18 | # include "ft_strings.h" 19 | # include "ft_input.h" 20 | # include "ft_memory.h" 21 | # include "ft_print.h" 22 | # include "ft_convert.h" 23 | # include "ft_colors.h" 24 | # include "ft_hashmap.h" 25 | 26 | #endif 27 | -------------------------------------------------------------------------------- /libft/objects/.gitignore: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kube/RT/5913f4753a3e8f1e6c2a829fa83fd69dfc86112f/libft/objects/.gitignore -------------------------------------------------------------------------------- /libft/sources/colors/blend_colors.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* blend_colors.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: cfeijoo +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2014/03/02 17:53:52 by cfeijoo #+# #+# */ 9 | /* Updated: 2014/03/02 21:38:14 by cfeijoo ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | int blend_colors(int color1, int color2, float coeff, int type) 16 | { 17 | t_color a; 18 | t_color b; 19 | 20 | a.color = color1; 21 | b.color = color2; 22 | if (coeff < 1) 23 | b.color = fade_color(b, coeff).color; 24 | if (type == COLOR_BLEND_ADD) 25 | return (color_blend_add(a, b).color); 26 | else if (type == COLOR_BLEND_SUB) 27 | return (color_blend_sub(a, b).color); 28 | else 29 | return (color_blend_over(a, b).color); 30 | } 31 | -------------------------------------------------------------------------------- /libft/sources/colors/color_blend_add.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* color_blend_add.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: cfeijoo +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2014/03/02 20:42:18 by cfeijoo #+# #+# */ 9 | /* Updated: 2014/03/02 21:39:19 by cfeijoo ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | t_color color_blend_add(t_color a, t_color b) 16 | { 17 | t_color c; 18 | int red; 19 | int green; 20 | int blue; 21 | 22 | red = (int)a.r * (int)a.a + (int)b.r * (int)b.a; 23 | green = (int)a.g * (int)a.a + (int)b.g * (int)b.a; 24 | blue = (int)a.b * (int)a.a + (int)b.b * (int)b.a; 25 | if ((int)a.a + (int)b.a < 255) 26 | c.a = (unsigned char)((int)a.a + (int)b.a); 27 | else 28 | c.a = 255; 29 | if (red < 255 * 255) 30 | c.r = (unsigned char)(red / 255); 31 | else 32 | c.r = 255; 33 | if (green < 255 * 255) 34 | c.g = (unsigned char)(green / 255); 35 | else 36 | c.g = 255; 37 | if (blue < 255 * 255) 38 | c.b = (unsigned char)(blue / 255); 39 | else 40 | c.b = 255; 41 | return (c); 42 | } 43 | -------------------------------------------------------------------------------- /libft/sources/colors/color_blend_over.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* color_blend_over.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: cfeijoo +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2014/03/02 20:42:47 by cfeijoo #+# #+# */ 9 | /* Updated: 2014/03/02 21:38:56 by cfeijoo ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | t_color color_blend_over(t_color a, t_color b) 16 | { 17 | t_color c; 18 | 19 | if (b.a == 0) 20 | return (a); 21 | else if (b.a == 255 || a.a == 0) 22 | return (b); 23 | else if (a.a < 255) 24 | { 25 | c.a = a.a + ((255 - a.a) * b.a) / 255; 26 | c.r = (a.r * a.a * (255 - b.a) + b.r * b.a) / c.a; 27 | c.g = (a.g * a.a * (255 - b.a) + b.g * b.a) / c.a; 28 | c.b = (a.b * a.a * (255 - b.a) + b.b * b.a) / c.a; 29 | } 30 | else 31 | { 32 | c.a = 255; 33 | c.r = (a.r * (255 - b.a) + b.r * b.a) / 255; 34 | c.g = (a.g * (255 - b.a) + b.g * b.a) / 255; 35 | c.b = (a.b * (255 - b.a) + b.b * b.a) / 255; 36 | } 37 | return (c); 38 | } 39 | -------------------------------------------------------------------------------- /libft/sources/colors/color_blend_sub.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* color_blend_sub.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: cfeijoo +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2014/03/02 20:41:39 by cfeijoo #+# #+# */ 9 | /* Updated: 2014/03/02 21:39:26 by cfeijoo ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | t_color color_blend_sub(t_color a, t_color b) 16 | { 17 | t_color c; 18 | int red; 19 | int green; 20 | int blue; 21 | 22 | red = (int)a.r * (int)a.a - (int)b.r * (int)b.a; 23 | green = (int)a.g * (int)a.a - (int)b.g * (int)b.a; 24 | blue = (int)a.b * (int)a.a - (int)b.b * (int)b.a; 25 | if ((int)a.a + (int)b.a > 0) 26 | c.a = ((a.a > b.a) ? a.a : b.a); 27 | else 28 | c.a = 0; 29 | if (red > 0) 30 | c.r = (unsigned char)(red / 255); 31 | else 32 | c.r = 0; 33 | if (green > 0) 34 | c.g = (unsigned char)(green / 255); 35 | else 36 | c.g = 0; 37 | if (blue > 0) 38 | c.b = (unsigned char)(blue / 255); 39 | else 40 | c.b = 0; 41 | return (c); 42 | } 43 | -------------------------------------------------------------------------------- /libft/sources/colors/fade_color.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* fade_color.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: cfeijoo +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2014/03/02 20:43:36 by cfeijoo #+# #+# */ 9 | /* Updated: 2014/03/02 21:38:27 by cfeijoo ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | t_color fade_color(t_color a, float opacity) 16 | { 17 | a.a = (unsigned char)((float)a.a * opacity); 18 | return (a); 19 | } 20 | -------------------------------------------------------------------------------- /libft/sources/convert/ft_abs.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_abs.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: cfeijoo +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2013/12/18 10:57:04 by cfeijoo #+# #+# */ 9 | /* Updated: 2014/02/17 18:54:50 by cfeijoo ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | int ft_abs(int nb) 16 | { 17 | if (nb < 0) 18 | return (-nb); 19 | return (nb); 20 | } 21 | -------------------------------------------------------------------------------- /libft/sources/convert/ft_atoi.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_atoi.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: cfeijoo +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2013/11/22 02:16:29 by cfeijoo #+# #+# */ 9 | /* Updated: 2014/02/17 21:32:26 by cfeijoo ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | static int ft_isspace(char c) 16 | { 17 | if (c == ' ' || 18 | c == '\n' || 19 | c == '\t' || 20 | c == '\v' || 21 | c == '\f' || 22 | c == '\r') 23 | { 24 | return (1); 25 | } 26 | return (0); 27 | } 28 | 29 | int ft_atoi(const char *str) 30 | { 31 | int i; 32 | int sign; 33 | int nb; 34 | 35 | i = 0; 36 | nb = 0; 37 | sign = 1; 38 | while (ft_isspace(str[i])) 39 | i++; 40 | if (str[i] == '-') 41 | { 42 | sign = -1; 43 | i++; 44 | } 45 | else if (str[i] == '+') 46 | i++; 47 | while (ft_isdigit(str[i])) 48 | { 49 | nb = nb * 10 + (str[i] - '0') * sign; 50 | i++; 51 | } 52 | return (nb); 53 | } 54 | -------------------------------------------------------------------------------- /libft/sources/convert/ft_itoa.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_itoa.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: cfeijoo +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2013/11/24 04:46:36 by cfeijoo #+# #+# */ 9 | /* Updated: 2014/02/17 21:33:15 by cfeijoo ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | #include 15 | 16 | static int ft_getpower(int n, unsigned int base) 17 | { 18 | unsigned int power; 19 | 20 | power = 0; 21 | n = ft_abs(n); 22 | while (n) 23 | { 24 | n = n / base; 25 | power++; 26 | } 27 | return (power); 28 | } 29 | 30 | char *ft_itoa(int n) 31 | { 32 | char *str; 33 | unsigned int length; 34 | 35 | if (n == 0) 36 | return ("0"); 37 | length = ft_getpower(n, 11) + (n < 0); 38 | str = (char*)malloc(length * sizeof(*str)); 39 | if (n < 0) 40 | str[0] = '-'; 41 | while (n) 42 | { 43 | str[length] = '0' + ft_abs(n % 10); 44 | n = ft_abs(n / 10); 45 | length --; 46 | } 47 | return (str); 48 | } 49 | -------------------------------------------------------------------------------- /libft/sources/convert/ft_tolower.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_tolower.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: cfeijoo +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2013/11/23 00:51:39 by cfeijoo #+# #+# */ 9 | /* Updated: 2014/01/05 20:36:46 by cfeijoo ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | int ft_tolower(int c) 16 | { 17 | if (c >= 'A' && c <= 'Z') 18 | { 19 | return (c + ('a' - 'A')); 20 | } 21 | return (c); 22 | } 23 | -------------------------------------------------------------------------------- /libft/sources/convert/ft_toupper.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_toupper.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: cfeijoo +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2013/11/23 01:05:52 by cfeijoo #+# #+# */ 9 | /* Updated: 2014/02/17 19:09:58 by cfeijoo ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | 14 | 15 | int ft_toupper(int c) 16 | { 17 | if (c >= 'a' && c <= 'z') 18 | { 19 | return (c - ('a' - 'A')); 20 | } 21 | return (c); 22 | } 23 | -------------------------------------------------------------------------------- /libft/sources/convert/hash.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* hash.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: cfeijoo +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2014/02/19 04:08:13 by cfeijoo #+# #+# */ 9 | /* Updated: 2014/02/19 04:13:23 by cfeijoo ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | unsigned int basic_hash(char *str) 14 | { 15 | int c; 16 | unsigned int hash; 17 | 18 | hash = 5381; 19 | while ((c = *str++)) 20 | hash = ((hash << 5) + hash) + c; 21 | return (hash); 22 | } 23 | -------------------------------------------------------------------------------- /libft/sources/input/ft_getchar.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_getchar.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: cfeijoo +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2013/12/17 16:24:33 by cfeijoo #+# #+# */ 9 | /* Updated: 2014/02/17 20:00:54 by cfeijoo ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | char ft_getchar(void) 16 | { 17 | char a; 18 | 19 | read(0, &a, 1); 20 | return (a); 21 | } 22 | -------------------------------------------------------------------------------- /libft/sources/lists/ft_lstadd.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_lstadd.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: cfeijoo +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2013/12/01 16:33:44 by cfeijoo #+# #+# */ 9 | /* Updated: 2014/02/17 21:35:21 by cfeijoo ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | void ft_lstadd(t_list **alst, t_list *new) 16 | { 17 | if (new) 18 | { 19 | new->next = *alst; 20 | *alst = new; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /libft/sources/lists/ft_lstdel.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_lstdel.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: cfeijoo +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2013/12/01 16:27:46 by cfeijoo #+# #+# */ 9 | /* Updated: 2014/02/17 20:07:42 by cfeijoo ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | #include 15 | 16 | void ft_lstdel(t_list **alst, void (*del)(void *, size_t)) 17 | { 18 | t_list *current; 19 | 20 | if (alst) 21 | { 22 | current = *alst; 23 | while (current) 24 | { 25 | if (del) 26 | (*del)(current->content, current->content_size); 27 | free(current); 28 | current = current->next; 29 | } 30 | } 31 | *alst = 0; 32 | } 33 | -------------------------------------------------------------------------------- /libft/sources/lists/ft_lstdelone.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_lstdelone.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: cfeijoo +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2013/12/01 16:32:44 by cfeijoo #+# #+# */ 9 | /* Updated: 2014/02/17 20:08:13 by cfeijoo ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | #include 15 | 16 | void ft_lstdelone(t_list **alst, void (*del)(void *, size_t)) 17 | { 18 | if (alst) 19 | { 20 | if (del) 21 | (*del)((*alst)->content, (*alst)->content_size); 22 | free(*alst); 23 | } 24 | *alst = 0; 25 | } 26 | -------------------------------------------------------------------------------- /libft/sources/lists/ft_lstfreeto.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_lstfreeto.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: cfeijoo +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2013/12/08 23:28:23 by cfeijoo #+# #+# */ 9 | /* Updated: 2014/02/17 21:35:55 by cfeijoo ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | #include 15 | 16 | void ft_lstfreeto(t_list **alst, t_list *to) 17 | { 18 | t_list *last; 19 | t_list *current; 20 | 21 | current = *alst; 22 | if (alst && to) 23 | { 24 | while (current && current != to) 25 | { 26 | last = current; 27 | current = current->next; 28 | free(last); 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /libft/sources/lists/ft_lstiter.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_lstiter.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: cfeijoo +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2013/12/01 16:35:03 by cfeijoo #+# #+# */ 9 | /* Updated: 2014/02/17 21:36:02 by cfeijoo ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | void ft_lstiter(t_list *lst, void (*f)(t_list *elem)) 16 | { 17 | if (lst && *f) 18 | { 19 | (*f)(lst); 20 | if (lst->next) 21 | ft_lstiter(lst->next, f); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /libft/sources/lists/ft_lstmap.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_lstmap.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: cfeijoo +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2013/12/01 16:37:01 by cfeijoo #+# #+# */ 9 | /* Updated: 2014/02/19 16:16:51 by cfeijoo ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | t_list *ft_lstmap(t_list *lst, t_list *(*f)(t_list *elem)) 16 | { 17 | t_list *newlst; 18 | 19 | if (lst && *f) 20 | { 21 | newlst = (*f)(lst); 22 | if (newlst && lst->next) 23 | newlst->next = ft_lstmap(lst->next, f); 24 | return (newlst); 25 | } 26 | return (0); 27 | } 28 | -------------------------------------------------------------------------------- /libft/sources/lists/ft_lstnew.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_lstnew.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: cfeijoo +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2013/12/01 15:18:08 by cfeijoo #+# #+# */ 9 | /* Updated: 2014/02/17 20:06:51 by cfeijoo ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | #include 15 | #include 16 | 17 | t_list *ft_lstnew(void const *content, size_t content_size) 18 | { 19 | t_list *newlst; 20 | 21 | newlst = (t_list*)malloc(sizeof(t_list)); 22 | if (content_size) 23 | newlst->content = ft_memdup(content, content_size); 24 | newlst->content_size = content_size; 25 | newlst->next = 0; 26 | return (newlst); 27 | } 28 | -------------------------------------------------------------------------------- /libft/sources/lists/ft_lstqueueadd.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_lstqueueadd.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: cfeijoo +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2013/12/04 22:55:28 by cfeijoo #+# #+# */ 9 | /* Updated: 2014/02/17 21:36:10 by cfeijoo ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | void ft_lstqueueadd(t_list **alst, t_list *new) 16 | { 17 | t_list *current; 18 | 19 | if (new && alst) 20 | { 21 | current = *alst; 22 | if (current) 23 | { 24 | while (current->next) 25 | current = current->next; 26 | current->next = new; 27 | } 28 | else 29 | ft_lstadd(alst, new); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /libft/sources/lists/ft_lstrev.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_lstrev.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: cfeijoo +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2013/12/11 14:27:23 by cfeijoo #+# #+# */ 9 | /* Updated: 2014/02/17 21:36:21 by cfeijoo ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | void ft_lstrev(t_list **alst) 16 | { 17 | t_list *new; 18 | t_list *old_next; 19 | t_list *old_current; 20 | 21 | new = 0; 22 | old_current = *alst; 23 | while (old_current) 24 | { 25 | old_next = old_current->next; 26 | old_current->next = new; 27 | new = old_current; 28 | old_current = old_next; 29 | } 30 | *alst = new; 31 | } 32 | -------------------------------------------------------------------------------- /libft/sources/math/ft_sqrt.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_sqrt.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: cfeijoo +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2014/01/05 19:02:45 by cfeijoo #+# #+# */ 9 | /* Updated: 2014/02/18 04:38:56 by cfeijoo ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | /* 14 | ** Quake 3's Fast Inverse Square Root 15 | */ 16 | 17 | float ft_invsqrt (float x) 18 | { 19 | int i; 20 | float xhalf; 21 | 22 | xhalf = 0.5f * x; 23 | i = *(int*)&x; 24 | i = 0x5f3759df - (i >> 1); 25 | x = *(float*)&i; 26 | x = x * (1.5f - xhalf * x * x); 27 | x = x * (1.5f - (xhalf * x * x)); 28 | return (x); 29 | } 30 | 31 | float ft_sqrt(float x) 32 | { 33 | return (1.0 / ft_invsqrt(x)); 34 | } 35 | -------------------------------------------------------------------------------- /libft/sources/math/infin_number_gt.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* infin_number_gt.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: cfeijoo +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2014/02/23 00:18:16 by cfeijoo #+# #+# */ 9 | /* Updated: 2014/02/23 00:27:02 by cfeijoo ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | int infin_number_gt(t_infin_number *a, t_infin_number *b) 16 | { 17 | int i; 18 | 19 | if (a->length > b->length) 20 | return (1); 21 | else if (b->length > a->length) 22 | return (0); 23 | i = a->length; 24 | while (i >= 0) 25 | { 26 | if (b->value[i] > a->value[i]) 27 | return (0); 28 | else if (b->value[i] < a->value[i]) 29 | return (1); 30 | i--; 31 | } 32 | return (0); 33 | } 34 | -------------------------------------------------------------------------------- /libft/sources/math/load_infin_number.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* load_infin_number.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: cfeijoo +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2014/02/23 00:11:17 by cfeijoo #+# #+# */ 9 | /* Updated: 2014/02/23 00:32:42 by cfeijoo ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | #include 15 | #include 16 | 17 | static void reverse_number(t_infin_number *number) 18 | { 19 | unsigned int i; 20 | unsigned int length; 21 | char *reversed_value; 22 | 23 | length = number->length; 24 | reversed_value = (char*)malloc((int)length * sizeof(char)); 25 | i = 0; 26 | while (i < length) 27 | { 28 | reversed_value[i] = number->value[length - i - 1] - '0'; 29 | i++; 30 | } 31 | number->value = reversed_value; 32 | } 33 | 34 | t_infin_number *load_infin_number(char *value) 35 | { 36 | t_infin_number *number; 37 | unsigned int length; 38 | 39 | number = (t_infin_number*)malloc(sizeof(t_infin_number)); 40 | if (*value == '-') 41 | { 42 | number->sign = -1; 43 | value++; 44 | } 45 | else 46 | number->sign = 1; 47 | number->value = value; 48 | while (*value == '0') 49 | value++; 50 | length = 0; 51 | while (ft_isdigit(value[length])) 52 | length++; 53 | number->length = length; 54 | reverse_number(number); 55 | return (number); 56 | } 57 | -------------------------------------------------------------------------------- /libft/sources/math/print_infin_number.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* print_infin_number.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: cfeijoo +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2014/02/23 00:20:46 by cfeijoo #+# #+# */ 9 | /* Updated: 2014/02/23 00:32:26 by cfeijoo ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | #include 15 | 16 | void print_infin_number(t_infin_number *number) 17 | { 18 | int i; 19 | char digit; 20 | 21 | i = number->length - 1; 22 | if (number->length > 0) 23 | { 24 | if (number->sign == -1) 25 | write(1, "-", 1); 26 | while (i >= 0) 27 | { 28 | digit = '0' + number->value[i]; 29 | write(1, &digit, 1); 30 | i--; 31 | } 32 | } 33 | else 34 | write(1, "0", 1); 35 | } 36 | -------------------------------------------------------------------------------- /libft/sources/math/vector_operations.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* vector_operations.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: cfeijoo +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2014/03/10 02:14:08 by kube #+# #+# */ 9 | /* Updated: 2014/03/26 19:42:51 by cfeijoo ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | t_vector *vector_add(t_vector *a, t_vector *b, float coeff) 16 | { 17 | a->x += b->x * coeff; 18 | a->y += b->y * coeff; 19 | a->z += b->z * coeff; 20 | return (a); 21 | } 22 | 23 | t_vector vect_product(t_vector *a, t_vector *b) 24 | { 25 | t_vector c; 26 | 27 | c.x = a->y * b->z - a->z * b->y; 28 | c.y = a->z * b->x - a->x * b->z; 29 | c.z = a->x * b->y - a->y * b->x; 30 | return (c); 31 | } 32 | -------------------------------------------------------------------------------- /libft/sources/math/vector_properties.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* vector_properties.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: cfeijoo +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2014/02/19 02:18:59 by cfeijoo #+# #+# */ 9 | /* Updated: 2014/03/26 19:45:23 by cfeijoo ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | #ifdef USE_MATH 16 | # include 17 | # define SQRT sqrt 18 | #else 19 | # define SQRT ft_sqrt 20 | #endif 21 | 22 | float vect_dot(t_vector *a, t_vector *b) 23 | { 24 | return (a->x * b->x + a->y * b->y + a->z * b->z); 25 | } 26 | 27 | float vect_norm(t_vector *a) 28 | { 29 | return (SQRT(a->x * a->x + a->y * a->y + a->z * a->z)); 30 | } 31 | 32 | t_vector vector_from_points(t_vector *a, t_vector *b) 33 | { 34 | t_vector c; 35 | 36 | c.x = a->x - b->x; 37 | c.y = a->y - b->y; 38 | c.z = a->z - b->z; 39 | return (c); 40 | } 41 | 42 | float distance_between_points(t_point *a, t_point *b) 43 | { 44 | t_vector c; 45 | 46 | c = vector_from_points((t_vector*)a, (t_vector*)b); 47 | return (vect_norm(&c)); 48 | } 49 | -------------------------------------------------------------------------------- /libft/sources/math/vector_transformations.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* vector_transformations.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: kube +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2014/02/19 01:51:22 by cfeijoo #+# #+# */ 9 | /* Updated: 2014/03/10 02:13:39 by kube ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | #ifdef USE_MATH 16 | # include 17 | # define COS cos 18 | # define SIN sin 19 | #else 20 | # define COS ft_cos 21 | # define SIN ft_sin 22 | #endif 23 | 24 | void vect_rot_z(t_vector *v, float angle) 25 | { 26 | t_point a; 27 | 28 | a.x = v->x; 29 | a.y = v->y; 30 | v->x = a.x * COS(angle) - a.y * SIN(angle); 31 | v->y = a.x * SIN(angle) + a.y * COS(angle); 32 | } 33 | 34 | void vect_rot_x(t_vector *v, float angle) 35 | { 36 | t_point a; 37 | 38 | a.y = v->y; 39 | a.z = v->z; 40 | v->y = a.y * SIN(angle) + a.z * COS(angle); 41 | v->z = a.y * COS(angle) - a.z * SIN(angle); 42 | } 43 | 44 | void vect_rot_y(t_vector *v, float angle) 45 | { 46 | t_point a; 47 | 48 | a.x = v->x; 49 | a.z = v->z; 50 | v->x = a.z * SIN(angle) + a.x * COS(angle); 51 | v->z = a.z * COS(angle) - a.x * SIN(angle); 52 | } 53 | 54 | void vect_scale(t_vector *v, float coeff) 55 | { 56 | v->x *= coeff; 57 | v->y *= coeff; 58 | v->z *= coeff; 59 | } 60 | 61 | void normalize_vector(t_vector *a) 62 | { 63 | float norm; 64 | 65 | norm = vect_norm(a); 66 | a->x /= norm; 67 | a->y /= norm; 68 | a->z /= norm; 69 | } 70 | -------------------------------------------------------------------------------- /libft/sources/memory/ft_bzero.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_bzero.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: cfeijoo +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2013/11/20 14:31:22 by cfeijoo #+# #+# */ 9 | /* Updated: 2014/02/18 19:37:29 by cfeijoo ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | void ft_bzero(void *s, size_t n) 16 | { 17 | char *cache; 18 | size_t limit; 19 | 20 | cache = (char*)s; 21 | limit = (size_t)s + n; 22 | while ((size_t)cache < limit) 23 | { 24 | if (cache) 25 | *cache = 0; 26 | cache++; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /libft/sources/memory/ft_memalloc.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_memalloc.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: cfeijoo +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2013/11/24 03:56:30 by cfeijoo #+# #+# */ 9 | /* Updated: 2014/02/17 20:09:44 by cfeijoo ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | #include 15 | 16 | void *ft_memalloc(size_t size) 17 | { 18 | void *new; 19 | 20 | new = malloc(size * sizeof(char)); 21 | if (new) 22 | ft_bzero(new, size); 23 | return (new); 24 | } 25 | -------------------------------------------------------------------------------- /libft/sources/memory/ft_memccpy.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_memccpy.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: cfeijoo +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2013/11/21 15:49:52 by cfeijoo #+# #+# */ 9 | /* Updated: 2014/02/18 19:19:37 by cfeijoo ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | void *ft_memccpy(void *s1, const void *s2, int c, size_t n) 16 | { 17 | size_t i; 18 | char *c1; 19 | const char *c2; 20 | 21 | i = 0; 22 | c1 = s1; 23 | c2 = s2; 24 | while (i < n) 25 | { 26 | c1[i] = c2[i]; 27 | if (c2[i] == c) 28 | { 29 | return (void *)&(c1[i + 1]); 30 | } 31 | i++; 32 | } 33 | return (0); 34 | } 35 | -------------------------------------------------------------------------------- /libft/sources/memory/ft_memchr.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_memchr.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: cfeijoo +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2013/11/21 20:41:46 by cfeijoo #+# #+# */ 9 | /* Updated: 2014/02/17 19:23:55 by cfeijoo ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | void *ft_memchr(const void *s, int c, size_t n) 16 | { 17 | size_t i; 18 | const char *t; 19 | 20 | i = 0; 21 | t = s; 22 | while (i < n) 23 | { 24 | if (t[i] == (char)c) 25 | return (void *)(t + i); 26 | i++; 27 | } 28 | return (0); 29 | } 30 | -------------------------------------------------------------------------------- /libft/sources/memory/ft_memcmp.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_memcmp.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: cfeijoo +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2013/11/21 20:48:59 by cfeijoo #+# #+# */ 9 | /* Updated: 2014/02/17 19:20:29 by cfeijoo ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | int ft_memcmp(const void *s1, const void *s2, size_t n) 16 | { 17 | size_t i; 18 | const char *c1; 19 | const char *c2; 20 | 21 | i = 0; 22 | c1 = s1; 23 | c2 = s2; 24 | while (i < n) 25 | { 26 | if (c1[i] != c2[i]) 27 | return (c1[i] - c2[i]); 28 | i++; 29 | } 30 | return (0); 31 | } 32 | -------------------------------------------------------------------------------- /libft/sources/memory/ft_memcpy.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_memcpy.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: cfeijoo +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2013/11/20 16:28:46 by cfeijoo #+# #+# */ 9 | /* Updated: 2014/02/17 20:00:10 by cfeijoo ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | void *ft_memcpy(void *s1, const void *s2, size_t n) 16 | { 17 | size_t i; 18 | char *c1; 19 | const char *c2; 20 | 21 | i = 0; 22 | c1 = s1; 23 | c2 = s2; 24 | while (i < n) 25 | { 26 | c1[i] = c2[i]; 27 | i++; 28 | } 29 | return (s1); 30 | } 31 | -------------------------------------------------------------------------------- /libft/sources/memory/ft_memdel.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_memdel.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: cfeijoo +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2013/11/24 03:58:15 by cfeijoo #+# #+# */ 9 | /* Updated: 2014/02/17 18:52:45 by cfeijoo ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | void ft_memdel(void **ap) 16 | { 17 | if (ap && *ap) 18 | { 19 | free(*ap); 20 | *ap = NULL; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /libft/sources/memory/ft_memdup.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_memdup.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: cfeijoo +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2013/12/01 15:37:23 by cfeijoo #+# #+# */ 9 | /* Updated: 2014/02/17 21:21:00 by cfeijoo ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | #include 15 | 16 | void *ft_memdup(const void *oldmem, size_t size) 17 | { 18 | void *newmem; 19 | 20 | if (oldmem) 21 | { 22 | newmem = malloc(size); 23 | if (newmem) 24 | ft_memmove(newmem, oldmem, size); 25 | return (newmem); 26 | } 27 | return (0); 28 | } 29 | -------------------------------------------------------------------------------- /libft/sources/memory/ft_memmove.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_memmove.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: cfeijoo +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2013/11/21 18:13:36 by cfeijoo #+# #+# */ 9 | /* Updated: 2014/02/17 21:38:36 by cfeijoo ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | void *ft_memmove(void *s1, const void *s2, size_t n) 16 | { 17 | size_t i; 18 | int sens; 19 | char *c1; 20 | const char *c2; 21 | 22 | if (s1 && s2) 23 | { 24 | i = 0; 25 | sens = 1; 26 | c1 = s1; 27 | c2 = s2; 28 | if (s1 >= s2 && n > 0) 29 | { 30 | i = n - 1; 31 | sens = -1; 32 | } 33 | while (i != n * sens) 34 | { 35 | c1[i] = c2[i]; 36 | i += sens; 37 | } 38 | } 39 | return (s1); 40 | } 41 | -------------------------------------------------------------------------------- /libft/sources/memory/ft_memset.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_memset.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: cfeijoo +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2013/11/19 18:44:18 by cfeijoo #+# #+# */ 9 | /* Updated: 2014/02/17 19:17:51 by cfeijoo ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | void *ft_memset(void *b, int c, size_t len) 16 | { 17 | unsigned int i; 18 | unsigned char *cache; 19 | 20 | i = 0; 21 | cache = (unsigned char*)b; 22 | while (i < (unsigned int)len) 23 | { 24 | cache[i] = c; 25 | i++; 26 | } 27 | return (b); 28 | } 29 | -------------------------------------------------------------------------------- /libft/sources/print/exit_with_error.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* exit_with_error.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: cfeijoo +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2014/02/22 16:04:57 by cfeijoo #+# #+# */ 9 | /* Updated: 2014/02/22 23:19:40 by cfeijoo ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | #include 15 | 16 | void exit_with_error(char *message, int error) 17 | { 18 | ft_putendl_fd(message, 2); 19 | exit (error); 20 | } 21 | -------------------------------------------------------------------------------- /libft/sources/print/ft_putchar.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_putchar.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: cfeijoo +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2013/11/24 04:47:58 by cfeijoo #+# #+# */ 9 | /* Updated: 2014/02/17 19:28:06 by cfeijoo ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | void ft_putchar(char c) 16 | { 17 | write(1, &c, 1); 18 | } 19 | -------------------------------------------------------------------------------- /libft/sources/print/ft_putchar_fd.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_putchar_fd.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: cfeijoo +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2013/11/24 04:51:35 by cfeijoo #+# #+# */ 9 | /* Updated: 2014/02/17 19:28:22 by cfeijoo ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | void ft_putchar_fd(char c, int fd) 16 | { 17 | write(fd, &c, 1); 18 | } 19 | -------------------------------------------------------------------------------- /libft/sources/print/ft_putendl.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_putendl.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: cfeijoo +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2013/11/24 04:50:35 by cfeijoo #+# #+# */ 9 | /* Updated: 2014/02/17 21:40:20 by cfeijoo ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | void ft_putendl(char const *s) 16 | { 17 | ft_putstr(s); 18 | ft_putchar('\n'); 19 | } 20 | -------------------------------------------------------------------------------- /libft/sources/print/ft_putendl_fd.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_putendl_fd.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: cfeijoo +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2013/11/24 05:02:16 by cfeijoo #+# #+# */ 9 | /* Updated: 2014/02/17 21:39:16 by cfeijoo ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | void ft_putendl_fd(char const *s, int fd) 16 | { 17 | ft_putstr_fd(s, fd); 18 | ft_putchar_fd('\n', fd); 19 | } 20 | -------------------------------------------------------------------------------- /libft/sources/print/ft_putlnbr.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_putlnbr.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: cfeijoo +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2013/12/01 16:22:00 by cfeijoo #+# #+# */ 9 | /* Updated: 2014/02/17 19:27:52 by cfeijoo ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | static long int ft_labs(long int n) 16 | { 17 | if (n < 0) 18 | return (-n); 19 | return (n); 20 | } 21 | 22 | void ft_putlnbr(long int n) 23 | { 24 | char a; 25 | 26 | if (n < 0) 27 | write(1, "-", 1); 28 | if (n / 10) 29 | ft_putlnbr(ft_labs(n / 10)); 30 | a = '0' + ft_labs(n % 10); 31 | write(1, &a, 1); 32 | } 33 | -------------------------------------------------------------------------------- /libft/sources/print/ft_putnbr.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_putnbr.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: cfeijoo +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2013/11/21 02:46:45 by cfeijoo #+# #+# */ 9 | /* Updated: 2014/02/17 21:39:59 by cfeijoo ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | #include 15 | #include 16 | 17 | void ft_putnbr(int n) 18 | { 19 | char a; 20 | 21 | if (n < 0) 22 | write(1, "-", 1); 23 | if (n / 10) 24 | ft_putnbr(ft_abs(n / 10)); 25 | a = '0' + ft_abs(n % 10); 26 | write(1, &a, 1); 27 | } 28 | -------------------------------------------------------------------------------- /libft/sources/print/ft_putnbr_fd.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_putnbr_fd.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: cfeijoo +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2013/11/24 05:03:58 by cfeijoo #+# #+# */ 9 | /* Updated: 2014/02/19 19:47:47 by cfeijoo ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | #include 15 | #include 16 | 17 | void ft_putnbr_fd(int n, int fd) 18 | { 19 | char a; 20 | 21 | if (n < 0) 22 | write(fd, "-", 1); 23 | if (n / 10) 24 | ft_putnbr_fd(ft_abs(n / 10), fd); 25 | a = '0' + ft_abs(n % 10); 26 | write(fd, &a, 1); 27 | } 28 | -------------------------------------------------------------------------------- /libft/sources/print/ft_putnbrb.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_putnbrb.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: cfeijoo +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2013/11/26 17:03:35 by cfeijoo #+# #+# */ 9 | /* Updated: 2014/02/17 21:42:46 by cfeijoo ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | #include 15 | #include 16 | 17 | void ft_putnbrb(long int n, unsigned int base) 18 | { 19 | int a; 20 | char b[36] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"; 21 | 22 | if (base <= 36 && base > 1) 23 | { 24 | if (n < 0) 25 | write(1, "-", 1); 26 | if (n / base) 27 | ft_putnbrb(ft_abs(n / base), base); 28 | a = ft_abs(n % base); 29 | write(1, b + a, 1); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /libft/sources/print/ft_putstr.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_putstr.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: cfeijoo +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2013/11/24 04:49:29 by cfeijoo #+# #+# */ 9 | /* Updated: 2014/02/17 19:24:20 by cfeijoo ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | void ft_putstr(char const *s) 16 | { 17 | if (s) 18 | { 19 | while (*s) 20 | { 21 | write(1, s, 1); 22 | s++; 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /libft/sources/print/ft_putstr_fd.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_putstr_fd.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: cfeijoo +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2013/11/24 04:56:53 by cfeijoo #+# #+# */ 9 | /* Updated: 2014/02/17 21:43:01 by cfeijoo ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | #include 15 | 16 | void ft_putstr_fd(char const *s, int fd) 17 | { 18 | if (s) 19 | write(fd, s, ft_strlen(s)); 20 | } 21 | -------------------------------------------------------------------------------- /libft/sources/print/ft_putunbr.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_putunbr.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: cfeijoo +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2013/11/24 05:03:58 by cfeijoo #+# #+# */ 9 | /* Updated: 2014/03/17 22:18:22 by cfeijoo ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | #include 15 | #include 16 | 17 | void ft_putunbr(unsigned int n) 18 | { 19 | char a; 20 | 21 | if (n / 10) 22 | ft_putunbr(n / 10); 23 | a = '0' + n % 10; 24 | write(1, &a, 1); 25 | } 26 | -------------------------------------------------------------------------------- /libft/sources/print/ft_putunbr_fd.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_putunbr_fd.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: cfeijoo +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2013/11/24 05:03:58 by cfeijoo #+# #+# */ 9 | /* Updated: 2014/03/17 22:17:10 by cfeijoo ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | #include 15 | #include 16 | 17 | void ft_putunbr_fd(unsigned int n, int fd) 18 | { 19 | char a; 20 | 21 | if (n / 10) 22 | ft_putunbr_fd(n / 10, fd); 23 | a = '0' + n % 10; 24 | write(fd, &a, 1); 25 | } 26 | -------------------------------------------------------------------------------- /libft/sources/strings/ft_isalnum.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_isalnum.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: cfeijoo +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2013/11/23 00:04:52 by cfeijoo #+# #+# */ 9 | /* Updated: 2014/02/22 23:18:01 by cfeijoo ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | int ft_isalnum(int c) 16 | { 17 | if (ft_isalpha(c) || ft_isdigit(c)) 18 | return (1); 19 | return (0); 20 | } 21 | -------------------------------------------------------------------------------- /libft/sources/strings/ft_isalpha.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_isalpha.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: cfeijoo +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2013/11/22 23:39:54 by cfeijoo #+# #+# */ 9 | /* Updated: 2014/02/17 21:56:10 by cfeijoo ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | int ft_isalpha(int c) 14 | { 15 | if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')) 16 | return (1); 17 | return (0); 18 | } 19 | -------------------------------------------------------------------------------- /libft/sources/strings/ft_isascii.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_isascii.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: cfeijoo +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2013/11/23 00:38:14 by cfeijoo #+# #+# */ 9 | /* Updated: 2014/02/17 21:56:16 by cfeijoo ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | int ft_isascii(int c) 14 | { 15 | if (c >= 0 && c <= 127) 16 | return (1); 17 | return (0); 18 | } 19 | -------------------------------------------------------------------------------- /libft/sources/strings/ft_isdigit.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_isdigit.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: cfeijoo +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2013/11/22 23:56:07 by cfeijoo #+# #+# */ 9 | /* Updated: 2014/02/17 19:11:35 by cfeijoo ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | int ft_isdigit(int c) 14 | { 15 | if (c >= '0' && c <= '9') 16 | return (1); 17 | return (0); 18 | } 19 | -------------------------------------------------------------------------------- /libft/sources/strings/ft_isprint.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_isprint.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: cfeijoo +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2013/11/23 00:07:33 by cfeijoo #+# #+# */ 9 | /* Updated: 2014/02/17 22:43:00 by cfeijoo ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | int ft_isprint(int c) 14 | { 15 | if (c >= ' ' && c <= '~') 16 | return (1); 17 | return (0); 18 | } 19 | -------------------------------------------------------------------------------- /libft/sources/strings/ft_strbeginwith.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strbeginwith.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: cfeijoo +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2014/02/22 15:29:31 by cfeijoo #+# #+# */ 9 | /* Updated: 2014/02/22 15:32:16 by cfeijoo ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | /* 14 | ** Checks that string A begins with string B 15 | */ 16 | 17 | int ft_strbeginwith(char *a, char *b) 18 | { 19 | while (*b && *a == *b) 20 | { 21 | a++; 22 | b++; 23 | } 24 | if (!*a) 25 | return (1); 26 | return (0); 27 | } 28 | -------------------------------------------------------------------------------- /libft/sources/strings/ft_strcat.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strcat.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: cfeijoo +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2013/11/23 08:07:49 by cfeijoo #+# #+# */ 9 | /* Updated: 2014/02/17 21:24:10 by cfeijoo ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | char *ft_strcat(char *s1, const char *s2) 16 | { 17 | size_t i; 18 | size_t len1; 19 | 20 | len1 = ft_strlen(s1); 21 | i = 0; 22 | while (s2[i]) 23 | { 24 | s1[len1 + i] = s2[i]; 25 | i++; 26 | } 27 | s1[len1 + i] = 0; 28 | return (s1); 29 | } 30 | -------------------------------------------------------------------------------- /libft/sources/strings/ft_strchr.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strchr.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: cfeijoo +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2013/11/23 08:16:45 by cfeijoo #+# #+# */ 9 | /* Updated: 2014/02/17 21:56:39 by cfeijoo ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | char *ft_strchr(const char *s, int c) 16 | { 17 | size_t i; 18 | 19 | i = 0; 20 | while (s[i] || s[i] == (char)c) 21 | { 22 | if (s[i] == (char)c) 23 | return ((char*)(s + i)); 24 | i++; 25 | } 26 | return (0); 27 | } 28 | -------------------------------------------------------------------------------- /libft/sources/strings/ft_strclr.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strclr.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: cfeijoo +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2013/11/24 04:18:02 by cfeijoo #+# #+# */ 9 | /* Updated: 2014/02/17 21:43:26 by cfeijoo ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | #include 15 | 16 | void ft_strclr(char *s) 17 | { 18 | if (s) 19 | ft_bzero(s, ft_strlen(s)); 20 | } 21 | -------------------------------------------------------------------------------- /libft/sources/strings/ft_strcmp.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strcmp.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: cfeijoo +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2013/11/23 08:26:32 by cfeijoo #+# #+# */ 9 | /* Updated: 2014/02/17 19:35:43 by cfeijoo ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | int ft_strcmp(const char *s1, const char *s2) 14 | { 15 | int i; 16 | 17 | i = 0; 18 | while (s1[i] && s2[i] && s1[i] == s2[i]) 19 | i++; 20 | if (s1[i] > s2[i]) 21 | return (1); 22 | else if (s1[i] < s2[i]) 23 | return (-1); 24 | else 25 | return (0); 26 | } 27 | -------------------------------------------------------------------------------- /libft/sources/strings/ft_strcpy.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strcpy.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: cfeijoo +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2013/11/22 02:02:58 by cfeijoo #+# #+# */ 9 | /* Updated: 2014/02/17 21:22:49 by cfeijoo ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | char *ft_strcpy(char *s1, const char *s2) 16 | { 17 | unsigned int i; 18 | size_t len2; 19 | 20 | i = 0; 21 | len2 = ft_strlen((char*)s2); 22 | while (s2[i] && i < len2) 23 | { 24 | s1[i] = s2[i]; 25 | i++; 26 | } 27 | s1[i] = 0; 28 | return (s1); 29 | } 30 | -------------------------------------------------------------------------------- /libft/sources/strings/ft_strdel.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strdel.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: cfeijoo +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2013/11/24 04:11:50 by cfeijoo #+# #+# */ 9 | /* Updated: 2014/02/17 21:43:39 by cfeijoo ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | void ft_strdel(char **as) 16 | { 17 | ft_memdel((void**)as); 18 | } 19 | -------------------------------------------------------------------------------- /libft/sources/strings/ft_strdup.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strdup.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: cfeijoo +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2013/11/22 01:39:06 by cfeijoo #+# #+# */ 9 | /* Updated: 2014/03/22 23:55:45 by cfeijoo ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | #include 15 | #include 16 | 17 | char *ft_strdup(const char *s1) 18 | { 19 | int i; 20 | char *s2; 21 | 22 | i = 0; 23 | if (!s1) 24 | return (0); 25 | s2 = (char*)malloc((ft_strlen((char*)s1) + 1) * sizeof(*s1)); 26 | if (s2) 27 | { 28 | while (s1[i]) 29 | { 30 | s2[i] = s1[i]; 31 | i++; 32 | } 33 | s2[i] = 0; 34 | } 35 | else 36 | { 37 | errno = ENOMEM; 38 | return (0); 39 | } 40 | return (s2); 41 | } 42 | -------------------------------------------------------------------------------- /libft/sources/strings/ft_strequ.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strequ.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: cfeijoo +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2013/11/24 04:32:19 by cfeijoo #+# #+# */ 9 | /* Updated: 2014/02/17 21:56:56 by cfeijoo ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | int ft_strequ(char const *s1, char const *s2) 14 | { 15 | if (s1 && s2) 16 | { 17 | while (*s1 || *s2) 18 | { 19 | if (*s1 != *s2) 20 | return (0); 21 | s1++; 22 | s2++; 23 | } 24 | return (1); 25 | } 26 | return (0); 27 | } 28 | -------------------------------------------------------------------------------- /libft/sources/strings/ft_strinarray.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strinarray.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: cfeijoo +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2013/12/09 16:49:02 by cfeijoo #+# #+# */ 9 | /* Updated: 2014/02/17 21:30:43 by cfeijoo ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | ssize_t ft_strinarray(char **array, char *str) 16 | { 17 | ssize_t i; 18 | 19 | i = 0; 20 | while (array[i]) 21 | { 22 | if (ft_strequ(array[i], str)) 23 | return (i); 24 | i++; 25 | } 26 | return (0); 27 | } 28 | -------------------------------------------------------------------------------- /libft/sources/strings/ft_strisinarray.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strisinarray.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: cfeijoo +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2013/12/09 16:49:02 by cfeijoo #+# #+# */ 9 | /* Updated: 2014/02/17 21:57:04 by cfeijoo ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | ssize_t ft_strinarray(char **array, char *str) 14 | { 15 | ssize_t i; 16 | 17 | i = 0; 18 | while (array[i] && array[i][0]) 19 | { 20 | if (strequ(array[i], str)) 21 | return (i); 22 | i++; 23 | } 24 | return (0); 25 | } 26 | -------------------------------------------------------------------------------- /libft/sources/strings/ft_strisnum.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strisnum.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: cfeijoo +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2014/02/22 23:13:52 by cfeijoo #+# #+# */ 9 | /* Updated: 2014/02/22 23:17:55 by cfeijoo ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | /* 16 | ** Checks if string is only composed of digits (valid int) 17 | */ 18 | 19 | int ft_strisnum(char *str) 20 | { 21 | while (*str) 22 | { 23 | if (!ft_isdigit(*str)) 24 | return (0); 25 | str++; 26 | } 27 | return (1); 28 | } 29 | -------------------------------------------------------------------------------- /libft/sources/strings/ft_striter.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_striter.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: cfeijoo +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2013/11/24 04:19:34 by cfeijoo #+# #+# */ 9 | /* Updated: 2014/02/17 21:57:48 by cfeijoo ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | void ft_striter(char *s, void (*f)(char *)) 14 | { 15 | if (*f && s) 16 | { 17 | while (*s) 18 | { 19 | (*f)(s); 20 | s++; 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /libft/sources/strings/ft_striteri.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_striteri.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: cfeijoo +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2013/11/24 04:22:36 by cfeijoo #+# #+# */ 9 | /* Updated: 2014/02/17 21:57:54 by cfeijoo ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | void ft_striteri(char *s, void (*f)(unsigned int, char *)) 14 | { 15 | unsigned int i; 16 | 17 | i = 0; 18 | if (s && f && *f) 19 | { 20 | while (s[i]) 21 | { 22 | (*f)(i, s + i); 23 | i++; 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /libft/sources/strings/ft_strjoin.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strjoin.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: cfeijoo +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2013/11/24 04:40:04 by cfeijoo #+# #+# */ 9 | /* Updated: 2014/02/17 21:24:36 by cfeijoo ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | #include 15 | 16 | char *ft_strjoin(char const *s1, char const *s2) 17 | { 18 | size_t length; 19 | char *new; 20 | char nullchar; 21 | 22 | nullchar = 0; 23 | if (!s1) 24 | s1 = &nullchar; 25 | if (!s2) 26 | s2 = &nullchar; 27 | length = ft_strlen(s1) + ft_strlen(s2); 28 | new = (char*)malloc(length * sizeof(*new)); 29 | if (new) 30 | { 31 | ft_strcpy(new, s1); 32 | ft_strcpy(new + ft_strlen(s1), s2); 33 | } 34 | return (new); 35 | } 36 | -------------------------------------------------------------------------------- /libft/sources/strings/ft_strlcat.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strlcat.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: cfeijoo +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2013/11/24 02:05:17 by cfeijoo #+# #+# */ 9 | /* Updated: 2014/02/17 21:59:30 by cfeijoo ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | size_t ft_strlcat(char *dst, const char *src, size_t size) 16 | { 17 | char *d; 18 | const char *s; 19 | size_t dlen; 20 | size_t n; 21 | 22 | d = dst; 23 | s = src; 24 | n = size; 25 | while (n-- != 0 && *d != 0) 26 | d++; 27 | dlen = d - dst; 28 | n = size - dlen; 29 | if (!n) 30 | return (dlen + ft_strlen(s)); 31 | while (*s != '\0') 32 | { 33 | if (n != 1) 34 | { 35 | *d++ = *s; 36 | n--; 37 | } 38 | s++; 39 | } 40 | *d = 0; 41 | return (dlen + (s - src)); 42 | } 43 | -------------------------------------------------------------------------------- /libft/sources/strings/ft_strlen.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strlen.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: cfeijoo +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2013/11/22 01:34:43 by cfeijoo #+# #+# */ 9 | /* Updated: 2014/02/19 05:09:25 by cfeijoo ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | size_t ft_strlen (const char *s) 16 | { 17 | size_t length; 18 | 19 | length = 0; 20 | while (s[length]) 21 | length++; 22 | return (length); 23 | } 24 | -------------------------------------------------------------------------------- /libft/sources/strings/ft_strmap.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strmap.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: cfeijoo +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2013/11/24 04:24:44 by cfeijoo #+# #+# */ 9 | /* Updated: 2014/02/17 21:21:37 by cfeijoo ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | char *ft_strmap(char const*s, char (*f)(char)) 16 | { 17 | char *newstr; 18 | 19 | if (s && *f) 20 | { 21 | newstr = ft_strdup(s); 22 | ft_striter((char*)newstr, (void(*)(char*))f); 23 | return (newstr); 24 | } 25 | return (0); 26 | } 27 | -------------------------------------------------------------------------------- /libft/sources/strings/ft_strmapi.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strmapi.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: cfeijoo +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2013/11/24 04:30:09 by cfeijoo #+# #+# */ 9 | /* Updated: 2014/02/17 22:42:35 by cfeijoo ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | char *ft_strmapi(char const *s, char (*f)(unsigned int, char)) 16 | { 17 | char *newstr; 18 | 19 | if (s && *f) 20 | { 21 | newstr = ft_strdup(s); 22 | ft_striteri((char*)s, (void(*)(unsigned int, char*))f); 23 | return (newstr); 24 | } 25 | return (0); 26 | } 27 | -------------------------------------------------------------------------------- /libft/sources/strings/ft_strncat.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strncat.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: cfeijoo +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2013/11/23 08:08:06 by cfeijoo #+# #+# */ 9 | /* Updated: 2014/02/17 21:21:58 by cfeijoo ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | char *ft_strncat(char *s1, const char *s2, size_t n) 16 | { 17 | size_t i; 18 | size_t len1; 19 | 20 | i = 0; 21 | len1 = ft_strlen(s1); 22 | while (s2[i] && i < n) 23 | { 24 | s1[len1 + i] = s2[i]; 25 | i++; 26 | } 27 | s1[len1 + i] = 0; 28 | return (s1); 29 | } 30 | -------------------------------------------------------------------------------- /libft/sources/strings/ft_strncmp.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strncmp.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: cfeijoo +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2013/11/24 02:20:16 by cfeijoo #+# #+# */ 9 | /* Updated: 2014/02/17 21:28:40 by cfeijoo ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | int ft_strncmp(const char *s1, const char *s2, size_t n) 16 | { 17 | size_t i; 18 | 19 | i = 0; 20 | while (s1[i] && s2[i] && s1[i] == s2[i] && i < n) 21 | i++; 22 | if (s1[i] > s2[i]) 23 | return (1); 24 | else if (s1[i] < s2[i]) 25 | return (-1); 26 | else 27 | return (0); 28 | } 29 | -------------------------------------------------------------------------------- /libft/sources/strings/ft_strncpy.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strncpy.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: cfeijoo +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2013/11/22 02:15:04 by cfeijoo #+# #+# */ 9 | /* Updated: 2014/02/17 21:58:06 by cfeijoo ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | char *ft_strncpy(char *s1, const char *s2, size_t n) 16 | { 17 | unsigned int i; 18 | size_t len2; 19 | 20 | i = 0; 21 | len2 = ft_strlen((char*)s2); 22 | while (i < n) 23 | { 24 | if (i < len2) 25 | s1[i] = s2[i]; 26 | else 27 | s1[i] = 0; 28 | i++; 29 | } 30 | return (s1); 31 | } 32 | -------------------------------------------------------------------------------- /libft/sources/strings/ft_strnequ.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strnequ.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: cfeijoo +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2013/11/24 04:35:21 by cfeijoo #+# #+# */ 9 | /* Updated: 2014/02/17 21:58:14 by cfeijoo ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | int ft_strnequ(char const *s1, char const *s2, size_t n) 16 | { 17 | if (s1 && s2) 18 | { 19 | while ((*s1 || *s2) && n) 20 | { 21 | if (*s1 != *s2) 22 | return (0); 23 | s1++; 24 | s2++; 25 | n--; 26 | } 27 | return (1); 28 | } 29 | return (0); 30 | } 31 | -------------------------------------------------------------------------------- /libft/sources/strings/ft_strnew.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strnew.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: cfeijoo +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2013/11/24 04:07:01 by cfeijoo #+# #+# */ 9 | /* Updated: 2014/02/17 21:58:20 by cfeijoo ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | #include 15 | 16 | char *ft_strnew(size_t size) 17 | { 18 | char *newstr; 19 | 20 | if (size) 21 | { 22 | newstr = (char*)malloc((size + 1) * sizeof(char)); 23 | if (newstr) 24 | { 25 | ft_bzero(newstr, size + 1); 26 | return (newstr); 27 | } 28 | } 29 | return (0); 30 | } 31 | -------------------------------------------------------------------------------- /libft/sources/strings/ft_strnstr.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strnstr.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: cfeijoo +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2013/11/24 02:14:37 by cfeijoo #+# #+# */ 9 | /* Updated: 2014/02/17 21:58:26 by cfeijoo ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | char *ft_strnstr(const char *s1, const char *s2, size_t n) 16 | { 17 | size_t begin; 18 | size_t current; 19 | 20 | begin = 0; 21 | current = 0; 22 | if (!*s2) 23 | return ((char *)s1); 24 | while (s1[begin] && n > begin) 25 | { 26 | if (s1[begin + current] == s2[current] && begin + current < n) 27 | current++; 28 | else 29 | { 30 | current = 0; 31 | begin++; 32 | } 33 | if (!s2[current]) 34 | return ((char *)s1 + begin); 35 | } 36 | return (0); 37 | } 38 | -------------------------------------------------------------------------------- /libft/sources/strings/ft_strrchr.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strrchr.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: cfeijoo +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2013/11/23 08:23:18 by cfeijoo #+# #+# */ 9 | /* Updated: 2014/02/17 21:58:38 by cfeijoo ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | char *ft_strrchr(const char *s, int c) 16 | { 17 | int i; 18 | 19 | i = ft_strlen((char*)s); 20 | while (i >= 0) 21 | { 22 | if (s[i] == (char)c) 23 | return ((char*)(s + i)); 24 | i--; 25 | } 26 | return (0); 27 | } 28 | -------------------------------------------------------------------------------- /libft/sources/strings/ft_strsplit.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strsplit.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: cfeijoo +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2013/11/24 04:44:28 by cfeijoo #+# #+# */ 9 | /* Updated: 2014/02/17 21:45:30 by cfeijoo ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | #include 15 | 16 | static int ft_getwordsnb(char const *s, char c) 17 | { 18 | unsigned int nb; 19 | size_t i; 20 | 21 | i = 0; 22 | nb = 0; 23 | while (s && s[i]) 24 | { 25 | while ((char)s[i] == c) 26 | i++; 27 | if(s[i] && (char)s[i] != c) 28 | nb++; 29 | while(s[i] && (char)s[i] != c) 30 | i++; 31 | } 32 | return (nb); 33 | } 34 | 35 | char **ft_strsplit(char const *s, char c) 36 | { 37 | char *t; 38 | char **splited; 39 | size_t k; 40 | 41 | splited = (char**)malloc((ft_getwordsnb(s, c) + 1) * sizeof(char*)); 42 | t = ft_strdup(s); 43 | k = 0; 44 | while (t && *t) 45 | { 46 | while (*t == c) 47 | { 48 | *t = 0; 49 | t++; 50 | } 51 | if (*t && *t != c) 52 | { 53 | splited[k] = t; 54 | k++; 55 | } 56 | while(*t && *t != c) 57 | t++; 58 | } 59 | splited[k] = 0; 60 | return (splited); 61 | } 62 | -------------------------------------------------------------------------------- /libft/sources/strings/ft_strstr.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strstr.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: cfeijoo +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2013/11/24 02:09:58 by cfeijoo #+# #+# */ 9 | /* Updated: 2014/02/17 21:58:51 by cfeijoo ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | char *ft_strstr(const char *s1, const char *s2) 14 | { 15 | int begin; 16 | int current; 17 | 18 | begin = 0; 19 | current = 0; 20 | if (!*s2) 21 | return ((char *)s1); 22 | while (s1[begin]) 23 | { 24 | if (s1[begin + current] == s2[current]) 25 | current++; 26 | else 27 | { 28 | current = 0; 29 | begin++; 30 | } 31 | if (!s2[current]) 32 | return ((char *)s1 + begin); 33 | } 34 | return (0); 35 | } 36 | -------------------------------------------------------------------------------- /libft/sources/strings/ft_strsub.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strsub.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: cfeijoo +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2013/11/24 04:37:52 by cfeijoo #+# #+# */ 9 | /* Updated: 2014/02/17 21:58:59 by cfeijoo ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | char *ft_strsub(char const *s, unsigned int start, size_t len) 16 | { 17 | char *newstr; 18 | 19 | if (s && len && start + len <= ft_strlen(s)) 20 | { 21 | newstr = ft_strnew(len); 22 | if (newstr) 23 | return (ft_strncpy(newstr, s + start, len)); 24 | } 25 | return (0); 26 | } 27 | -------------------------------------------------------------------------------- /libft/sources/strings/ft_strtrim.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strtrim.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: cfeijoo +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2013/11/24 04:42:43 by cfeijoo #+# #+# */ 9 | /* Updated: 2014/02/17 21:59:14 by cfeijoo ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | static int ft_isspace(char c) 16 | { 17 | if (c == ' ' || 18 | c == '\n' || 19 | c == '\t' || 20 | c == '\v' || 21 | c == '\f' || 22 | c == '\r') 23 | { 24 | return (1); 25 | } 26 | return (0); 27 | } 28 | 29 | char *ft_strtrim(char const *s) 30 | { 31 | unsigned int i; 32 | unsigned int j; 33 | char *newstr; 34 | 35 | if (s) 36 | { 37 | i = 0; 38 | while (ft_isspace(s[i])) 39 | i++; 40 | j = ft_strlen(s); 41 | while (ft_isspace(s[j])) 42 | j--; 43 | newstr = ft_strsub(s, i, j - i); 44 | return (newstr); 45 | } 46 | return (0); 47 | } 48 | -------------------------------------------------------------------------------- /objects/.gitignore: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kube/RT/5913f4753a3e8f1e6c2a829fa83fd69dfc86112f/objects/.gitignore -------------------------------------------------------------------------------- /sources/camera/camera_init.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* camera_init.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: cfeijoo +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2014/03/09 01:50:07 by kube #+# #+# */ 9 | /* Updated: 2014/03/18 22:14:13 by cfeijoo ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | void init_cam(t_camera *cam, float x, float y, float z) 16 | { 17 | cam->x_axis.x = 1.0f; 18 | cam->x_axis.y = 0.0f; 19 | cam->x_axis.z = 0.0f; 20 | cam->y_axis.x = 0.0f; 21 | cam->y_axis.y = 1.0f; 22 | cam->y_axis.z = 0.0f; 23 | cam->z_axis.x = 0.0f; 24 | cam->z_axis.y = 0.0f; 25 | cam->z_axis.z = 1.0f; 26 | cam->origin.x = x; 27 | cam->origin.y = y; 28 | cam->origin.z = z; 29 | } 30 | 31 | void init_cam_angle(t_camera *cam, float y, float z) 32 | { 33 | cam_rot_y(cam, y); 34 | cam_rot_z(cam, z); 35 | } 36 | 37 | void update_render_cam(t_camera *render_cam, t_camera *camera) 38 | { 39 | render_cam->origin = camera->origin; 40 | render_cam->x_axis = camera->x_axis; 41 | render_cam->y_axis = camera->y_axis; 42 | render_cam->z_axis = camera->z_axis; 43 | } 44 | -------------------------------------------------------------------------------- /sources/equations/change_ray.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* change_ray.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: cfeijoo +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2014/03/26 13:08:39 by lbinet #+# #+# */ 9 | /* Updated: 2014/03/27 20:18:25 by cfeijoo ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | 19 | void change_ray(t_ray *ray, t_ray *new_ray, t_object *obj, 20 | t_object *new_obj) 21 | { 22 | float matrix[9]; 23 | float inverted_matrix[9]; 24 | t_vector x; 25 | t_vector y; 26 | t_vector z; 27 | 28 | z = obj->normal; 29 | if (z.x == 0 && z.y == 0 && (z.z == 1 || z.z == -1)) 30 | return; 31 | if ((z.x == 1 || z.x == -1) && z.y == 0 && z.y == 0) 32 | { 33 | x.x = 0; 34 | x.y = 1; 35 | x.z = 0; 36 | y.x = 0; 37 | y.y = 0; 38 | y.z = 1; 39 | } 40 | else if (z.x == 0 && (z.y == 1 || z.y == -1) && z.z == 0) 41 | { 42 | x.x = 0; 43 | x.y = 0; 44 | x.z = 1; 45 | y.x = 1; 46 | y.y = 0; 47 | y.z = 0; 48 | } 49 | else 50 | { 51 | normalize_vector(&z); 52 | y.x = -z.y; 53 | y.y = z.x; 54 | y.z = 0; 55 | normalize_vector(&y); 56 | x = vect_product(&y, &z); 57 | normalize_vector(&x); 58 | } 59 | transformation_matrix(matrix, &x, &y, &z); 60 | invert_matrix(matrix, inverted_matrix); 61 | new_ray->origin = matrix_point_product(inverted_matrix, &ray->origin); 62 | new_obj->origin = matrix_point_product(inverted_matrix, &obj->origin); 63 | new_ray->direction = matrix_vector_product(inverted_matrix, &ray->direction); 64 | } 65 | -------------------------------------------------------------------------------- /sources/equations/equation_cone.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* equation_cone.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: cfeijoo +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2014/03/26 18:27:36 by cfeijoo #+# #+# */ 9 | /* Updated: 2014/03/27 20:24:49 by cfeijoo ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | 19 | float cone_equation(t_object *cone, t_ray *ray) 20 | { 21 | double a; 22 | double b; 23 | double c; 24 | double det; 25 | double angle; 26 | 27 | angle = cone->aperture * (M_PI / 180); 28 | a = ray->direction.x * ray->direction.x + ray->direction.y * ray->direction.y - ray->direction.z * ray->direction.z 29 | * tan(angle) * tan(angle); 30 | b = 2 * (ray->origin.x * ray->direction.x + ray->origin.y * ray->direction.y - ray->direction.x * cone->origin.x 31 | - ray->direction.y * cone->origin.y + (ray->direction.z * (cone->origin.z - ray->origin.z)) 32 | * tan(angle) * tan(angle)); 33 | c = ray->origin.x * ray->origin.x + ray->origin.y * ray->origin.y + cone->origin.x * cone->origin.x 34 | + cone->origin.y * cone->origin.y - 2 * (ray->origin.x * cone->origin.x + ray->origin.y * cone->origin.y) 35 | - (ray->origin.z * ray->origin.z - 2 * (ray->origin.z * cone->origin.z) + cone->origin.z * cone->origin.z) 36 | * tan(angle) * tan(angle); 37 | det = b * b - 4 * a * c; 38 | if (det >= 0) 39 | { 40 | det = sqrt(det); 41 | return (positive_smallest((-b + det) / (2 * a), (-b - det) / (2 * a))); 42 | } 43 | return (INFINITY); 44 | } 45 | -------------------------------------------------------------------------------- /sources/equations/equation_cylinder.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* equation_cylinder.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: cfeijoo +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2014/03/23 21:05:44 by cfeijoo #+# #+# */ 9 | /* Updated: 2014/03/27 20:24:59 by cfeijoo ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | 19 | float cylinder_equation(t_object *cylinder, t_ray *ray) 20 | { 21 | float a; 22 | float b; 23 | float c; 24 | float det; 25 | float res; 26 | 27 | a = ray->direction.x * ray->direction.x + ray->direction.y * ray->direction.y; 28 | b = 2 * (ray->origin.x * ray->direction.x + ray->origin.y * ray->direction.y 29 | - ray->direction.x * cylinder->origin.x - ray->direction.y * cylinder->origin.y); 30 | c = ray->origin.x * ray->origin.x + ray->origin.y * ray->origin.y + cylinder->origin.x * cylinder->origin.x 31 | + cylinder->origin.y * cylinder->origin.y - cylinder->radius * cylinder->radius - 2 * (ray->origin.x * cylinder->origin.x 32 | + ray->origin.y * cylinder->origin.y); 33 | det = b * b - 4 * a * c; 34 | if (det >= 0) 35 | { 36 | det = sqrt(det); 37 | res = positive_smallest((-b + det) / (2 * a), (-b -det) / (2 * a)); 38 | return (res); 39 | } 40 | return (INFINITY); 41 | } 42 | -------------------------------------------------------------------------------- /sources/equations/equation_plane.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* equation_plane.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: cfeijoo +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2014/03/26 18:29:42 by cfeijoo #+# #+# */ 9 | /* Updated: 2014/03/26 18:30:38 by cfeijoo ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | #include 15 | #include 16 | #include 17 | 18 | float plane_equation(t_object *plane, t_ray *ray) 19 | { 20 | float n; 21 | float d; 22 | float res; 23 | 24 | n = plane->normal.x * (plane->origin.x - ray->origin.x) 25 | + plane->normal.y * (plane->origin.y - ray->origin.y) 26 | + plane->normal.z * (plane->origin.z - ray->origin.z); 27 | d = plane->normal.x * ray->direction.x 28 | + plane->normal.y * ray->direction.y 29 | + plane->normal.z * ray->direction.z; 30 | if ((res = n / d) > 0) 31 | return (res); 32 | return (INFINITY); 33 | } 34 | -------------------------------------------------------------------------------- /sources/equations/positive_smallest.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* positive_smallest.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: cfeijoo +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2014/03/05 19:30:09 by lbinet #+# #+# */ 9 | /* Updated: 2014/03/26 18:31:44 by cfeijoo ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | #include 15 | #include 16 | #include 17 | 18 | float positive_smallest(float a, float b) 19 | { 20 | if (a < 0) 21 | { 22 | if (b > 0) 23 | return (b); 24 | return (INFINITY); 25 | } 26 | if (b < 0) 27 | { 28 | if (a > 0) 29 | return (a); 30 | return (INFINITY); 31 | } 32 | if (a < b) 33 | return (a); 34 | return (b); 35 | } 36 | -------------------------------------------------------------------------------- /sources/interpreter/command_antialias.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* command_antialias.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: cfeijoo +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2014/03/17 03:01:57 by cfeijoo #+# #+# */ 9 | /* Updated: 2014/03/27 17:14:01 by cfeijoo ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | #include 15 | #include 16 | 17 | void cmd_antialias(char **line) 18 | { 19 | int value; 20 | 21 | value = -1; 22 | if (*line) 23 | value = ft_atoi(*line); 24 | if (value < 1 || value > 40 || !line[1]) 25 | env->scene->antialias = (unsigned int)value; 26 | else 27 | ft_putendl_fd("usage: antialias ", 2); 28 | } 29 | -------------------------------------------------------------------------------- /sources/interpreter/command_editmode.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* command_editmode.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: cfeijoo +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2014/03/17 03:01:57 by cfeijoo #+# #+# */ 9 | /* Updated: 2014/03/27 00:16:33 by cfeijoo ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | #include 15 | #include 16 | 17 | void cmd_editmode(char **line) 18 | { 19 | (void)line; 20 | env->fast_mode = 1; 21 | env->last_scene_change = clock(); 22 | env->block_events = 0; 23 | } 24 | -------------------------------------------------------------------------------- /sources/interpreter/command_export.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* command_export.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: cfeijoo +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2014/03/17 03:01:57 by cfeijoo #+# #+# */ 9 | /* Updated: 2014/03/27 19:42:55 by cfeijoo ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | 19 | void cmd_export(char **line) 20 | { 21 | int file; 22 | 23 | file = 1; 24 | if ((ft_strequ(*line, "image") 25 | || ft_strequ(*line, "scene")) 26 | && line[1]) 27 | file = open(line[1], O_CREAT | O_TRUNC | O_WRONLY, 0666); 28 | else 29 | ft_putendl_fd("usage: export [image|scene] ", 2); 30 | if (file > 0) 31 | { 32 | if (ft_strequ(*line, "image")) 33 | export_image(file); 34 | else if (ft_strequ(*line, "scene")) 35 | export_scene(file); 36 | close(file); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /sources/interpreter/command_list.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* command_list.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: cfeijoo +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2014/03/17 03:01:57 by cfeijoo #+# #+# */ 9 | /* Updated: 2014/03/27 00:01:45 by cfeijoo ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | #include 15 | 16 | #include 17 | 18 | void cmd_list(char **line) 19 | { 20 | t_object *object; 21 | t_light *light; 22 | 23 | (void)line; 24 | object = env->scene->objects; 25 | ft_putendl("OBJECTS:"); 26 | while (object) 27 | { 28 | if (object->type == OBJ_SPHERE) 29 | ft_putstr("Sphere "); 30 | else if (object->type == OBJ_PLANE) 31 | ft_putstr("Plane "); 32 | printf("\t%u\n", (unsigned int)object); 33 | ft_putendl(""); 34 | object = object->next; 35 | } 36 | light = env->scene->lights; 37 | ft_putendl("\nLIGHTS:"); 38 | while (light) 39 | { 40 | ft_putstr("Light "); 41 | printf("\t%u\n", (unsigned int)light); 42 | ft_putendl(""); 43 | light = light->next; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /sources/interpreter/command_recursivity.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* command_recursivity.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: cfeijoo +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2014/03/17 03:01:57 by cfeijoo #+# #+# */ 9 | /* Updated: 2014/03/27 00:18:36 by cfeijoo ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | #include 15 | #include 16 | 17 | void cmd_recursivity(char **line) 18 | { 19 | int value; 20 | 21 | value = -1; 22 | if (*line) 23 | value = ft_atoi(*line); 24 | if (value < 0 || value > 40 || !line[1]) 25 | env->scene->recursivity = (unsigned int)value; 26 | else 27 | ft_putendl_fd("usage: recursivity ", 2); 28 | } 29 | -------------------------------------------------------------------------------- /sources/interpreter/command_remove.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* command_remove.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: cfeijoo +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2014/03/17 03:01:57 by cfeijoo #+# #+# */ 9 | /* Updated: 2014/03/27 19:50:48 by cfeijoo ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | #include 15 | #include 16 | 17 | static int search_objects(int search) 18 | { 19 | t_object *object; 20 | 21 | object = env->scene->objects; 22 | while (object) 23 | { 24 | if ((int)object == search) 25 | { 26 | remove_object(env->scene, object); 27 | return (1); 28 | } 29 | object = object->next; 30 | } 31 | return (0); 32 | } 33 | 34 | static int search_lights(int search) 35 | { 36 | t_light *light; 37 | 38 | light = env->scene->lights; 39 | while (light) 40 | { 41 | if ((int)light == search) 42 | { 43 | remove_light(env->scene, light); 44 | return (1); 45 | } 46 | light = light->next; 47 | } 48 | return (0); 49 | } 50 | 51 | void cmd_remove(char **line) 52 | { 53 | int search; 54 | 55 | if (*line) 56 | { 57 | search = (unsigned int)ft_atoi(*line); 58 | if (search_objects(search)) 59 | return ; 60 | if (search_lights(search)) 61 | return ; 62 | ft_putendl("Object not found."); 63 | } 64 | else 65 | ft_putendl("usage: remove "); 66 | } 67 | -------------------------------------------------------------------------------- /sources/interpreter/command_render.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* command_render.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: cfeijoo +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2014/03/17 03:01:57 by cfeijoo #+# #+# */ 9 | /* Updated: 2014/03/27 00:15:42 by cfeijoo ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | #include 15 | #include 16 | 17 | void cmd_render(char **line) 18 | { 19 | (void)line; 20 | env->fast_mode = 0; 21 | env->last_scene_change = clock(); 22 | env->block_events = 1; 23 | } 24 | -------------------------------------------------------------------------------- /sources/interpreter/command_unblock.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* command_unblock.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: cfeijoo +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2014/03/17 03:01:57 by cfeijoo #+# #+# */ 9 | /* Updated: 2014/03/27 00:25:55 by cfeijoo ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | #include 15 | #include 16 | 17 | void cmd_unblock(char **line) 18 | { 19 | (void)line; 20 | env->block_events = 0; 21 | } 22 | -------------------------------------------------------------------------------- /sources/interpreter/init_interpreter.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* init_interpreter.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: cfeijoo +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2014/03/27 18:12:41 by cfeijoo #+# #+# */ 9 | /* Updated: 2014/05/15 02:03:00 by cfeijoo ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | 19 | static void interpreter_add_command(t_command **commands, char *token, 20 | void (*callback)(char**)) 21 | { 22 | t_command *new_command; 23 | 24 | new_command = (t_command*)malloc(sizeof(t_command)); 25 | new_command->token = ft_strdup(token); 26 | new_command->callback = callback; 27 | new_command->next = *commands; 28 | *commands = new_command; 29 | } 30 | 31 | void interpreter_init_commands(t_interpreter *interpreter) 32 | { 33 | interpreter->commands = NULL; 34 | interpreter_add_command(&interpreter->commands, "list", cmd_list); 35 | interpreter_add_command(&interpreter->commands, "remove", cmd_remove); 36 | interpreter_add_command(&interpreter->commands, "add", cmd_add); 37 | interpreter_add_command(&interpreter->commands, "export", cmd_export); 38 | interpreter_add_command(&interpreter->commands, "antialias", cmd_antialias); 39 | interpreter_add_command(&interpreter->commands, "render", cmd_render); 40 | interpreter_add_command(&interpreter->commands, "edit_mode", cmd_editmode); 41 | interpreter_add_command(&interpreter->commands, "recursion", 42 | cmd_recursivity); 43 | interpreter_add_command(&interpreter->commands, "unblock", cmd_unblock); 44 | } 45 | -------------------------------------------------------------------------------- /sources/keyboard.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* keyboard.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: cfeijoo +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2014/03/08 15:50:12 by cfeijoo #+# #+# */ 9 | /* Updated: 2014/03/27 15:58:17 by cfeijoo ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | 19 | void init_pressed_keys(t_pressedkeys *keys) 20 | { 21 | ft_bzero(keys, sizeof(*keys)); 22 | } 23 | 24 | int is_one_key_pressed(t_pressedkeys *keys) 25 | { 26 | int i; 27 | int *key; 28 | 29 | i = 0; 30 | key = (int*)keys; 31 | while ((size_t)key - (size_t)(keys) < sizeof(*keys)) 32 | { 33 | if (*key) 34 | return (1); 35 | key++; 36 | } 37 | return (0); 38 | } 39 | -------------------------------------------------------------------------------- /sources/keyboard/keyboard.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* keyboard.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: cfeijoo +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2014/03/08 15:50:12 by cfeijoo #+# #+# */ 9 | /* Updated: 2014/03/27 16:00:27 by cfeijoo ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | 19 | void init_pressed_keys(t_pressedkeys *keys) 20 | { 21 | ft_bzero(keys, sizeof(*keys)); 22 | } 23 | 24 | int is_one_key_pressed(t_pressedkeys *keys) 25 | { 26 | int i; 27 | int *key; 28 | 29 | i = 0; 30 | key = (int*)keys; 31 | while ((size_t)key - (size_t)(keys) < sizeof(*keys)) 32 | { 33 | if (*key) 34 | return (1); 35 | key++; 36 | } 37 | return (0); 38 | } 39 | -------------------------------------------------------------------------------- /sources/keyboard/keyrelease_hook.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* keyrelease_hook.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: cfeijoo +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2014/03/27 15:53:32 by cfeijoo #+# #+# */ 9 | /* Updated: 2014/03/27 16:03:36 by cfeijoo ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | 19 | int keyrelease_hook(int keycode, t_pressedkeys *keys) 20 | { 21 | if (keycode == 65363) 22 | keys->right = 0; 23 | else if (keycode == 65361) 24 | keys->left = 0; 25 | else if (keycode == 65362) 26 | keys->up = 0; 27 | else if (keycode == 65364) 28 | keys->down = 0; 29 | else if (keycode == 65365) 30 | keys->p_up = 0; 31 | else if (keycode == 65366) 32 | keys->p_down = 0; 33 | else if (keycode == 65451) 34 | keys->num_plus = 0; 35 | else if (keycode == 65453) 36 | keys->num_minus = 0; 37 | else if (keycode == 119) 38 | keys->w = 0; 39 | else if (keycode == 97) 40 | keys->a = 0; 41 | else if (keycode == 115) 42 | keys->s = 0; 43 | else if (keycode == 100) 44 | keys->d = 0; 45 | else if (keycode == 65535) 46 | keys->del = 0; 47 | else if (keycode == 32) 48 | keys->space = 0; 49 | else if (keycode == 65507) 50 | keys->ctrl = 0; 51 | else if (keycode == 65289) 52 | keys->tab = 0; 53 | else if (keycode == 65406 || keycode == 65513) 54 | keys->alt = 0; 55 | return (0); 56 | } 57 | -------------------------------------------------------------------------------- /sources/light_diaphragm.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* light_diaphragm.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: cfeijoo +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2014/03/17 20:03:19 by cfeijoo #+# #+# */ 9 | /* Updated: 2014/03/23 15:36:33 by cfeijoo ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | #include 15 | 16 | int light_diaphragm(t_light_color *light, float diaphragm) 17 | { 18 | t_color color; 19 | 20 | color.red = (unsigned char)(fmin((light->red / diaphragm), 1.0) * 255); 21 | color.blue = (unsigned char)(fmin((light->blue / diaphragm), 1.0) * 255); 22 | color.green = (unsigned char)(fmin((light->green / diaphragm), 1.0) * 255); 23 | return (color.color); 24 | } 25 | -------------------------------------------------------------------------------- /sources/mouse/mouse.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* mouse.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: cfeijoo +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2014/03/13 02:33:19 by cfeijoo #+# #+# */ 9 | /* Updated: 2014/03/27 16:30:20 by cfeijoo ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | 20 | int mousepress_ev(int button, int x, int y) 21 | { 22 | t_ray ray; 23 | 24 | if (env->block_events) 25 | return (0); 26 | ray = get_ray_from_point(x, y); 27 | throw_ray(&ray, 0, NULL, 0); 28 | if (button == 1) 29 | env->pressed_mouse = 1; 30 | if (ray.inter_t != INFINITY) 31 | { 32 | if (button == 1 && env->pressed_keys.del) 33 | { 34 | remove_object(env->scene, ray.closest); 35 | update_image(env); 36 | } 37 | else 38 | { 39 | if (button == 3) 40 | { 41 | ft_putstr("Selected object "); 42 | ft_putunbr((unsigned int)ray.closest); 43 | ft_putendl("."); 44 | } 45 | env->selected_object = ray.closest; 46 | } 47 | } 48 | return (0); 49 | } 50 | 51 | int mouserelease_ev(int button, int x, int y) 52 | { 53 | (void)x; 54 | (void)y; 55 | if (env->block_events) 56 | return (0); 57 | if (button == 1 || button == 0) 58 | { 59 | env->selected_object = NULL; 60 | env->pressed_mouse = 0; 61 | } 62 | return (0); 63 | } 64 | -------------------------------------------------------------------------------- /sources/pixel.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* pixel.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: cfeijoo +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2014/03/17 20:01:18 by cfeijoo #+# #+# */ 9 | /* Updated: 2014/03/19 16:09:39 by cfeijoo ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | void pixel_to_image(int x, int y, int color) 16 | { 17 | unsigned int i; 18 | 19 | i = env->scene->view_width * (unsigned int)y + (unsigned int)x; 20 | if (i < env->scene->view_width * env->scene->view_height && (int)y >= 0 21 | && (int)x >= 0 && (unsigned int)x < env->scene->view_width) 22 | env->data[i] = color; 23 | } 24 | -------------------------------------------------------------------------------- /sources/scene_parser/command_add_cone.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* command_add_cone.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: cfeijoo +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2014/03/27 15:22:51 by acollin #+# #+# */ 9 | /* Updated: 2014/03/27 19:19:14 by cfeijoo ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | #include 15 | #include 16 | #include 17 | 18 | void cmd_add_cone(t_parser *parser, char **line) 19 | { 20 | (void)line; 21 | parser->last_type = LAST_OBJECT; 22 | add_object(env->scene, new_object(OBJ_CONE)); 23 | } 24 | -------------------------------------------------------------------------------- /sources/scene_parser/command_add_cylinder.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* command_add_cylinder.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: cfeijoo +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2014/03/27 15:25:36 by acollin #+# #+# */ 9 | /* Updated: 2014/03/27 18:49:34 by cfeijoo ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | #include 15 | #include 16 | #include 17 | 18 | void cmd_add_cylinder(t_parser *parser, char **line) 19 | { 20 | (void)line; 21 | parser->last_type = LAST_OBJECT; 22 | add_object(env->scene, new_object(OBJ_CYLINDER)); 23 | } 24 | -------------------------------------------------------------------------------- /sources/scene_parser/command_add_light.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* command_add_light.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: acollin +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2014/03/27 15:12:06 by acollin #+# #+# */ 9 | /* Updated: 2014/03/27 16:48:38 by acollin ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | 20 | void cmd_add_light(t_parser *parser, char **line) 21 | { 22 | t_light *new_light; 23 | 24 | (void)line; 25 | new_light = (t_light *)ft_memalloc(sizeof(t_light)); 26 | new_light->intensity = 1.0; 27 | new_light->color.red = 1.0; 28 | new_light->color.green = 1.0; 29 | new_light->color.blue = 1.0; 30 | new_light->next = env->scene->lights; 31 | env->scene->lights = new_light; 32 | parser->last_type = LAST_LIGHT; 33 | } 34 | -------------------------------------------------------------------------------- /sources/scene_parser/command_add_plane.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* command_add_plane.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: cfeijoo +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2014/03/27 14:29:14 by cfeijoo #+# #+# */ 9 | /* Updated: 2014/03/27 15:23:03 by acollin ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | #include 15 | #include 16 | #include 17 | 18 | void cmd_add_plane(t_parser *parser, char **line) 19 | { 20 | (void)line; 21 | parser->last_type = LAST_OBJECT; 22 | add_object(env->scene, new_object(OBJ_PLANE)); 23 | } 24 | -------------------------------------------------------------------------------- /sources/scene_parser/command_add_sphere.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* command_add_sphere.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: cfeijoo +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2014/03/27 14:29:14 by cfeijoo #+# #+# */ 9 | /* Updated: 2014/03/27 14:47:58 by cfeijoo ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | #include 15 | #include 16 | #include 17 | 18 | void cmd_add_sphere(t_parser *parser, char **line) 19 | { 20 | (void)line; 21 | parser->last_type = LAST_OBJECT; 22 | add_object(env->scene, new_object(OBJ_SPHERE)); 23 | } 24 | -------------------------------------------------------------------------------- /sources/scene_parser/command_camera.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* command_camera.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: cfeijoo +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2014/03/27 15:22:51 by acollin #+# #+# */ 9 | /* Updated: 2014/03/27 18:53:26 by cfeijoo ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | #include 15 | #include 16 | #include 17 | 18 | void cmd_camera(t_parser *parser, char **line) 19 | { 20 | (void)line; 21 | parser->last_type = LAST_CAMERA; 22 | } 23 | -------------------------------------------------------------------------------- /sources/scene_parser/command_define_ambient.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* command_define_ambient.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: cfeijoo +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2014/03/27 17:23:25 by acollin #+# #+# */ 9 | /* Updated: 2014/03/27 19:22:09 by cfeijoo ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | 20 | void cmd_define_ambient(t_parser *parser, char **line) 21 | { 22 | if (parser->last_type == LAST_OBJECT) 23 | env->scene->objects->ambient = atof(line[0]); 24 | else 25 | ft_putendl_fd("ERROR! Orphan Property: ambient.", 2); 26 | } 27 | -------------------------------------------------------------------------------- /sources/scene_parser/command_define_antialias.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* command_define_antialias.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: acollin +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2014/03/27 19:42:48 by acollin #+# #+# */ 9 | /* Updated: 2014/03/27 19:49:11 by acollin ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | 20 | void cmd_define_antialias(t_parser *parser, char **line) 21 | { 22 | unsigned int antialias; 23 | 24 | if (parser->last_type == LAST_NONE) 25 | { 26 | antialias = (unsigned int)ft_atoi(line[0]); 27 | if (antialias >= 1 && antialias <= 40) 28 | env->scene->antialias = antialias; 29 | } 30 | else 31 | ft_putendl_fd("ERROR! Orphan Property: antialias.", 2); 32 | } 33 | -------------------------------------------------------------------------------- /sources/scene_parser/command_define_axisx.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* command_define_axisx.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: acollin +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2014/03/27 19:55:11 by acollin #+# #+# */ 9 | /* Updated: 2014/03/27 20:06:38 by acollin ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | 20 | void cmd_define_x_axisx(t_parser *parser, char **line) 21 | { 22 | if (parser->last_type == LAST_CAMERA) 23 | env->scene->camera.x_axis.x = atof(line[0]); 24 | else 25 | ft_putendl_fd("ERROR! Orphan Property x_axis.", 2); 26 | } 27 | 28 | void cmd_define_x_axisy(t_parser *parser, char **line) 29 | { 30 | if (parser->last_type == LAST_CAMERA) 31 | env->scene->camera.x_axis.y = atof(line[0]); 32 | else 33 | ft_putendl_fd("ERROR! Orphan Property x_axis.", 2); 34 | } 35 | 36 | void cmd_define_x_axisz(t_parser *parser, char **line) 37 | { 38 | if (parser->last_type == LAST_CAMERA) 39 | env->scene->camera.x_axis.z = atof(line[0]); 40 | else 41 | ft_putendl_fd("ERROR! Orphan Property x_axis.", 2); 42 | } 43 | -------------------------------------------------------------------------------- /sources/scene_parser/command_define_axisy.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* command_define_axisy.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: acollin +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2014/03/27 20:01:22 by acollin #+# #+# */ 9 | /* Updated: 2014/03/27 20:03:13 by acollin ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | 20 | void cmd_define_y_axisx(t_parser *parser, char **line) 21 | { 22 | if (parser->last_type == LAST_CAMERA) 23 | env->scene->camera.y_axis.x = atof(line[0]); 24 | else 25 | ft_putendl_fd("ERROR! Orphan Property y_axis.", 2); 26 | } 27 | 28 | void cmd_define_y_axisy(t_parser *parser, char **line) 29 | { 30 | if (parser->last_type == LAST_CAMERA) 31 | env->scene->camera.y_axis.y = atof(line[0]); 32 | else 33 | ft_putendl_fd("ERROR! Orphan Property y_axis.", 2); 34 | } 35 | 36 | void cmd_define_y_axisz(t_parser *parser, char **line) 37 | { 38 | if (parser->last_type == LAST_CAMERA) 39 | env->scene->camera.y_axis.z = atof(line[0]); 40 | else 41 | ft_putendl_fd("ERROR! Orphan Property y_axis.", 2); 42 | } 43 | -------------------------------------------------------------------------------- /sources/scene_parser/command_define_axisz.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* command_define_axisz.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: acollin +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2014/03/27 20:03:41 by acollin #+# #+# */ 9 | /* Updated: 2014/03/27 20:04:51 by acollin ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | 20 | void cmd_define_z_axisx(t_parser *parser, char **line) 21 | { 22 | if (parser->last_type == LAST_CAMERA) 23 | env->scene->camera.z_axis.x = atof(line[0]); 24 | else 25 | ft_putendl_fd("ERROR! Orphan Property z_axis.", 2); 26 | } 27 | 28 | void cmd_define_z_axisy(t_parser *parser, char **line) 29 | { 30 | if (parser->last_type == LAST_CAMERA) 31 | env->scene->camera.z_axis.y = atof(line[0]); 32 | else 33 | ft_putendl_fd("ERROR! Orphan Property z_axis.", 2); 34 | } 35 | 36 | void cmd_define_z_axisz(t_parser *parser, char **line) 37 | { 38 | if (parser->last_type == LAST_CAMERA) 39 | env->scene->camera.z_axis.z = atof(line[0]); 40 | else 41 | ft_putendl_fd("ERROR! Orphan Property z_axis.", 2); 42 | } 43 | -------------------------------------------------------------------------------- /sources/scene_parser/command_define_color.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* command_define_color.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: cfeijoo +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2014/03/27 17:47:33 by acollin #+# #+# */ 9 | /* Updated: 2014/03/27 19:23:07 by cfeijoo ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | 20 | void cmd_define_color(t_parser *parser, char **line) 21 | { 22 | if (parser->last_type == LAST_OBJECT) 23 | env->scene->objects->color.color = (int)strtol(line[0], NULL, 16); 24 | else 25 | ft_putendl_fd("ERROR! Orphan Property: Color.", 2); 26 | } 27 | -------------------------------------------------------------------------------- /sources/scene_parser/command_define_diaphragm.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* command_define_diaphragm.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: cfeijoo +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2014/03/27 19:49:44 by acollin #+# #+# */ 9 | /* Updated: 2014/03/27 21:03:01 by cfeijoo ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | 19 | void cmd_define_diaphragm(t_parser *parser, char **line) 20 | { 21 | if (parser->last_type == LAST_NONE) 22 | env->scene->diaphragm = atof(line[0]); 23 | else 24 | ft_putendl_fd("ERROR! Orphan Property: diaphragm.", 2); 25 | } 26 | -------------------------------------------------------------------------------- /sources/scene_parser/command_define_diffuse.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* command_define_diffuse.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: cfeijoo +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2014/03/27 17:28:38 by acollin #+# #+# */ 9 | /* Updated: 2014/03/27 19:21:59 by cfeijoo ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | 20 | void cmd_define_diffuse(t_parser *parser, char **line) 21 | { 22 | if (parser->last_type == LAST_OBJECT) 23 | env->scene->objects->diffuse = atof(line[0]); 24 | else 25 | ft_putendl_fd("ERROR! Orphan Property: diffuse.", 2); 26 | } 27 | -------------------------------------------------------------------------------- /sources/scene_parser/command_define_height.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* command_define_height.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: acollin +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2014/03/27 19:41:37 by acollin #+# #+# */ 9 | /* Updated: 2014/03/27 19:42:12 by acollin ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | 20 | void cmd_define_height(t_parser *parser, char **line) 21 | { 22 | if (parser->last_type == LAST_NONE) 23 | env->scene->view_height = (unsigned int)ft_atoi(line[0]); 24 | else 25 | ft_putendl_fd("ERROR! Orphan Property: height.", 2); 26 | } 27 | -------------------------------------------------------------------------------- /sources/scene_parser/command_define_intensity.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* command_define_intensity.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: cfeijoo +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2014/03/27 17:45:59 by acollin #+# #+# */ 9 | /* Updated: 2014/03/27 19:23:02 by cfeijoo ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | 20 | void cmd_define_intensity(t_parser *parser, char **line) 21 | { 22 | if (parser->last_type == LAST_LIGHT) 23 | env->scene->lights->intensity = atof(line[0]); 24 | else 25 | ft_putendl_fd("ERROR! Orphan Property: intensity.", 2); 26 | } 27 | -------------------------------------------------------------------------------- /sources/scene_parser/command_define_normxyz.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* command_define_normxyz.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: cfeijoo +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2014/03/27 16:40:41 by acollin #+# #+# */ 9 | /* Updated: 2014/03/27 19:22:58 by cfeijoo ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | 20 | void cmd_define_normx(t_parser *parser, char **line) 21 | { 22 | if (parser->last_type == LAST_OBJECT) 23 | env->scene->objects->normal.x = atof(line[0]); 24 | else 25 | ft_putendl_fd("ERROR! Orphan Property: normx.", 2); 26 | } 27 | 28 | void cmd_define_normz(t_parser *parser, char **line) 29 | { 30 | if (parser->last_type == LAST_OBJECT) 31 | env->scene->objects->normal.z = atof(line[0]); 32 | else 33 | ft_putendl_fd("ERROR! Orphan Property: normz.", 2); 34 | } 35 | 36 | void cmd_define_normy(t_parser *parser, char **line) 37 | { 38 | if (parser->last_type == LAST_OBJECT) 39 | env->scene->objects->normal.y = atof(line[0]); 40 | else 41 | ft_putendl_fd("ERROR! Orphan Property: normy.", 2); 42 | } 43 | -------------------------------------------------------------------------------- /sources/scene_parser/command_define_opacity.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* command_define_opacity.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: cfeijoo +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2014/03/27 17:26:35 by acollin #+# #+# */ 9 | /* Updated: 2014/03/27 19:23:18 by cfeijoo ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | 20 | void cmd_define_opacity(t_parser *parser, char **line) 21 | { 22 | if (parser->last_type == LAST_OBJECT) 23 | env->scene->objects->opacity = atof(line[0]); 24 | else 25 | ft_putendl_fd("ERROR! Orphan Property: opacity.", 2); 26 | } 27 | -------------------------------------------------------------------------------- /sources/scene_parser/command_define_radius.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* command_define_radius.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: cfeijoo +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2014/03/27 17:15:45 by acollin #+# #+# */ 9 | /* Updated: 2014/03/27 20:47:50 by cfeijoo ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | 20 | void cmd_define_radius(t_parser *parser, char **line) 21 | { 22 | if (parser->last_type == LAST_OBJECT) 23 | { 24 | if (env->scene->objects->type == OBJ_CONE 25 | || env->scene->objects->type == OBJ_SPHERE 26 | || env->scene->objects->type == OBJ_CYLINDER) 27 | env->scene->objects->radius = atof(line[0]); 28 | } 29 | else 30 | ft_putendl_fd("ERROR! Orphan Property: radius.", 2); 31 | } 32 | -------------------------------------------------------------------------------- /sources/scene_parser/command_define_recursivity.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* command_define_recursivity.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: acollin +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2014/03/27 19:46:25 by acollin #+# #+# */ 9 | /* Updated: 2014/03/27 19:48:44 by acollin ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | 20 | void cmd_define_recursivity(t_parser *parser, char **line) 21 | { 22 | int rec; 23 | 24 | if (parser->last_type == LAST_NONE) 25 | { 26 | rec = ft_atoi(line[0]); 27 | if (rec >= 0 && rec <= 1000) 28 | env->scene->recursivity = rec; 29 | } 30 | else 31 | ft_putendl_fd("ERROR! Orphan Property: recursivity.", 2); 32 | } 33 | -------------------------------------------------------------------------------- /sources/scene_parser/command_define_reflection.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* command_define_reflection.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: cfeijoo +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2014/03/27 17:36:30 by acollin #+# #+# */ 9 | /* Updated: 2014/03/27 19:21:53 by cfeijoo ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | 20 | void cmd_define_reflection(t_parser *parser, char **line) 21 | { 22 | if (parser->last_type == LAST_OBJECT) 23 | env->scene->objects->reflection = atof(line[0]); 24 | else 25 | ft_putendl_fd("ERROR! Orphan Property: reflection.", 2); 26 | } 27 | -------------------------------------------------------------------------------- /sources/scene_parser/command_define_refraction.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* command_define_refraction.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: cfeijoo +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2014/03/27 17:42:57 by acollin #+# #+# */ 9 | /* Updated: 2014/03/27 19:21:50 by cfeijoo ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | 20 | void cmd_define_refraction(t_parser *parser, char **line) 21 | { 22 | if (parser->last_type == LAST_OBJECT) 23 | env->scene->objects->refraction = atof(line[0]); 24 | else 25 | ft_putendl_fd("ERROR! Orphan Property: refraction.", 2); 26 | } 27 | -------------------------------------------------------------------------------- /sources/scene_parser/command_define_rgb.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* command_define_rgb.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: cfeijoo +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2014/03/27 17:10:22 by acollin #+# #+# */ 9 | /* Updated: 2014/03/27 19:21:48 by cfeijoo ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | 20 | void cmd_define_red(t_parser *parser, char **line) 21 | { 22 | if (parser->last_type == LAST_LIGHT) 23 | env->scene->lights->color.red = atof(line[0]); 24 | else 25 | ft_putendl_fd("ERROR! Orphan Property: red.", 2); 26 | } 27 | 28 | void cmd_define_green(t_parser *parser, char **line) 29 | { 30 | if (parser->last_type == LAST_LIGHT) 31 | env->scene->lights->color.green = atof(line[0]); 32 | else 33 | ft_putendl_fd("ERROR! Orphan Property: green.", 2); 34 | } 35 | 36 | void cmd_define_blue(t_parser *parser, char **line) 37 | { 38 | if (parser->last_type == LAST_LIGHT) 39 | env->scene->lights->color.blue = atof(line[0]); 40 | else 41 | ft_putendl_fd("ERROR! Orphan Property: blue.", 2); 42 | } 43 | -------------------------------------------------------------------------------- /sources/scene_parser/command_define_rotxyz.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* command_define_rotxyz.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: cfeijoo +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2014/03/27 16:44:16 by acollin #+# #+# */ 9 | /* Updated: 2014/03/27 19:21:46 by cfeijoo ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | 20 | void cmd_define_rotx(t_parser *parser, char **line) 21 | { 22 | if (parser->last_type == LAST_OBJECT) 23 | env->scene->objects->rotX = atof(line[0]); 24 | else if (parser->last_type == LAST_LIGHT) 25 | env->scene->lights->direction.x = atof(line[0]); 26 | else 27 | ft_putendl_fd("ERROR! Orphan Property: rotx.", 2); 28 | } 29 | 30 | void cmd_define_rotz(t_parser *parser, char **line) 31 | { 32 | if (parser->last_type == LAST_OBJECT) 33 | env->scene->objects->rotZ = atof(line[0]); 34 | else if (parser->last_type == LAST_LIGHT) 35 | env->scene->lights->direction.z = atof(line[0]); 36 | else 37 | ft_putendl_fd("ERROR! Orphan Property: rotz.", 2); 38 | } 39 | 40 | void cmd_define_roty(t_parser *parser, char **line) 41 | { 42 | if (parser->last_type == LAST_OBJECT) 43 | env->scene->objects->rotY = atof(line[0]); 44 | else if (parser->last_type == LAST_LIGHT) 45 | env->scene->lights->direction.y= atof(line[0]); 46 | else 47 | ft_putendl_fd("ERROR! Orphan Property: roty.", 2); 48 | } 49 | -------------------------------------------------------------------------------- /sources/scene_parser/command_define_specular.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* command_define_specular.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: cfeijoo +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2014/03/27 17:32:16 by acollin #+# #+# */ 9 | /* Updated: 2014/03/27 19:22:25 by cfeijoo ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | 20 | void cmd_define_specular(t_parser *parser, char **line) 21 | { 22 | if (parser->last_type == LAST_OBJECT) 23 | env->scene->objects->specular = atof(line[0]); 24 | else 25 | ft_putendl_fd("ERROR! Orphan Property: specular.", 2); 26 | } 27 | -------------------------------------------------------------------------------- /sources/scene_parser/command_define_width.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* command_define_width.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: acollin +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2014/03/27 19:35:06 by acollin #+# #+# */ 9 | /* Updated: 2014/03/27 19:41:13 by acollin ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | 20 | void cmd_define_width(t_parser *parser, char **line) 21 | { 22 | if (parser->last_type == LAST_NONE) 23 | env->scene->view_width = (unsigned int)ft_atoi(line[0]); 24 | else 25 | ft_putendl_fd("ERROR! Orphan Property: width.", 2); 26 | } 27 | --------------------------------------------------------------------------------