diff --git a/src/Charge.h b/src/Charge.h index 4d34498571fbd3431eb6790a850a6b9f35974c4c..f2dca543315fb3caf942796274aacf3109671f59 100644 --- a/src/Charge.h +++ b/src/Charge.h @@ -17,7 +17,22 @@ typedef struct Charge { Vector2 position; } Charge; +/** + * @brief Initializes a Charge. + * + * @param q The electrical charge. + * @param position The position of the charge in the universe. + * @return Charge The charge. + */ Charge charge_init(double q, Vector2 position); + +/** + * @brief Draws the charge. + * + * @param charge The charge. + * @param graphics The graphics in which we draw. + * @param universe The universe rectangle. + */ void charge_draw(Charge charge, Graphics *graphics, Rectangle *universe); #endif diff --git a/src/Graphics.h b/src/Graphics.h index 4fde5484f5ea7d086e2bebadfe06d72487bde752..448d305013bd9d2732a49b8a8ee4df41d56f34b5 100644 --- a/src/Graphics.h +++ b/src/Graphics.h @@ -39,7 +39,24 @@ extern void gfx_destroy(struct gfx_context_t *ctxt); extern void gfx_present(struct gfx_context_t *ctxt); extern SDL_Keycode gfx_keypressed(); +/** + * @brief Draws a line. + * + * @param graphics The graphics in which we draw. + * @param p0 The point 0 of the line. + * @param p1 The point 1 of the line. + * @param color The color of the circle. + */ void gfx_draw_line(Graphics *graphics, Point p0, Point p1, uint32_t color); + +/** + * @brief Draws a circle. + * + * @param graphics The graphics in which we draw. + * @param c The point in the center of the circle. + * @param r The radius of the circle. + * @param color The color of the circle. + */ void gfx_draw_circle(Graphics *graphics, Point c, uint32_t r, uint32_t color); #endif diff --git a/src/Point.h b/src/Point.h index 698dac8d05aadd57bcdfd49e53968ee916f6b6db..083a1278b39e98edcc2b9fa4c11cf290ea2af365 100644 --- a/src/Point.h +++ b/src/Point.h @@ -16,7 +16,24 @@ typedef struct Point { int y; } Point; +/** + * @brief Initializes a Point. + * + * @param x The x component of the point. + * @param y The y component of the point. + * @return Point The point. + */ Point point_init(int x, int y); + +/** + * @brief Converts a position to a point in a rectangle of size width x height. + * + * @param position The position in the universe. + * @param universe The universe rectangle. + * @param width The width of the screen. + * @param height The height of the screen. + * @return Point The point located on the screen. + */ Point position_to_point(Vector2 position, Rectangle *universe, int width, int height); #endif diff --git a/src/Rectangle.h b/src/Rectangle.h index cda18ffd6d7e3ea27c2a240f56fa39d7a86284d5..95fecbf7038b8611647d9c9dc442e50321c42984 100644 --- a/src/Rectangle.h +++ b/src/Rectangle.h @@ -15,7 +15,22 @@ typedef struct Rectangle { Vector2 bottom_right; } Rectangle; +/** + * @brief Initializes a Rectangle. + * + * @param x0 The x-component of the point at the top left. + * @param y0 The y-component of the point at the top left. + * @param x1 The x-component of the point at the bottom right. + * @param y1 The y-component of the point at the bottom right. + * @return Rectangle* The rectangle. + */ Rectangle *rectangle_init(int x0, int y0, int x1, int y1); + +/** + * @brief Frees memory of the rectangle. + * + * @param rectangle + */ void rectangle_destroy(Rectangle **rectangle); #endif diff --git a/src/Simulation.h b/src/Simulation.h index 93870639e712c55734e0d7c3c1011318c7f80bce..05d182cb3026369482a68a698d5e9c826f7179af 100644 --- a/src/Simulation.h +++ b/src/Simulation.h @@ -19,8 +19,28 @@ typedef struct Simulation { double delta_x; } Simulation; +/** + * @brief Initializes a Simulation. + * + * @param universe The universe rectangle. + * @param delta_x The The delta x used for drawing lines. + * @return Simulation* The simulation. + */ Simulation *simulation_init(Rectangle *universe, double delta_x); + +/** + * @brief Frees memory of the simulation. + * + * @param simulation The simulation. + */ void simulation_destroy(Simulation **simulation); + +/** + * @brief Draws the simulation. + * + * @param simulation The simulation. + * @param graphics The graphics in which we draw. + */ void simulation_draw(Simulation *simulation, Graphics *graphics); #endif diff --git a/src/Vector2.h b/src/Vector2.h index 6c176887e0b8e5b13a442e4d4074c68a448cfdf3..47c8d2dfbfe61317ccce2bae3f8becc800a8fc98 100644 --- a/src/Vector2.h +++ b/src/Vector2.h @@ -13,14 +13,80 @@ typedef struct Vector2 { double y; } Vector2; +/** + * @brief Initializes a Vector2. + * + * @param x The x component of the vector. + * @param y The y component of the vector. + * @return Vector2 The vector. + */ Vector2 vector2_init(double x, double y); + +/** + * @brief Initializes a vector with the x and y component at 0. + * + * @return Vector2 The vector. + */ Vector2 vector2_init_zero(); + +/** + * @brief Adds two vectors. + * + * @param a The left vector. + * @param b The right vector. + * @return Vector2 The sum of the two vectors. + */ Vector2 vector2_add(Vector2 a, Vector2 b); + +/** + * @brief Subtracts two vectors. + * + * @param a The left vector. + * @param b The right vector. + * @return The difference of the two vectors. + */ Vector2 vector2_substract(Vector2 a, Vector2 b); + +/** + * @brief Multiplies a vector and a scalar. + * + * @param v The vector. + * @param scalar The scalar. + * @return Vector2 The result of the multiplication. + */ Vector2 vector2_multiply(Vector2 v, double scalar); + +/** + * @brief Calculates the dot product between two vectors. + * + * @param a The left vector. + * @param b The right vector. + * @return double The result of the dot product. + */ double vector2_dot_product(Vector2 a, Vector2 b); + +/** + * @brief Calculates the norm squared of the vector. + * + * @param v The vector. + * @return double The norm squared. + */ double vector2_norm_sqr(Vector2 v); + +/** + * @brief Calculates the norm of the vector. + * + * @param v The vector. + * @return double The norm. + */ double vector2_norm(Vector2 v); + +/** + * @brief Normalizes the vector. + * + * @param v The vector. + * @return Vector2 The normalized vector. + */ Vector2 vector2_normalize(Vector2 v); #endif diff --git a/src/main.c b/src/main.c index 08d71ce0a92a3a93b9827ea154970452f0bc7c22..0e872f69e7eededfb171f380ee68c9ef3be6a347 100644 --- a/src/main.c +++ b/src/main.c @@ -24,6 +24,13 @@ #define UNUSED(x) x #endif +/** + * @brief Calculates the delta x used to draw the lines. + * + * @param width The width of the screen. + * @param height The height of the screen. + * @return double The delta x. + */ double compute_delta_x(int width, int height) { return 1 / sqrt((width * width) + (height * height)); } diff --git a/src/random_number.h b/src/random_number.h index 53be23f2dc3215942af4086efba43213434ca98c..fdfca869dd7d78f710392fd68801330508895b7f 100644 --- a/src/random_number.h +++ b/src/random_number.h @@ -8,7 +8,20 @@ #ifndef RANDOM_NUMBER_H #define RANDOM_NUMBER_H +/** + * @brief Draws a random number between min and max. + * + * @param min The minimum value. + * @param max The maximum value. + * @return int The random number. + */ int random_number_between(int min, int max); + +/** + * @brief Draws a random number between 0 and 1. + * + * @return double The random number. + */ double random_number_between_0_and_1(); #endif