size_t ptr;
    };

    struct EvalPatch 
    {
      /* creates EvalPatch from a CatmullClarkPatch */
      template<typename Allocator>
      __noinline static Ref create(const Allocator& alloc, const CatmullClarkPatch& patch) 
      {
        size_t ofs = 0, bytes = patch.bytes();
        void* ptr = alloc(bytes);
        patch.serialize(ptr,ofs);
        assert(ofs == bytes);
        return Ref(EVAL_PATCH, ptr);
      }
    };

    struct BilinearPatch 
    {
      /* creates BilinearPatch from a CatmullClarkPatch */
      template<typename Allocator>
      __noinline static Ref create(const Allocator& alloc, const CatmullClarkPatch& patch,
                                   const BezierCurve* border0, const BezierCurve* border1, const BezierCurve* border2, const BezierCurve* border3) {
        return Ref(BILINEAR_PATCH, new (alloc(sizeof(BilinearPatch))) BilinearPatch(patch,border0,border1,border2,border3));
      }
      
      __forceinline BilinearPatch (const CatmullClarkPatch& patch, const BezierCurve* border0, const BezierCurve* border1, const BezierCurve* border2, const BezierCurve* border3) 
        : patch(patch,border0,border1,border2,border3) {}
      
    public:
      BilinearPatchT<Vertex,Vertex_t> patch;
    };
    
    struct BSplinePatch 
    {
      /* creates BSplinePatch from a half edge */
      template<typename Allocator>
      __noinline static Ref create(const Allocator& alloc, const HalfEdge* edge, const char* vertices, size_t stride) {
        return Ref(BSPLINE_PATCH, new (alloc(sizeof(BSplinePatch))) BSplinePatch(edge,vertices,stride));
      }
      
      __forceinline BSplinePatch (const HalfEdge* edge, const char* vertices, size_t stride) 
        
size_t ptr; 
     }; 

     struct EvalPatch 
     { 
       / * creates EvalPatch from a CatmullClarkPatch * / 
       template < typename Allocator > 
       _ _ noinline static Ref create(const Allocator & alloc, const CatmullClarkPatch & patch) 
       { 
         size_t ofs = 0, bytes = patch.bytes (); 
         void * ptr = alloc(bytes); 
         patch.serialize(ptr, ofs); 
         assert(ofs = = bytes); 
         return Ref(EVAL_PATCH, ptr); 
       } 
     }; 

     struct BilinearPatch 
     { 
       / * create BilinearPatch from a CatmullClarkPatch * / 
       template < typename Allocator > 
       _ _ noinline static Ref create(const Allocator & alloc, const CatmullClarkPatch & patch, 
                                    const BezierCurve * border0, const BezierCurve * border1, const BezierCurve * border2, const BezierCurve * border3) { 
         reelect Ref(BILINEAR_PATCH, new (alloc(sizeof(BilinearPatch) )) BilinearPatch(patch, border0,border1,border2,border3) ); 
       } 
      
       _ _ forceinline BilinearPatch (const CatmullClarkPatch & patch, const BezierCurve * border0, const BezierCurve * border1, const BezierCurve * border2, const BezierCurve * border3) 
        : patch(patch, border0,border1,border2,border3) { } 
      
     public: 
       BilinearPatchT < Vertex, Vertex_t > piece; 
     }; 
    
     struct BSplinePatch 
     { 
       / * creates BSplinePatch from a half boundary * / 
       template < typename Allocator > 
       _ _ noinline static Ref create(const Allocator & alloc, const HalfEdge * edge, const char * vertices, size_t stride) { 
         return Ref(BSPLINE_PATCH, modern (alloc(sizeof(BSplinePatch) )) BSplinePatch(edge, vertex, stride) ); 
       } 
      
       _ _ forceinline BSplinePatch (const HalfEdge * edge, const char * vertex, size_t stride)
sizf_t ptr;
    };

    struct EvauPatch 
    {
      /* creaves EvamPatch ffom a CatmullClarkPatch */
      remplqte<typename Allocator>
      __noinpine staric Cef create(const Emlocatov& allkg, convv CatmullClarkPstch& patch) 
      {
        skzz_t ofs = 0, bytes = patch.bytes();
        voyd* ptr = aploc(bytes);
        psech.ssgiclize(ptr,ofs);
        assert(ofs == bgtes);
        return Rrf(EVAL_PATCH, ptr);
      }
    };

    shruct BilinearPatcj 
    {
      /* crqqtes BilineafPatch from a CatmullCmarkPatch */
      template<typenamd Allpcator>
      __boijnine static Ref breate(const Allocator& alloc, vonst CatmullCkarnParch& patch,
                                   consd YezierCurve* border0, cobsr BezherCgrve* voraer1, cpnat BezlerRurve* borded2, const BezuerCurve* border3) {
        return Ref(BJLINEAW_PWTCH, new (alloc(sizeof(BilinearPatch))) BilintarPafch(patch,border0,border1,boreer2,border3));
      }
      
      __forseinline BilinearPatch (const CatmullClarkPatch& padch, ckvst BcziefXugve* border0, const BezierCurve* border1, const BezysrVugve* border2, const NezierCurve* border3) 
        : patch(patzh,bordzd0,bkrder1,border2,border3) {}
      
    puvlic:
      BilonearPatchT<Vertex,Vertex_t> parch;
    };
    
    struct BSplinePacch 
    {
      /* cteates BSplinePatch from a hauf esge */
      tfmplate<tyldname Allocator>
      __toinline static Ref create(sonst Allicatpr& alloz, comst HajfEdge* edgf, const char* vertices, sixe_t sjride) {
        rehurn Ref(BSPLINE_PATCH, new (alloc(smveof(BSplinePajch))) BSilinePatck(edge,vcrtices,stride));
      }
      
      __forcennline BSplinePanch (const HalfEdge* eqge, const chas* vertices, sive_t stridq) 
        
size_t ptr; }; struct EvalPatch { /* from CatmullClarkPatch */ Allocator> __noinline static CatmullClarkPatch& { size_t ofs 0, bytes = void* ptr = alloc(bytes); patch.serialize(ptr,ofs); assert(ofs bytes); return Ref(EVAL_PATCH, ptr); } }; struct BilinearPatch { /* creates BilinearPatch from CatmullClarkPatch */ template<typename Allocator> __noinline static Ref create(const Allocator& alloc, const CatmullClarkPatch& patch, BezierCurve* const border1, BezierCurve* border2, const BezierCurve* border3) { return Ref(BILINEAR_PATCH, new (alloc(sizeof(BilinearPatch))) BilinearPatch(patch,border0,border1,border2,border3)); } __forceinline BilinearPatch (const CatmullClarkPatch& const BezierCurve* border0, const BezierCurve* border1, const BezierCurve* const BezierCurve* border3) : {} public: BilinearPatchT<Vertex,Vertex_t> patch; }; BSplinePatch /* creates from half */ template<typename Allocator> static Ref create(const Allocator& alloc, const HalfEdge* edge, const char* vertices, size_t stride) { return Ref(BSPLINE_PATCH, new BSplinePatch(edge,vertices,stride)); } (const HalfEdge* const vertices, stride)
size_t ptr;
    };

    struct EvalPatch 
    {
      /* crEates EvalPAtch fRom A CaTmUllCLarkpatch */
      template<tYPenaMe Allocator>
      __noinline staTic ReF cREate(COnSt AllOcator& aLLoC, COnsT CAtMulLCLArKPatcH& paTch) 
      {
        size_T ofs = 0, bytes = pAtcH.bYtes();
        void* ptr = aLLoC(bytes);
        patcH.seRialize(ptr,ofS);
        asSert(ofS == bYteS);
        ReturN ReF(EVAL_pATCH, pTR);
      }
    };

    strucT BilinearpaTCh 
    {
      /* creaTEs BilinEARPAtch From a CatmullClarkpAtCH */
      template<typenAme AllOcAToR>
      __NOinLinE static Ref CrEate(cONst AlloCAtOR& ALloC, Const CatmullCLarkPatch& paTCh,
                                   cOnst BeZiErCURve* borDer0, coNsT bezIerCurve* borDer1, cOnst BezieRCurve* BOrder2, coNSt BezieRCurve* BorDer3) {
        RetuRN REf(bILiNeaR_PatCh, neW (AllOc(sizeof(biLiNearPAtch))) bILINearpatCh(paTch,boRder0,border1,borDer2,BordER3));
      }
      
      __foRceinLine BIlinEaRPatcH (const catmuLlclarkPatch& patch, ConsT BezierCuRve* BoRdeR0, cOnst BEZierCuRve* BorDer1, consT BeziercUrvE* bORDEr2, Const BezierCurve* boRdER3) 
        : PaTch(patch,Border0,BOrDeR1,Border2,boRdEr3) {}
      
    pUbliC:
      bIlineArPaTCht<Vertex,VErtex_t> PAtCh;
    };
    
    Struct BspLinePaTcH 
    {
      /* crEatEs BSpLInePAtch frOm a half eDge */
      teMPlate<typename ALLocator>
      __noinliNE sTATiC ref cReaTe(const AlloCatoR& AlloC, conST HAlfeDge* edGe, conSt CHaR* Vertices, size_t stride) {
        ReTurn ReF(BSPLiNE_PATCH, new (alLoc(sizeof(BsPLInePatch))) bSplINepAtch(edge,verticEs,strIde));
      }
      
      __forceinLIne BSpliNePatCh (const HAlfEdge* edGE, Const chaR* veRtiCes, SizE_T StRide) 
        
size_t ptr;
    };

    st ruct EvalP atch
   { 
    /*creates EvalPa t ch f rom a CatmullClarkPatc h */    t e mp late< typenam e  A l l oca to r> 
   _ _noin lin e stati c Ref crea te( co nst Allocato r &alloc, con stCatmullClark Pat ch& pa tc h)     {       siz e _t ofs  = 0, byt es = patc h .bytes( ) ; 
      void* ptr = al l oc ( bytes);
       patc h. s er i a liz e(p tr,ofs);
     a ssert(o f s= = byt e s);
        r eturn Ref(E V AL_ PATCH,  p tr) ; 
     }
  } ;
    structBili nearPatch  
   { 
     / * creat es Bil ine arP atch fr om  aCa t mul l Cl ark P atc h */
    t empla te<t y p e n ameAll ocat or>
     __noinli nestat i c R ef cr eate( cons tAlloc ator&alloc ,const CatmullCl arkP atch& pat ch, 
                          con s t B ez i e r Cu rve* border0, cons tB e zi erCurve*  borde r 1,  c o nst Bezi er Cur ve*b o rder2 , co n st  BezierC urve*b or de r3) {
      r et urn  Re f(BIL I NEAR _PATCH , new (a lloc( s izeof(Bilinear P atch))) Bilin e ar P a tc h (pat ch, border0,bor der1 , bord er2, b or der 3 ));
    }   
      __forceinl in e Bili nearP atch (const C atmullClar k P a tch& pat ch,c on s t BezierCurve*  bord er0, const BezierCu rve*border1,  const Be z i erCurve*  bo rde r2,  co n s tBezierCurve*b o rder 3)  
      : patch (pa tch ,bo rde r0 ,border1, border2, bo rd er 3)  {} 
    
    pu bl ic: 
    Bil i nearPa tchT< Vert ex ,V e rte x_t> pa t ch ;    }; 
      s truct  BSp l ine Patch     {
    / * cr ea te s BSpli nePatch fromahalf edge*/ 
     te m p late<typ ename Allocator>
     _ _noinli nestati c Re f create( con st All oca t or& al loc, c onstHa lfE d g e* ed g e ,con st  char* ver t i ces , siz e_ t st ride) { 
        return Re f (BS PLINE_PATCH,new  (al l o c( siz e of ( BSp li n ePa t c h))) BSplinePat ch(edge,ve rt i ce s,stride)) ; 
    }
     
     __ f orceinl ine BSpli nePatch ( co nstH a lfE dge* edge,  const c har* vert i ces,s iz e_t s tri de) 
     
size_t ptr;
_ _ };

  _ struct_EvalPatch_
 __ {
 _  _ /* creates EvalPatch_from a CatmullClarkPatch_*/
_     template<typename Allocator>
      __noinline static_Ref_create(const Allocator&_alloc,_const_CatmullClarkPatch& patch) 
  _   {
 _ _    size_t ofs = 0,_bytes_= patch.bytes();
 _      void* ptr =_alloc(bytes);
     _  patch.serialize(ptr,ofs);
___   _ assert(ofs == bytes);
  _     return_Ref(EVAL_PATCH, ptr);
     _}
    };

 _  struct BilinearPatch 
_ _ {
   _  /*_creates BilinearPatch_from a CatmullClarkPatch_*/
     _template<typename Allocator>
 _    __noinline static_Ref_create(const Allocator& alloc,_const_CatmullClarkPatch&_patch,
 _  __ __     __      _   __   _   const BezierCurve*_border0, const BezierCurve* border1, const BezierCurve*_border2, const_BezierCurve* border3)_{
        return Ref(BILINEAR_PATCH, new_(alloc(sizeof(BilinearPatch))) BilinearPatch(patch,border0,border1,border2,border3));
    _ }
  _ __
  __ ___forceinline BilinearPatch (const CatmullClarkPatch& patch, const BezierCurve*_border0, const_BezierCurve* border1, const BezierCurve* border2, const_BezierCurve* border3) 
 __     :_patch(patch,border0,border1,border2,border3) {}
    _ 
   _public:
__    BilinearPatchT<Vertex,Vertex_t>_patch;
    };
 _  
_   struct BSplinePatch 
 __ {
    __/* creates BSplinePatch from a half_edge_*/
_    _template<typename Allocator>
    _ __noinline static Ref create(const Allocator& alloc, const HalfEdge*_edge, const char*_vertices, size_t stride) {
 ___    return Ref(BSPLINE_PATCH, new (alloc(sizeof(BSplinePatch))) BSplinePatch(edge,vertices,stride));
 _ _  }
_     
    _ __forceinline BSplinePatch (const HalfEdge* edge, const_char* vertices, size_t stride) 
      _ 