]> git.tdb.fi Git - libs/math.git/blobdiff - source/geometry/surfacepoint.h
Add an entry flag to SharedPoint
[libs/math.git] / source / geometry / surfacepoint.h
index 251964cef854d91469f6ed9c10280534d3519535..3b38e1d2d03f6fdf5e2ee5c99ff6fbfaca633813 100644 (file)
@@ -1,6 +1,7 @@
 #ifndef MSP_GEOMETRY_SURFACEPOINT_H_
 #define MSP_GEOMETRY_SURFACEPOINT_H_
 
+#include <algorithm>
 #include <msp/linal/vector.h>
 
 namespace Msp {
@@ -14,8 +15,24 @@ struct SurfacePoint
 {
        LinAl::Vector<T, N> position;
        LinAl::Vector<T, N> normal;
+       T distance;
+       bool entry;
 };
 
+template<typename T, unsigned N>
+void sort_points(SurfacePoint<T, N> *points, unsigned size)
+{
+       for(unsigned i=0; i<size; ++i)
+       {
+               unsigned n = i;
+               for(unsigned j=i+1; j<size; ++j)
+                       if(points[j].distance<points[n].distance)
+                               n = j;
+               if(n!=i)
+                       std::swap(points[i], points[n]);
+       }
+}
+
 } // namespace Geometry
 } // namespace Msp