KiCad PCB EDA Suite
Loading...
Searching...
No Matches
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 <[email protected]>
5 * Copyright (C) 1992-2021 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
34class BOARD_ITEM;
35
37{
38 MISSES,
41};
42
43
45{
47 CSG,
48 POLYGON,
51 RING,
56 MAX
57};
58
59
61{
62public:
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
109protected:
113
115};
116
117
118
120{
121public:
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
138 {
139 if( !s_instance )
141
142 return *s_instance;
143 }
144
145private:
150
151 unsigned int m_counter[static_cast<int>( OBJECT_2D_TYPE::MAX )];
152
154};
155
156#endif // _OBJECT_2D_H_
2D bounding box class definition.
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition: board_item.h:79
void AddOne(OBJECT_2D_TYPE aObjType)
Definition: object_2d.h:132
static OBJECT_2D_STATS * s_instance
Definition: object_2d.h:153
unsigned int GetCountOf(OBJECT_2D_TYPE aObjType) const
Definition: object_2d.h:127
unsigned int m_counter[static_cast< int >(OBJECT_2D_TYPE::MAX)]
Definition: object_2d.h:151
static OBJECT_2D_STATS & Instance()
Definition: object_2d.h:137
OBJECT_2D_STATS(const OBJECT_2D_STATS &old)
void ResetStats()
Definition: object_2d.h:122
const OBJECT_2D_STATS & operator=(const OBJECT_2D_STATS &old)
virtual bool Intersects(const BBOX_2D &aBBox) const =0
a.Intersects(b) ⇔ !a.Disjoint(b) ⇔ !(a ∩ b = ∅)
BBOX_2D m_bbox
Definition: object_2d.h:110
const SFVEC2F & GetCentroid() const
Definition: object_2d.h:105
virtual INTERSECTION_RESULT IsBBoxInside(const BBOX_2D &aBBox) const =0
Test this object if it's completely outside, intersects, or is completely inside aBBox.
virtual bool Overlaps(const BBOX_2D &aBBox) const =0
Test if the box overlaps the object.
const BBOX_2D & GetBBox() const
Definition: object_2d.h:103
virtual bool Intersect(const RAYSEG2D &aSegRay, float *aOutT, SFVEC2F *aNormalOut) const =0
OBJECT_2D_TYPE m_obj_type
Definition: object_2d.h:112
virtual ~OBJECT_2D()
Definition: object_2d.h:64
const BOARD_ITEM & m_boardItem
Definition: object_2d.h:114
SFVEC2F m_centroid
Definition: object_2d.h:111
const BOARD_ITEM & GetBoardItem() const
Definition: object_2d.h:66
OBJECT_2D_TYPE GetObjectType() const
Definition: object_2d.h:107
virtual bool IsPointInside(const SFVEC2F &aPoint) const =0
OBJECT_2D_TYPE
Definition: object_2d.h:45
INTERSECTION_RESULT
Definition: object_2d.h:37
Manage a bounding box defined by two SFVEC2F min max points.
Definition: bbox_2d.h:42
Definition: ray.h:106
glm::vec2 SFVEC2F
Definition: xv3d_types.h:42