1 /*
2 Copyright (C) 2010-2014 Kristian Duske
3
4 This file is part of TrenchBroom.
5
6 TrenchBroom 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 3 of the License, or
9 (at your option) any later version.
10
11 TrenchBroom 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 TrenchBroom. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20 #ifndef Polyhedron_Intersect_h
21 #define Polyhedron_Intersect_h
22
23 template <typename T, typename FP, typename VP>
intersect(const Polyhedron & other)24 Polyhedron<T,FP,VP> Polyhedron<T,FP,VP>::intersect(const Polyhedron& other) const {
25 Callback c;
26 return intersect(other, c);
27 }
28
29 template <typename T, typename FP, typename VP>
intersect(Polyhedron other,const Callback & callback)30 Polyhedron<T,FP,VP> Polyhedron<T,FP,VP>::intersect(Polyhedron other, const Callback& callback) const {
31 const Face* firstFace = m_faces.front();
32 const Face* currentFace = firstFace;
33 do {
34 const Plane<T,3> plane = callback.plane(currentFace);
35 const ClipResult result = other.clip(plane);
36 if (result.empty())
37 return Polyhedron();
38 currentFace = currentFace->next();
39 } while (currentFace != firstFace);
40 return other;
41 }
42
43 #endif /* Polyhedron_Intersect_h */
44