Help to reverse dividend quadrant surface

hi everyone
I need help to reverse the quad level in this script, actually away from the curve should be a smaller division

 private void RunScript(Surface S, List<Curve> C, int i, ref object A)
  {

    if (S != null && C != null && i > 0){
      List <Surface> Srf = new List<Surface>();
      subSrf(S, ref C, ref Srf, i);
      A = Srf;
    }

  }

  //  
 
  void subSrf(Surface S, ref List<Curve> C, ref List <Surface> Srf, int nGen){
    double tol = doc.ModelAbsoluteTolerance;
    bool inters = false; // check if intersection happened
    if (nGen > 0){
      //loop through curves
      foreach(Curve Cr in C){
        Rhino.Geometry.Intersect.CurveIntersections intEvent = Rhino.Geometry.Intersect.Intersection.CurveSurface(Cr, S, tol, tol);
        //Print(intEvent.Count.ToString());
        if (intEvent.Count > 0){
          inters = true;
          break;
        }
      }
      if (inters && nGen >= 1){ // if intersection happened and nGens>=1 (last loop)
        // divide surface
        //Surface[] Ss = sTrim(ref S);
        Surface[] Ss = sDiv(ref S); // this seems a tad faster
        // loop through surfaces
        foreach (Surface Sdiv in Ss){
          // call recursive subsurf
          subSrf(Sdiv, ref C, ref Srf, nGen - 1);
        }
      }else { // if no intersections event occurred then add surface to list
        Srf.Add(S);
      } // if nGen =0 (last iteration) add surface to the list
    }else {
      Srf.Add(S);
    }
  }

  // quad subdivision of a surface (split by domain)
  Surface[] sDiv(ref Surface S){
    Surface[] Ss = new Surface[4];
    Surface[] Sa = S.Split(0, S.Domain(0).Mid);
    for(int i = 0; i < Sa.Length; i++){
      Surface[] Sb = Sa[i].Split(1, Sa[i].Domain(1).Mid);
      for (int j = 0; j < Sb.Length; j++){
        Ss[i * Sa.Length + j] = Sb[j];
      }
    }
    return Ss;
  }

  // quad subdivision of a surface (trim by domain)
  Surface[] sTrim(ref Surface S){
    Surface[] Ss = new Surface[4];
    Interval u0 = new Interval(S.Domain(0).Min, S.Domain(0).Mid);
    Interval u1 = new Interval(S.Domain(0).Mid, S.Domain(0).Max);
    Interval v0 = new Interval(S.Domain(1).Min, S.Domain(1).Mid);
    Interval v1 = new Interval(S.Domain(1).Mid, S.Domain(1).Max);
    Ss[0] = S.Trim(u0, v0);
    Ss[1] = S.Trim(u0, v1);
    Ss[2] = S.Trim(u1, v0);
    Ss[3] = S.Trim(u1, v1);

    return Ss;
  }

@Mahdiyar
@laurent_delrieu

I have a “similar” C# - written for entirely different purposes. Does a Classic Recursive subDiv (according push/pull mode … etc etc) using a seed Rectangle3d.

Thus the thing requires some lines more in order to work against a BrepFace/Surface (or Lists of these)).



Notify if you want to attempt to modify that one .