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 #include "BoundsContainsNodeVisitor.h"
21 #include "Model/Brush.h"
22 #include "Model/Entity.h"
23 #include "Model/Group.h"
24 
25 namespace TrenchBroom {
26     namespace Model {
BoundsContainsNodeVisitor(const BBox3 & bounds)27         BoundsContainsNodeVisitor::BoundsContainsNodeVisitor(const BBox3& bounds) :
28         m_bounds(bounds) {}
29 
doVisit(const World * world)30         void BoundsContainsNodeVisitor::doVisit(const World* world)   { setResult(false); }
doVisit(const Layer * layer)31         void BoundsContainsNodeVisitor::doVisit(const Layer* layer)   { setResult(false); }
doVisit(const Group * group)32         void BoundsContainsNodeVisitor::doVisit(const Group* group)   { setResult(m_bounds.contains(group->bounds())); }
doVisit(const Entity * entity)33         void BoundsContainsNodeVisitor::doVisit(const Entity* entity) { setResult(m_bounds.contains(entity->bounds())); }
34 
doVisit(const Brush * brush)35         void BoundsContainsNodeVisitor::doVisit(const Brush* brush)   {
36             const Brush::VertexList vertices = brush->vertices();
37             Brush::VertexList::const_iterator it, end;
38             for (it = vertices.begin(), end = vertices.end(); it != end; ++it) {
39                 if (!m_bounds.contains((*it)->position())) {
40                     setResult(false);
41                     return;
42                 }
43             }
44             setResult(true);
45         }
46     }
47 }
48