]> git.tdb.fi Git - libs/math.git/blob - source/geometry/surfacepoint.h
Properly sort intersection points for complex shapes
[libs/math.git] / source / geometry / surfacepoint.h
1 #ifndef MSP_GEOMETRY_SURFACEPOINT_H_
2 #define MSP_GEOMETRY_SURFACEPOINT_H_
3
4 #include <algorithm>
5 #include <msp/linal/vector.h>
6
7 namespace Msp {
8 namespace Geometry {
9
10 /**
11 A point on the surface of a shape.
12 */
13 template<typename T, unsigned N>
14 struct SurfacePoint
15 {
16         LinAl::Vector<T, N> position;
17         LinAl::Vector<T, N> normal;
18         T distance;
19 };
20
21 template<typename T, unsigned N>
22 void sort_points(SurfacePoint<T, N> *points, unsigned size)
23 {
24         for(unsigned i=0; i<size; ++i)
25         {
26                 unsigned n = i;
27                 for(unsigned j=i+1; j<size; ++j)
28                         if(points[j].distance<points[n].distance)
29                                 n = j;
30                 if(n!=i)
31                         std::swap(points[i], points[n]);
32         }
33 }
34
35 } // namespace Geometry
36 } // namespace Msp
37
38 #endif