KiCad PCB EDA Suite
ccontainer.cpp
Go to the documentation of this file.
1 /*
2  * This program source code file is part of KiCad, a free EDA CAD application.
3  *
4  * Copyright (C) 2015-2016 Mario Luzeiro <mrluzeiro@ua.pt>
5  * Copyright (C) 1992-2016 KiCad Developers, see AUTHORS.txt for contributors.
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, you may find one here:
19  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20  * or you may search the http://www.gnu.org website for the version 2 license,
21  * or you may write to the Free Software Foundation, Inc.,
22  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23  */
24 
30 #include "ccontainer.h"
31 #include <stdio.h>
32 
34 {
35  m_objects.clear();
36  m_bbox.Reset();
37 }
38 
40 {
41  if( !m_objects.empty() )
42  {
43  for( LIST_OBJECT::iterator ii = m_objects.begin();
44  ii != m_objects.end();
45  ++ii )
46  {
47  delete *ii;
48  *ii = NULL;
49  }
50 
51  m_objects.clear();
52  }
53 
54  m_bbox.Reset();
55 }
56 
57 
59 {
60  Clear();
61 }
62 
63 
65 {
66  aOutVector.resize( m_objects.size() );
67 
68  if( !m_objects.empty() )
69  {
70  unsigned int i = 0;
71 
72  for( LIST_OBJECT::const_iterator ii = m_objects.begin();
73  ii != m_objects.end();
74  ++ii )
75  {
76  wxASSERT( (*ii) != NULL );
77 
78  aOutVector[i++] = static_cast<const COBJECT *>(*ii);
79  }
80  }
81 }
82 
83 
84 bool CCONTAINER::Intersect( const RAY &aRay, HITINFO &aHitInfo ) const
85 {
86 
87  if( !m_bbox.Intersect( aRay ) )
88  return false;
89 
90  bool hitted = false;
91 
92  for( LIST_OBJECT::const_iterator ii = m_objects.begin();
93  ii != m_objects.end();
94  ++ii )
95  {
96  const COBJECT *object = static_cast<const COBJECT *>(*ii);
97 
98  if( object->Intersect( aRay, aHitInfo) )
99  hitted = true;
100  }
101 
102  return hitted;
103 }
104 
105 
106 bool CCONTAINER::IntersectP( const RAY &aRay, float aMaxDistance ) const
107 {
108 /*
109  if( !m_bbox.Inside( aRay.m_Origin ) )
110  if( !m_bbox.Intersect( aRay ) )
111  return false;
112 */
113  for( LIST_OBJECT::const_iterator ii = m_objects.begin();
114  ii != m_objects.end();
115  ++ii )
116  {
117  const COBJECT *object = static_cast<const COBJECT *>(*ii);
118 
119  if( object->IntersectP( aRay, aMaxDistance ) )
120  return true;
121  }
122 
123  return false;
124 }
std::vector< const COBJECT * > CONST_VECTOR_OBJECT
Definition: ccontainer.h:39
LIST_OBJECT m_objects
Definition: ccontainer.h:45
Definition: ray.h:43
void ConvertTo(CONST_VECTOR_OBJECT &aOutVector) const
Definition: ccontainer.cpp:64
bool IntersectP(const RAY &aRay, float aMaxDistance) const override
Definition: ccontainer.cpp:106
virtual bool IntersectP(const RAY &aRay, float aMaxDistance) const =0
Functions Intersect for shadow test.
bool Intersect(const RAY &aRay, float *t) const
Function Intersect.
Definition: cbbox_ray.cpp:46
bool Intersect(const RAY &aRay, HITINFO &aHitInfo) const override
Definition: ccontainer.cpp:84
virtual bool Intersect(const RAY &aRay, HITINFO &aHitInfo) const =0
Functions Intersect.
Stores the hit information of a ray with a point on the surface of a object.
Definition: hitinfo.h:40
virtual ~CGENERICCONTAINER()
Definition: ccontainer.cpp:58
void Reset()
Function Reset reset the bounding box to zero and de-initialized it.
Definition: cbbox.cpp:98