//========================================================================================
// E3D
//
// Parametric Faces
//
// AUTHOR:  Gabor Nagy
// DATE:    2025-Dec-14 18:07:36
//
// Copyright (C) 1996-2026 by Gabor Nagy. All rights reserved.
//========================================================================================
#ifndef _E3D_Face_h
#define _E3D_Face_h

#ifndef _E3D_VertexGeometry_h
#include <E3D/VertexGeometry.h>
#endif

#ifndef _E3D_Spline_h
#include <E3D/Spline.h>
#endif

#ifndef _E3D_Polygon_h
//#include <E3D/Polygon.h>
#endif


#if defined (__cplusplus) && (!(defined (__CPLUSLIBS)))
extern "C" {
#endif


#ifndef E3dPolygon_DEF
#define E3dPolygon_DEF  1
typedef struct E3dPolygon_S   E3dPolygon;
EListA_t(E3dPolygon);
typedef struct E3dPolygon_S*  E3dPolygonPtr;
EListA_t(E3dPolygonPtr);
#endif

#ifndef E3dPolyGroup_DEF
#define E3dPolyGroup_DEF
typedef struct E3dPolyGroup_S   E3dPolyGroup;
typedef struct E3dPolyGroup_S*  E3dPolyGroupPtr;
EList_t(E3dPolyGroupPtr);
#endif

typedef struct
{
	E3dVertexGeometryCore;

// E3dFace part
//
	E3dSpline*               Exterior;  // Exterior contour
	EList(, E3dSpline*, Holes);         // Array of E3dSpline pointers defining holes


// For drawing the Face
//
	E3dCoord3                Normal;

// We use a PolyGroup to draw the Face.
// Also, tools that create Faces, can create Polygons within the Face, to help tesselation.
// For example, a gear profile may have each tooth split into rectangles.
// This is also where we keep the Material and the TextureMappers for the Face.
//
	E3dPolyGroup*            PolyGroup;
} E3dFace, *E3dFacePtr;
EListA_t(E3dFacePtr);


//------------------------------------------------------------------------
// Patch (Bezier, BSpline, NURBS etc.)
//------------------------------------------------------------------------
typedef struct
{
// E3dGeometry part
//
	E3dGeometryCore;


// E3dPatch part
//
	int             PatchType;
	unsigned int    Degree;
	E3dSpline**     Sides;    // Patch sides
	EIndex          NumOfSides;
} E3dPatch;


extern E3dObjectClass  E3dFace_class[];

//--------------------------------------------------------
// Function prototypes
//--------------------------------------------------------

extern void        E3dFace_FreeTesselation(E3dFace* PFace);
extern void        E3dFace_FreeContents(E3dFace* PFace);
extern void        E3dFace_SetExterior(E3dFace* PFace, E3dSpline* PExterior);
extern void        E3dFace_AppendHole(E3dFace* PFace, E3dSpline* PHole);
extern void        E3dFace_InsertHole(E3dFace* PFace, E3dSpline* PHole, const EIndex PWhere);
extern void        E3dFace_RemoveHole(E3dFace* PFace, E3dSpline* PHole);

extern EIndex      E3dFace_ConvertToPolygons(E3dFace* PFace, const E3dVertexNodeSize PDstVertexNodeSize, const E3dVertexIndex PVertexOffset, const EBool PCreateTriangles, const EBool PInverse,  E3dPolygon* PPolygons);

extern EIndex      E3dFace_CreateVertices(E3dFace* PFace);
extern int         E3dFace_Tesselate(E3dFace* PFace);
extern E3dCoord2*  E3dFace_Flatten(E3dFace* PFace);

extern EIndex      E3dFace_TextureMappingUpdate(E3dFace* PFace, const EBool PUpdateSTs);
extern EBool       E3dFace_GetBoundingBox(E3dFace* PFace, const uint32_t PWhatToInclude,  E3dBBox* PBBox);


#if defined (__cplusplus) && (!(defined (__CPLUSLIBS)))
}	// Close scope of 'extern "C"' declaration
#endif

#endif	// _E3D_Face_h
