From 6235fac509e06798ff1ab7081e92292c3c065362 Mon Sep 17 00:00:00 2001
From: Florian Burgener <florian.burgener@etu.hesge.ch>
Date: Mon, 9 May 2022 14:46:10 +0200
Subject: [PATCH] Add comments

---
 src/Charge.h        | 15 +++++++++++
 src/Graphics.h      | 17 ++++++++++++
 src/Point.h         | 17 ++++++++++++
 src/Rectangle.h     | 15 +++++++++++
 src/Simulation.h    | 20 ++++++++++++++
 src/Vector2.h       | 66 +++++++++++++++++++++++++++++++++++++++++++++
 src/main.c          |  7 +++++
 src/random_number.h | 13 +++++++++
 8 files changed, 170 insertions(+)

diff --git a/src/Charge.h b/src/Charge.h
index 4d34498..f2dca54 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 4fde548..448d305 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 698dac8..083a127 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 cda18ff..95fecbf 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 9387063..05d182c 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 6c17688..47c8d2d 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 08d71ce..0e872f6 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 53be23f..fdfca86 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
-- 
GitLab