Skip to content
Snippets Groups Projects
Commit 6235fac5 authored by florian.burgener's avatar florian.burgener
Browse files

Add comments

parent eaa61433
Branches
No related tags found
No related merge requests found
......@@ -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
......@@ -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
......@@ -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
......@@ -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
......@@ -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
......@@ -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
......@@ -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));
}
......
......@@ -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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment