/*****************************************************************************
* Conversion routines from curvesand surfaces to polygons and polylines.     *
*									     *
* Written by:  Gershon Elber				Ver 1.0, Apr 1992    *
*****************************************************************************/

#include "irit_sm.h"
#include "iritprsr.h"
#include "allocate.h"
#include "ffcnvrt.h"
#include "ip_cnvrt.h"

/*****************************************************************************
* Routine to convert a curve into a polyline with SamplesPerCurve samples.   *
*****************************************************************************/
IPPolygonStruct *Curve2Polylines(CagdCrvStruct *Crv, int DrawCurve,
				 int DrawCtlPoly, int SamplesPerCurve)
{
    IPPolygonStruct *Poly,
	*PolyHead = DrawCurve ? IritCurve2Polylines(Crv, SamplesPerCurve)
			      : NULL;

    if (DrawCtlPoly) {
	Poly = IritCurve2CtlPoly(Crv);
	Poly -> Pnext = PolyHead;
	PolyHead = Poly;
    }

    return PolyHead;
}

/*****************************************************************************
* Routine to convert a single surface into a polylines with SamplesPerCurve  *
* samples, NumOfIsolines isolines into a polyline object list.		     *
*****************************************************************************/
IPPolygonStruct *Surface2Polylines(CagdSrfStruct *Srf,
				   int DrawSurface, int DrawMesh,
				   int NumOfIsolines[2], int SamplesPerCurve)
{
    IPPolygonStruct *Poly, *PolyTemp,
	*PolyHead = DrawSurface ?
	    IritSurface2Polylines(Srf, NumOfIsolines, SamplesPerCurve) :
	    NULL;

    if (DrawMesh) {
	Poly = PolyTemp = IritSurface2CtlMesh(Srf);
	if (PolyTemp) {
	    while (PolyTemp -> Pnext)
		PolyTemp = PolyTemp -> Pnext;
	    PolyTemp -> Pnext = PolyHead;
	    PolyHead = Poly;
	}
    }

    return PolyHead;
}
