1 // intersect_decls.h (Declarations for "friend" intersection functions)
2 //
3 //  The WorldForge Project
4 //  Copyright (C) 2002  The WorldForge Project
5 //
6 //  This program is free software; you can redistribute it and/or modify
7 //  it under the terms of the GNU General Public License as published by
8 //  the Free Software Foundation; either version 2 of the License, or
9 //  (at your option) any later version.
10 //
11 //  This program is distributed in the hope that it will be useful,
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 //  GNU General Public License for more details.
15 //
16 //  You should have received a copy of the GNU General Public License
17 //  along with this program; if not, write to the Free Software
18 //  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 //
20 //  For information about WorldForge and its authors, please contact
21 //  the Worldforge Web Site at http://www.worldforge.org.
22 //
23 
24 // Author: Ron Steinke
25 
26 #ifndef WFMATH_INTERSECT_DECLS_H
27 #define WFMATH_INTERSECT_DECLS_H
28 
29 #include <wfmath/const.h>
30 
31 namespace WFMath {
32 
33 // Some Intersect and Contains helper functions
34 
_Less(CoordType x1,CoordType x2,bool proper)35 inline bool _Less(CoordType x1, CoordType x2, bool proper)
36 {
37   return proper ? x1 <= x2 : (x2 - x1) > numeric_constants<CoordType>::epsilon();
38 }
39 
_LessEq(CoordType x1,CoordType x2,bool proper)40 inline bool _LessEq(CoordType x1, CoordType x2, bool proper)
41 {
42   return !proper ? x1 <= x2 : x1 < x2;
43 }
44 
_Greater(CoordType x1,CoordType x2,bool proper)45 inline bool _Greater(CoordType x1, CoordType x2, bool proper)
46 {
47   return proper ? x1 >= x2 : (x1 - x2) > numeric_constants<CoordType>::epsilon();
48 }
49 
_GreaterEq(CoordType x1,CoordType x2,bool proper)50 inline bool _GreaterEq(CoordType x1, CoordType x2, bool proper)
51 {
52   return !proper ? x1 >= x2 : x1 > x2;
53 }
54 
55 template<int dim>
56 bool Intersect(const AxisBox<dim>& b, const Point<dim>& p, bool proper);
57 template<int dim>
58 bool Contains(const Point<dim>& p, const AxisBox<dim>& b, bool proper);
59 
60 template<int dim>
61 bool Intersect(const Ball<dim>& b, const Point<dim>& p, bool proper);
62 template<int dim>
63 bool Contains(const Point<dim>& p, const Ball<dim>& b, bool proper);
64 
65 template<int dim>
66 bool Intersect(const Segment<dim>& s, const Point<dim>& p, bool proper);
67 template<int dim>
68 bool Contains(const Point<dim>& p, const Segment<dim>& s, bool proper);
69 
70 template<int dim>
71 bool Intersect(const RotBox<dim>& r, const Point<dim>& p, bool proper);
72 template<int dim>
73 bool Contains(const Point<dim>& p, const RotBox<dim>& r, bool proper);
74 
75 template<int dim>
76 bool Intersect(const AxisBox<dim>& b1, const AxisBox<dim>& b2, bool proper);
77 template<int dim>
78 bool Contains(const AxisBox<dim>& outer, const AxisBox<dim>& inner, bool proper);
79 
80 template<int dim>
81 bool Intersect(const Ball<dim>& b, const AxisBox<dim>& a, bool proper);
82 template<int dim>
83 bool Contains(const Ball<dim>& b, const AxisBox<dim>& a, bool proper);
84 template<int dim>
85 bool Contains(const AxisBox<dim>& a, const Ball<dim>& b, bool proper);
86 
87 template<int dim>
88 bool Intersect(const Segment<dim>& s, const AxisBox<dim>& b, bool proper);
89 template<int dim>
90 bool Contains(const Segment<dim>& s, const AxisBox<dim>& b, bool proper);
91 template<int dim>
92 bool Contains(const AxisBox<dim>& b, const Segment<dim>& s, bool proper);
93 
94 template<int dim>
95 bool Intersect(const RotBox<dim>& r, const AxisBox<dim>& b, bool proper);
96 template<int dim>
97 bool Contains(const RotBox<dim>& r, const AxisBox<dim>& b, bool proper);
98 template<int dim>
99 bool Contains(const AxisBox<dim>& b, const RotBox<dim>& r, bool proper);
100 
101 template<int dim>
102 bool Intersect(const Ball<dim>& b1, const Ball<dim>& b2, bool proper);
103 template<int dim>
104 bool Contains(const Ball<dim>& outer, const Ball<dim>& inner, bool proper);
105 
106 template<int dim>
107 bool Intersect(const Segment<dim>& s, const Ball<dim>& b, bool proper);
108 template<int dim>
109 bool Contains(const Ball<dim>& b, const Segment<dim>& s, bool proper);
110 template<int dim>
111 bool Contains(const Segment<dim>& s, const Ball<dim>& b, bool proper);
112 
113 template<int dim>
114 bool Intersect(const RotBox<dim>& r, const Ball<dim>& b, bool proper);
115 template<int dim>
116 bool Contains(const RotBox<dim>& r, const Ball<dim>& b, bool proper);
117 template<int dim>
118 bool Contains(const Ball<dim>& b, const RotBox<dim>& r, bool proper);
119 
120 template<int dim>
121 bool Intersect(const Segment<dim>& s1, const Segment<dim>& s2, bool proper);
122 template<int dim>
123 bool Contains(const Segment<dim>& s1, const Segment<dim>& s2, bool proper);
124 
125 template<int dim>
126 bool Intersect(const RotBox<dim>& r, const Segment<dim>& s, bool proper);
127 template<int dim>
128 bool Contains(const RotBox<dim>& r, const Segment<dim>& s, bool proper);
129 template<int dim>
130 bool Contains(const Segment<dim>& s, const RotBox<dim>& r, bool proper);
131 
132 template<int dim>
133 bool Intersect(const RotBox<dim>& r1, const RotBox<dim>& r2, bool proper);
134 template<int dim>
135 bool Contains(const RotBox<dim>& outer, const RotBox<dim>& inner, bool proper);
136 
137 template<int dim>
138 bool Intersect(const Polygon<dim>& r, const Point<dim>& p, bool proper);
139 template<int dim>
140 bool Contains(const Point<dim>& p, const Polygon<dim>& r, bool proper);
141 
142 template<int dim>
143 bool Intersect(const Polygon<dim>& p, const AxisBox<dim>& b, bool proper);
144 template<int dim>
145 bool Contains(const Polygon<dim>& p, const AxisBox<dim>& b, bool proper);
146 template<int dim>
147 bool Contains(const AxisBox<dim>& b, const Polygon<dim>& p, bool proper);
148 
149 template<int dim>
150 bool Intersect(const Polygon<dim>& p, const Ball<dim>& b, bool proper);
151 template<int dim>
152 bool Contains(const Polygon<dim>& p, const Ball<dim>& b, bool proper);
153 template<int dim>
154 bool Contains(const Ball<dim>& b, const Polygon<dim>& p, bool proper);
155 
156 template<int dim>
157 bool Intersect(const Polygon<dim>& r, const Segment<dim>& s, bool proper);
158 template<int dim>
159 bool Contains(const Polygon<dim>& p, const Segment<dim>& s, bool proper);
160 template<int dim>
161 bool Contains(const Segment<dim>& s, const Polygon<dim>& p, bool proper);
162 
163 template<int dim>
164 bool Intersect(const Polygon<dim>& p, const RotBox<dim>& r, bool proper);
165 template<int dim>
166 bool Contains(const Polygon<dim>& p, const RotBox<dim>& r, bool proper);
167 template<int dim>
168 bool Contains(const RotBox<dim>& r, const Polygon<dim>& p, bool proper);
169 
170 template<int dim>
171 bool Intersect(const Polygon<dim>& p1, const Polygon<dim>& p2, bool proper);
172 template<int dim>
173 bool Contains(const Polygon<dim>& outer, const Polygon<dim>& inner, bool proper);
174 
175 } // namespace WFMath
176 
177 #endif  // WFMATH_INTERSECT_DECLS_H
178