Esempio n. 1
0
static
Float
getMedian(const GeDynamicArray<Vector> &points, const Int32 *pnts, Int32 numPoints, Random &rng, INT axis, Sorter &sorter)
{
	Int32 maxSamples = 20;
	Int32 numSamples = numPoints < maxSamples ? numPoints : maxSamples;
	Float* samples = NewMemClear(Float,numSamples);
	for(Int32 i=0;i<numSamples;i++){
		Float val = rng.Get01();
		Int32 a = val * (numPoints-1);
		switch(axis){
			case 0:
				samples[i] = points[pnts[a]].x;
				break;
			case 1:
				samples[i] = points[pnts[a]].y;
				break;
			case 2:
				samples[i] = points[pnts[a]].z;
				break;
		}
		
	}
	sorter.Sort(samples,numSamples,sizeof(Float));
	Float ret = samples[numSamples/2];
	DeleteMem(samples);
	return ret;
}
Esempio n. 2
0
 void SortByDelta()
 {
   struct Sorter : public maxon::BaseSort<Sorter>
   {
     static inline
     Bool LessThan(const Connection& a, const Connection& b)
     {
       return a.delta < b.delta;
     }
   };
   Sorter sorter;
   sorter.Sort(Begin(), End());
 }