]> git.tdb.fi Git - libs/math.git/blob - source/geometry/surfacepoint.h
Adjust start_nesting in CompositeShape::get_intersections
[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         bool entry;
20 };
21
22 template<typename T, unsigned N>
23 void sort_points(SurfacePoint<T, N> *points, unsigned size)
24 {
25         for(unsigned i=0; i<size; ++i)
26         {
27                 unsigned n = i;
28                 for(unsigned j=i+1; j<size; ++j)
29                         if(points[j].distance<points[n].distance)
30                                 n = j;
31                 if(n!=i)
32                         std::swap(points[i], points[n]);
33         }
34 }
35
36 } // namespace Geometry
37 } // namespace Msp
38
39 #endif