Quantcast
Channel: Grasshopper Developer - McNeel Forum
Viewing all articles
Browse latest Browse all 3658

Got invalid PolyLines after compiling in vs which work in the c# component

$
0
0

@Baris wrote:

Hi,

as in the title described the problem is strange.
I copy the code from the c# component and compile it and it outputs invalid polylines when the division number is uneven:

 private void RunScript(Surface S, int U, int V, ref object A)
  {

    var pLines = new List<Polyline>();



    double uStep = 1.0 / U;
    double vStep = 1.0 / V;

    Point3d ptA;
    Point3d ptB;
    Point3d ptC;
    Point3d ptD;




    S.SetDomain(0, new Interval(0, 1));
    S.SetDomain(1, new Interval(0, 1));

    for (int i = 0; i < U + 1; i++)
    {
      for (int j = 0; j < V + 1; j++)
      {



        if ((i + j) % 2 == 1)
        {
          var pts = new List<Point3d>();
          if (i > 0)
          {
            ptA = S.PointAt((i - 1) * uStep, j * vStep);
            pts.Add(ptA);
          }
          else
          {
            ptA = S.PointAt(i * uStep, j * vStep);
            pts.Add(ptA);
          }


          if (j > 0)
          {
            ptB = S.PointAt(i * uStep, (j - 1) * vStep);
            pts.Add(ptB);
          }

          else
          {
            ptB = S.PointAt(i * uStep, j * vStep);
            pts.Add(ptB);
          }


          if (i < U)
          {
            ptC = S.PointAt((i + 1) * uStep, j * vStep);
            pts.Add(ptC);
          }

          else
          {
            ptC = S.PointAt(i * uStep, j * vStep);
            pts.Add(ptC);
          }



          if (j <= V - 1)
          {
            ptD = S.PointAt(i * uStep, (j + 1) * vStep);
            pts.Add(ptD);
          }

          else
          {
            ptD = S.PointAt(i * uStep, j * vStep);
            pts.Add(ptD);
          }

          pts.Add(ptA);


          pLines.Add(new Polyline(pts));

        }

      }

    }
    A = pLines;
  }

here the vs file:CrvDiamondComponent.cs (5.5 KB)
Thanks for aclaration!

Posts: 12

Participants: 4

Read full topic


Viewing all articles
Browse latest Browse all 3658

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>