INFO607
Functions
points.c File Reference
#include <assert.h>
#include <stdlib.h>
#include "points.h"

Go to the source code of this file.

Functions

void TabPoints_init (TabPoints *tab)
 
void TabPoints_ajoute (TabPoints *tab, Point p)
 
void TabPoints_set (TabPoints *tab, int i, Point p)
 
Point TabPoints_get (TabPoints *tab, int i)
 
int TabPoints_nb (TabPoints *tab)
 
void TabPoints_termine (TabPoints *tab)
 

Function Documentation

◆ TabPoints_ajoute()

void TabPoints_ajoute ( TabPoints tab,
Point  p 
)

Ajoute si possible le point p à la fin du tableau de points tab.

Parameters
tabun pointeur vers une structure TabPoint valide.
pun point.

Definition at line 12 of file points.c.

13{
14 if ( tab->nb < tab->taille )
15 tab->points[ tab->nb++ ] = p;
16}
int nb
Definition points.h:11
Point * points
Definition points.h:12
int taille
Definition points.h:10

References STabPoint::nb, STabPoint::points, and STabPoint::taille.

Referenced by diskRandom().

◆ TabPoints_get()

Point TabPoints_get ( TabPoints tab,
int  i 
)
Parameters
tabun pointeur vers une structure TabPoint valide.
iun index valide (entre 0 et TabPoints_nb( tab ) )
Returns
le i-ème point du tableau de points tab.

Definition at line 24 of file points.c.

25{
26 assert ( i < tab->nb );
27 return tab->points[ i ];
28}

References STabPoint::points.

Referenced by on_draw().

◆ TabPoints_init()

void TabPoints_init ( TabPoints tab)

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

Parameters
tabun pointeur vers une structure TabPoint.

Definition at line 5 of file points.c.

6{
7 tab->taille = 100;
8 tab->nb = 0;
9 tab->points = (Point*) malloc( tab->taille * sizeof( Point ) );
10}
Definition points.h:4

References STabPoint::nb, STabPoint::points, and STabPoint::taille.

Referenced by main().

◆ TabPoints_nb()

int TabPoints_nb ( TabPoints tab)
Parameters
tabun pointeur vers une structure TabPoint valide.
Returns
le nombre de points utiles stockés dans le tableau de points tab.

Definition at line 30 of file points.c.

31{
32 return tab->nb;
33}

References STabPoint::nb.

Referenced by on_draw().

◆ TabPoints_set()

void TabPoints_set ( TabPoints tab,
int  i,
Point  p 
)

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

Parameters
tabun pointeur vers une structure TabPoint valide.
iun index valide (entre 0 et TabPoints_nb( tab ) )
pun point.

Definition at line 18 of file points.c.

19{
20 assert ( i < tab->nb );
21 tab->points[ i ] = p;
22}

References STabPoint::points.

◆ TabPoints_termine()

void TabPoints_termine ( TabPoints 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 TabPoint valide.

Definition at line 35 of file points.c.

36{
37 if ( tab->points != NULL ) free( tab->points );
38 tab->taille = 0;
39 tab->nb = 0;
40 tab->points = NULL;
41}

References STabPoint::nb, STabPoint::points, and STabPoint::taille.