INFO607
particules.c
Go to the documentation of this file.
1#include <assert.h>
2#include <stdlib.h>
3#include <math.h>
4#include "particules.h"
5
6void initParticule( Particule* p, double x, double y, double vx, double vy,
7 double m )
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}
17
19{
20 tab->taille = 10;
21 tab->nb = 0;
22 tab->particules = (Particule*) malloc( tab->taille * sizeof( Particule ) );
23}
24
26{
27 if ( tab->nb == tab->taille )
29 tab->particules[ tab->nb++ ] = p;
30}
31
33{
34 assert ( i < tab->nb );
35 tab->particules[ i ] = p;
36}
37
39{
40 assert ( i < tab->nb );
41 return tab->particules[ i ];
42}
43
45{
46 assert ( i < tab->nb );
47 return tab->particules + i;
48}
49
51{
52 return tab->nb;
53}
54
56{
57 if ( tab->particules != NULL ) free( tab->particules );
58 tab->taille = 0;
59 tab->nb = 0;
60 tab->particules = NULL;
61}
62
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}
73
75{
76 assert( tab->nb > 0 );
77 --tab->nb;
78}
79
81{
82 assert ( i >= 0 );
83 assert ( i < tab->nb );
84 tab->particules[ i ] = tab->particules[ --tab->nb ];
85}
86
87
int TabParticules_nb(TabParticules *tab)
Definition particules.c:50
void TabParticules_agrandir(TabParticules *tab)
Definition particules.c:63
void TabParticules_set(TabParticules *tab, int i, Particule p)
Definition particules.c:32
void TabParticules_supprime_dernier(TabParticules *tab)
Definition particules.c:74
void TabParticules_termine(TabParticules *tab)
Definition particules.c:55
Particule * TabParticules_ref(TabParticules *tab, int i)
Definition particules.c:44
void TabParticules_init(TabParticules *tab)
Definition particules.c:18
void TabParticules_supprime(TabParticules *tab, int i)
Definition particules.c:80
void TabParticules_ajoute(TabParticules *tab, Particule p)
Definition particules.c:25
void initParticule(Particule *p, double x, double y, double vx, double vy, double m)
Definition particules.c:6
Particule TabParticules_get(TabParticules *tab, int i)
Definition particules.c:38
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
Représente un tableau dynamique de particules.
Definition particules.h:23
Particule * particules
Definition particules.h:26