next up previous contents index
Next: Set of planar curves Up: Planar curve Previous: Related file (external) types   Contents   Index


Functions Summary

The following is a description of all the functions related to the Curve type. The list is in alphabetical order.

$ \bigcirc$Name


mw_change_curve - Define the curve structure, if not defined




$ \bigcirc$Summary


Curve mw_change_curve(curve)

Curve curve;




$ \bigcirc$Description


This function returns a Curve structure if the input curve = NULL. It is provided despite the mw_new_curve function for global coherence with other memory types.

The function mw_change_curve returns NULL if not enough memory is available to allocate the structure. Your code should check this return value to send an error message in the NULL case, and do appropriate statement.

Since the MegaWave2 compiler allocates structures for input and output objects (See Volume one: ``MegaWave2 User's Guide''), this function is normally used only for internal objects. Do not forget to deallocate the internal curve structures before the end of the module, except if they are part of an input or output chain.




$ \bigcirc$Example

/* Define a curve with 10 points which is the straight line (0,0)-(9,9) */

Curve curve=NULL; /* Internal use: no Input neither Output of module */
Point_curve newp,oldp=NULL;
int i;

curve = mw_change_curve(curve);
if (curve == NULL) mwerror(FATAL,1,"Not enough memory.\n");
...
(End of this example as for the mw_new_curve function).

$ \bigcirc$Name


mw_copy_curve - Copy a curve into another one




$ \bigcirc$Summary


Curve mw_copy_curve(in,out)

Curve in, out;




$ \bigcirc$Description


This function duplicates the points contained in in. The result is put in out, which may not be a predefined structure : in case of out=NULL, the out structure is allocated.

The function mw_copy_curve returns NULL if not enough memory is available to perform the copy, or out elsewhere. Your code should check this return value to send an error message in the NULL case, and do appropriate statement.




$ \bigcirc$Example

Curve in; /* Predefined curve */
Curve out=NULL; 

out=mw_copy_curve(in,out);
if (!out) mwerror(FATAL,1,"Not enough memory.\n");

$ \bigcirc$Name


mw_delete_curve - Deallocate a curve




$ \bigcirc$Summary


void mw_delete_curve(curve)

Curve curve;




$ \bigcirc$Description


This function deallocates all the memory allocated by the curve variable that is, all the points belonging to this chain and the Curvestructure itself. You should set curve = NULL after this call since the address pointed by curve is no longer valid.




$ \bigcirc$Example

/* Remove the first curve of an existing curve set (curves) */

Curves curves;/* Existing curve set (e.g. Input of module) */
Curve curve;  /* Internal use */

curve = curves->first;
curves->first=curves->next;
curves->next->previous = NULL;
mw_delete_curve(curve);
curve = NULL;

$ \bigcirc$Name


mw_length_curve - Return the number of points of a curve




$ \bigcirc$Summary


unsigned int mw_length_curve(cv);

Curve cv;




$ \bigcirc$Description


This function return the number of points contained in the given curve cv. It returns 0 if the structure is empty.




$ \bigcirc$Example

Curve curve; /* Internal use: no Input neither Output of module */
Point_curve newp,oldp=NULL;
int i;

curve = mw_new_curve();
if (curve == NULL) mwerror(FATAL,1,"Not enough memory.\n");

/* Define a curve with 5 points */
for (i=1;i<=5;i++)
{
 newp = mw_new_point_curve();
 if (newp == NULL) mwerror(FATAL,1,"Not enough memory.\n");
 if (i=0) curve->first = newp;
 newp->x = newp->y = i;
 newp->previous = oldp;
 if (oldp) oldp->next = newp;
 oldp=newp;
} 

/* The length is 5 */
printf("Length=%d\n",mw_length_curve(curve));
$ \bigcirc$Name


mw_new_curve - Create a new curve




$ \bigcirc$Summary


Curve mw_new_curve();




$ \bigcirc$Description


This function creates a new Curvestructure. It returns NULL if not enough memory is available to create the structure. Your code should check this value to send an error message in the NULL case, and do appropriate statement.

Since the MegaWave2 compiler allocates structures for input and output objects (See Volume one: ``MegaWave2 User's Guide''), this function is normally used only for internal objects. Do not forget to deallocate the internal structures before the end of the module, except if they are part of an input or output chain.




$ \bigcirc$Example

/* Define a curve with 10 points which is the straight line (0,0)-(9,9) */

Curve curve; /* Internal use: no Input neither Output of module */
Point_curve newp,oldp=NULL;
int i;

curve = mw_new_curve();
if (curve == NULL) mwerror(FATAL,1,"Not enough memory.\n");

for (i=0;i<10;i++)
{
 newp = mw_new_point_curve();
 if (newp == NULL) mwerror(FATAL,1,"Not enough memory.\n");
 if (i=0) curve->first = newp;
 newp->x = newp->y = i;
 newp->previous = oldp;
 if (oldp) oldp->next = newp;
 oldp=newp;
}


next up previous contents index
Next: Set of planar curves Up: Planar curve Previous: Related file (external) types   Contents   Index
mw 2004-05-05