Added the Solid 3.5 sources to the blender source tree.
[blender.git] / extern / solid / src / broad / BP_EndpointList.h
1 /*
2  * SOLID - Software Library for Interference Detection
3  * 
4  * Copyright (C) 2001-2003  Dtecta.  All rights reserved.
5  *
6  * This library may be distributed under the terms of the Q Public License
7  * (QPL) as defined by Trolltech AS of Norway and appearing in the file
8  * LICENSE.QPL included in the packaging of this file.
9  *
10  * This library may be distributed and/or modified under the terms of the
11  * GNU General Public License (GPL) version 2 as published by the Free Software
12  * Foundation and appearing in the file LICENSE.GPL included in the
13  * packaging of this file.
14  *
15  * This library is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
16  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
17  *
18  * Commercial use or any other use of this library not covered by either 
19  * the QPL or the GPL requires an additional license from Dtecta. 
20  * Please contact info@dtecta.com for enquiries about the terms of commercial
21  * use of this library.
22  */
23
24 #ifndef BP_ENDPOINTLIST_H
25 #define BP_ENDPOINTLIST_H
26
27 //#define PARANOID
28
29 #include <vector>
30
31 #include "BP_Endpoint.h"
32 #include "BP_ProxyList.h"
33
34 class BP_Scene;
35
36 typedef bool (*T_Overlap)(const BP_Proxy& a, const BP_Proxy& b);
37
38 class BP_EndpointList : public std::vector<BP_Endpoint> {
39 public:
40         BP_EndpointList() {}
41         
42         DT_Index stab(const BP_Endpoint& pos, BP_ProxyList& proxies) const;
43         
44         DT_Index stab(DT_Scalar pos, BP_ProxyList& proxies) const
45         {
46                 return stab(BP_Endpoint(pos, BP_Endpoint::MINIMUM, 0), proxies);
47         }
48         
49
50    void range(const BP_Endpoint& min, const BP_Endpoint& max, 
51                           DT_Index& first, DT_Index& last, BP_ProxyList& proxies) const;
52         
53         void range(DT_Scalar lb, DT_Scalar ub, DT_Index& first, DT_Index& last, BP_ProxyList& proxies) const 
54         {
55                 range(BP_Endpoint(lb, BP_Endpoint::MINIMUM, 0), 
56                           BP_Endpoint(ub, BP_Endpoint::MAXIMUM, 0),
57                           first, last, proxies);
58         }
59         
60         void addInterval(const BP_Endpoint& min, const BP_Endpoint& max, BP_ProxyList& proxies);
61         void removeInterval(DT_Index first, DT_Index last, BP_ProxyList& proxies);
62
63         void move(DT_Index index, DT_Scalar pos, Uint32 type, BP_Scene& scene, T_Overlap overlap);      
64    
65    DT_Scalar nextLambda(DT_Index& index, DT_Scalar source, DT_Scalar target) const;
66         
67
68 private:
69         void encounters(const BP_Endpoint& a, const BP_Endpoint& b,
70                                             BP_Scene& scene, T_Overlap overlap);
71
72
73 #ifdef PARANOID
74         bool invariant() const 
75         {
76                 DT_Count count = 0;
77                 DT_Index i;
78                 for (i = 0; i != size(); ++i) 
79                 {
80          const BP_Endpoint& endpoint = (*this)[i];
81
82                         if (endpoint.getType() == BP_Endpoint::MINIMUM) 
83                         {
84                                 ++count;
85                         }
86                         else 
87                         {
88                                 --count;
89                         }
90                         if (endpoint.getCount() != count)
91                         {
92                                 return false;
93                         }
94                         if (endpoint.getIndex() != i) 
95                         {
96                                 return false;
97                         }
98                 }
99                 return true;
100         }
101 #else
102         bool invariant() const { return true; }
103 #endif
104
105 };
106
107
108
109 #endif