INFO607
Classes | Typedefs | Functions
particules.h File Reference
#include "points.h"

Go to the source code of this file.

Classes

struct  SParticule
 
struct  STabParticule
 Représente un tableau dynamique de particules. More...
 

Typedefs

typedef struct SParticule Particule
 
typedef struct STabParticule TabParticules
 Représente un tableau dynamique de particules.
 

Functions

void initParticule (Particule *p, double x, double y, double vx, double vy, double m)
 
void TabParticules_init (TabParticules *tab)
 
void TabParticules_ajoute (TabParticules *tab, Particule p)
 
void TabParticules_set (TabParticules *tab, int i, Particule p)
 
Particule TabParticules_get (TabParticules *tab, int i)
 
ParticuleTabParticules_ref (TabParticules *tab, int i)
 
int TabParticules_nb (TabParticules *tab)
 
void TabParticules_termine (TabParticules *tab)
 
void TabParticules_agrandir (TabParticules *tab)
 
void TabParticules_supprime_dernier (TabParticules *tab)
 
void TabParticules_supprime (TabParticules *tab, int i)
 

Typedef Documentation

◆ Particule

typedef struct SParticule Particule

Représente un point / une particule en mouvement, avec position, mais aussi vitesse, force, et masse.

◆ TabParticules

typedef struct STabParticule TabParticules

Représente un tableau dynamique de particules.

Function Documentation

◆ initParticule()

void initParticule ( Particule p,
double  x,
double  y,
double  vx,
double  vy,
double  m 
)

Initialise le point p avec la position (x,y), la vitesse (vx,vy), une masse m et des forces nulles.x

Definition at line 6 of file particules.c.

8{
9 p->x[0] = x;
10 p->x[1] = y;
11 p->v[0] = vx;
12 p->v[1] = vy;
13 p->f[0] = 0.0;
14 p->f[1] = 0.0;
15 p->m = m;
16}
double x[DIM]
Definition particules.h:9
double f[DIM]
Definition particules.h:11
double v[DIM]
Definition particules.h:10
double m
Definition particules.h:12

References SParticule::f, SParticule::m, SParticule::v, and SParticule::x.

Referenced by fontaine().

◆ TabParticules_agrandir()

void TabParticules_agrandir ( TabParticules tab)

Utilisé en interne. Agrandit automatiquement le tableau si nécessaire.

Definition at line 63 of file particules.c.

64{
65 int new_taille = 2*tab->taille;
66 Particule* new_pts = (Particule*) malloc( new_taille * sizeof( Particule ) );
67 for ( int i = 0; i < tab->nb; ++i )
68 new_pts[ i ] = tab->particules[ i ];
69 free( tab->particules );
70 tab->particules = new_pts;
71 tab->taille = new_taille;
72}
Particule * particules
Definition particules.h:26

References STabParticule::nb, STabParticule::particules, and STabParticule::taille.

Referenced by TabParticules_ajoute().

◆ TabParticules_ajoute()

void TabParticules_ajoute ( TabParticules tab,
Particule  p 
)

Ajoute si possible le particule p à la fin du tableau de particules tab.

Parameters
tabun pointeur vers une structure TabParticule valide.
pune particule.

Definition at line 25 of file particules.c.

26{
27 if ( tab->nb == tab->taille )
29 tab->particules[ tab->nb++ ] = p;
30}
void TabParticules_agrandir(TabParticules *tab)
Definition particules.c:63

References STabParticule::nb, STabParticule::particules, TabParticules_agrandir(), and STabParticule::taille.

Referenced by fontaine().

◆ TabParticules_get()

Particule TabParticules_get ( TabParticules tab,
int  i 
)
Parameters
tabun pointeur vers une structure TabParticule valide.
iun index valide (entre 0 et TabParticules_nb( tab ) )
Returns
le i-ème point du tableau de points tab.

Definition at line 38 of file particules.c.

39{
40 assert ( i < tab->nb );
41 return tab->particules[ i ];
42}

References STabParticule::particules.

Referenced by on_draw().

◆ TabParticules_init()

void TabParticules_init ( TabParticules tab)

Initialise le tableau de particules tab. Il contient 0 particules initialement, mais peut accueillir jusqu'à 10 particules sans être agrandi.

Parameters
tabun pointeur vers une structure TabParticule.

Definition at line 18 of file particules.c.

19{
20 tab->taille = 10;
21 tab->nb = 0;
22 tab->particules = (Particule*) malloc( tab->taille * sizeof( Particule ) );
23}

References STabParticule::nb, STabParticule::particules, and STabParticule::taille.

Referenced by main().

◆ TabParticules_nb()

int TabParticules_nb ( TabParticules tab)
Parameters
tabun pointeur vers une structure TabParticule valide.
Returns
le nombre de points utiles stockés dans le tableau de points tab.

Definition at line 50 of file particules.c.

51{
52 return tab->nb;
53}

References STabParticule::nb.

Referenced by calculDynamique(), deplaceTout(), on_draw(), and ticAffichage().

◆ TabParticules_ref()

Particule * TabParticules_ref ( TabParticules tab,
int  i 
)
Parameters
tabun pointeur vers une structure TabParticule valide.
iun index valide (entre 0 et TabParticules_nb( tab ) )
Returns
un pointeur vers le i-ème point du tableau de points tab.

Definition at line 44 of file particules.c.

45{
46 assert ( i < tab->nb );
47 return tab->particules + i;
48}

References STabParticule::particules.

Referenced by calculDynamique(), and deplaceTout().

◆ TabParticules_set()

void TabParticules_set ( TabParticules tab,
int  i,
Particule  p 
)

Modifie le i-ème point du tableau de points tab. Il devient le point p.

Parameters
tabun pointeur vers une structure TabParticule valide.
iun index valide (entre 0 et TabParticules_nb( tab ) )
pune particule.

Definition at line 32 of file particules.c.

33{
34 assert ( i < tab->nb );
35 tab->particules[ i ] = p;
36}

References STabParticule::particules.

◆ TabParticules_supprime()

void TabParticules_supprime ( TabParticules tab,
int  i 
)

Supprime un élément en position i du tableau. Met le dernier élément du tableau à la place.

Definition at line 80 of file particules.c.

81{
82 assert ( i >= 0 );
83 assert ( i < tab->nb );
84 tab->particules[ i ] = tab->particules[ --tab->nb ];
85}

References STabParticule::nb, and STabParticule::particules.

Referenced by deplaceTout().

◆ TabParticules_supprime_dernier()

void TabParticules_supprime_dernier ( TabParticules tab)

Supprime le dernier élément du tableau.

Definition at line 74 of file particules.c.

75{
76 assert( tab->nb > 0 );
77 --tab->nb;
78}

References STabParticule::nb.

◆ TabParticules_termine()

void TabParticules_termine ( TabParticules tab)

Indique que le tableau de points tab n'est plus utilisé et libère la mémoire associée. Il passe à une taille 0.

Parameters
tabun pointeur vers une structure TabParticule valide.

Definition at line 55 of file particules.c.

56{
57 if ( tab->particules != NULL ) free( tab->particules );
58 tab->taille = 0;
59 tab->nb = 0;
60 tab->particules = NULL;
61}

References STabParticule::nb, STabParticule::particules, and STabParticule::taille.