KiCad PCB EDA Suite
object_2d.h
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-2020 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 
29 #ifndef _OBJECT_2D_H_
30 #define _OBJECT_2D_H_
31 
32 #include "bbox_2d.h"
33 
34 class BOARD_ITEM;
35 
37 {
38  MISSES,
39  INTERSECTS,
41 };
42 
43 
44 enum class OBJECT_2D_TYPE
45 {
47  CSG,
48  POLYGON,
49  DUMMYBLOCK,
50  POLYGON4PT,
51  RING,
52  ROUNDSEG,
53  TRIANGLE,
54  CONTAINER,
56  MAX
57 };
58 
59 
60 class OBJECT_2D
61 {
62 public:
63  OBJECT_2D( OBJECT_2D_TYPE aObjType, const BOARD_ITEM& aBoardItem );
64  virtual ~OBJECT_2D() {}
65 
66  const BOARD_ITEM& GetBoardItem() const { return m_boardItem; }
67 
82  virtual bool Overlaps( const BBOX_2D& aBBox ) const = 0;
83 
87  virtual bool Intersects( const BBOX_2D& aBBox ) const = 0;
88 
92  virtual bool Intersect( const RAYSEG2D& aSegRay, float* aOutT, SFVEC2F* aNormalOut ) const = 0;
93 
99  virtual INTERSECTION_RESULT IsBBoxInside( const BBOX_2D& aBBox ) const = 0;
100 
101  virtual bool IsPointInside( const SFVEC2F& aPoint ) const = 0;
102 
103  const BBOX_2D& GetBBox() const { return m_bbox; }
104 
105  const SFVEC2F& GetCentroid() const { return m_centroid; }
106 
108 
109 protected:
113 
115 };
116 
117 
118 
120 {
121 public:
122  void ResetStats()
123  {
124  memset( m_counter, 0, sizeof( unsigned int ) * static_cast<int>( OBJECT_2D_TYPE::MAX ) );
125  }
126 
127  unsigned int GetCountOf( OBJECT_2D_TYPE aObjType ) const
128  {
129  return m_counter[static_cast<int>( aObjType )];
130  }
131 
132  void AddOne( OBJECT_2D_TYPE aObjType )
133  {
134  m_counter[static_cast<int>( aObjType )]++;
135  }
136 
137  void PrintStats();
138 
140  {
141  if( !s_instance )
143 
144  return *s_instance;
145  }
146 
147 private:
149  OBJECT_2D_STATS( const OBJECT_2D_STATS& old );
150  const OBJECT_2D_STATS& operator=( const OBJECT_2D_STATS& old );
152 
153  unsigned int m_counter[static_cast<int>( OBJECT_2D_TYPE::MAX )];
154 
156 };
157 
158 #endif // _OBJECT_2D_H_
BBOX_2D m_bbox
Definition: object_2d.h:110
void PrintStats()
Definition: object_2d.cpp:64
unsigned int m_counter[static_cast< int >(OBJECT_2D_TYPE::MAX)]
Definition: object_2d.h:153
unsigned int GetCountOf(OBJECT_2D_TYPE aObjType) const
Definition: object_2d.h:127
2D bounding box class definition.
virtual INTERSECTION_RESULT IsBBoxInside(const BBOX_2D &aBBox) const =0
Test this object if it's completely outside, intersects, or is completely inside aBBox.
const SFVEC2F & GetCentroid() const
Definition: object_2d.h:105
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition: board_item.h:82
virtual ~OBJECT_2D()
Definition: object_2d.h:64
SFVEC2F m_centroid
Definition: object_2d.h:111
OBJECT_2D_TYPE m_obj_type
Definition: object_2d.h:112
const BOARD_ITEM & m_boardItem
Definition: object_2d.h:114
OBJECT_2D(OBJECT_2D_TYPE aObjType, const BOARD_ITEM &aBoardItem)
Definition: object_2d.cpp:36
glm::vec2 SFVEC2F
Definition: xv3d_types.h:42
INTERSECTION_RESULT
Definition: object_2d.h:36
const BBOX_2D & GetBBox() const
Definition: object_2d.h:103
virtual bool Overlaps(const BBOX_2D &aBBox) const =0
Test if the box overlaps the object.
static OBJECT_2D_STATS & Instance()
Definition: object_2d.h:139
const BOARD_ITEM & GetBoardItem() const
Definition: object_2d.h:66
static OBJECT_2D_STATS * s_instance
Definition: object_2d.h:155
virtual bool Intersect(const RAYSEG2D &aSegRay, float *aOutT, SFVEC2F *aNormalOut) const =0
Manage a bounding box defined by two SFVEC2F min max points.
Definition: bbox_2d.h:41
OBJECT_2D_TYPE GetObjectType() const
Definition: object_2d.h:107
void AddOne(OBJECT_2D_TYPE aObjType)
Definition: object_2d.h:132
OBJECT_2D_TYPE
Definition: object_2d.h:44
void ResetStats()
Definition: object_2d.h:122
virtual bool IsPointInside(const SFVEC2F &aPoint) const =0
virtual bool Intersects(const BBOX_2D &aBBox) const =0
a.Intersects(b) ⇔ !a.Disjoint(b) ⇔ !(a ∩ b = ∅)
const OBJECT_2D_STATS & operator=(const OBJECT_2D_STATS &old)
Definition: ray.h:110