// A structure to subdivide two intersecting patches about their intersection.
struct split
{
surface[] S={new surface};
surface[] T={new surface};
struct tree {
tree[] tree=new tree[2];
}
// Default subdivision depth.
int n=20;
// Subdivide p and q to depth n if they overlap.
void write(tree pt, tree qt, triple[][] p, triple[][] q, int depth=n) {
--depth;
triple[][][] Split(triple[][] P, real u=0)=depth % 2 == 0 ? hsplit : vsplit;
triple[][][] P=Split(p);
triple[][][] Q=Split(q);
// Output the subpatches of p from subdivision.
void read(surface[] S, tree t, triple[][] p, int depth=n) {
--depth;
triple[][][] Split(triple[][] P, real u=0)=depth % 2 == 0 ? hsplit : vsplit;
triple[][][] P=Split(p);