Author Topic: Point3dcollection to Point3d[]  (Read 3531 times)

0 Members and 1 Guest are viewing this topic.

BillZndl

  • Guest
Point3dcollection to Point3d[]
« on: January 12, 2011, 07:00:59 AM »
Newbie question. net2.0 VS2008

To get the stretch points of a solid3d, you have to use a point3dcollection.
But my program needs to return a Point3d[] array.

Code: [Select]
Point3dCollection pts = new Point3dCollection();
                    ent.GetStretchPoints(pts);

Point3d[] PntLst = ???

What's the most efficient way to put the points from the collection to the array.

I seem to remember looking into this before and ended up iterating the collection, adding to the array one at a time.
Which doesn't seem like the best method for this.

TIA



gile

  • Gator
  • Posts: 2520
  • Marseille, France
Re: Point3dcollection to Point3d[]
« Reply #1 on: January 12, 2011, 07:10:21 AM »
Hi

Code: [Select]
Point3d[] PntLst = new Point3d[pts.Count];
pts.CopyTo(PnLst, 0);
Speaking English as a French Frog

BillZndl

  • Guest
Re: Point3dcollection to Point3d[]
« Reply #2 on: January 12, 2011, 08:17:17 AM »
Hi

Code: [Select]
Point3d[] PntLst = new Point3d[pts.Count];
pts.CopyTo(PnLst, 0);

Ah, I was so close.  :-)

Thanks gile!

kaefer

  • Guest
Re: Point3dcollection to Point3d[]
« Reply #3 on: January 15, 2011, 09:54:22 AM »
Hi

Code: [Select]
Point3d[] PntLst = new Point3d[pts.Count];
pts.CopyTo(PnLst, 0);

Not bad. Interestingly, it's not clearcut that this is always the fastest way. Good old one-by-one ranks in the top too.
Code: [Select]
           Foo[] fooArray = new Foo[fooCollection.Count];
            for(int i=0;i<foo.Count;i++) fooArray[i]=fooCollection[i];

And if an untyped array were sufficient, construction via ArrayList could steal the show.
Code: [Select]
           object[] objArray = (new System.Collections.ArrayList(fooCollection)).ToArray();
From cursory timing it would appear that System.Collections.ICollection.CopyTo performs best with bigger data.
« Last Edit: January 16, 2011, 03:26:45 AM by kaefer »

BillZndl

  • Guest
Re: Point3dcollection to Point3d[]
« Reply #4 on: January 15, 2011, 11:29:26 AM »
Hi

Code: [Select]
Point3d[] PntLst = new Point3d[pts.Count];
pts.CopyTo(PnLst, 0);

Not bad. Interestingly, it's not clearcut that this is always the fastest way. Good old one-by-one ranks in the top too.
Code: [Select]
            Foo fooArray = new Foo[fooCollection.Count];
            for(int i=0;i<foo.Count;i++) fooArray[i]=fooCollection[i];

And if an untyped array were sufficient, construction via ArrayList could steal the show.
Code: [Select]
            object[] objArray = (new System.Collections.ArrayList(fooCollection)).ToArray();
From cursory timing it would appear that System.Collections.ICollection.CopyTo performs best with bigger data.

Thanks kaefer.

In another part of my program, I was collecting points of subentities of a polyline,
so during the loop I used List<Point3d> lst.AddRange to collect all the points before adding them to
the final array. PntLst = lst.ToArray();
This worked with the GetSamplePoints() method.
Don't know why some methods return a Point3d[] and some a Point3dCollection(), if it even matters
but List<> is another way to handle points so I thought I'd mention it.