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 The 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, see <https://www.gnu.org/licenses/>.
19 */
20
24
25#ifndef _OBJECT_2D_H_
26#define _OBJECT_2D_H_
27
28#include "bbox_2d.h"
29
30class BOARD_ITEM;
31
38
39
54
55
57{
58public:
59 OBJECT_2D( OBJECT_2D_TYPE aObjType, const BOARD_ITEM& aBoardItem );
60 virtual ~OBJECT_2D() {}
61
62 const BOARD_ITEM& GetBoardItem() const { return m_boardItem; }
63
78 virtual bool Overlaps( const BBOX_2D& aBBox ) const = 0;
79
83 virtual bool Intersects( const BBOX_2D& aBBox ) const = 0;
84
88 virtual bool Intersect( const RAYSEG2D& aSegRay, float* aOutT, SFVEC2F* aNormalOut ) const = 0;
89
95 virtual INTERSECTION_RESULT IsBBoxInside( const BBOX_2D& aBBox ) const = 0;
96
97 virtual bool IsPointInside( const SFVEC2F& aPoint ) const = 0;
98
99 const BBOX_2D& GetBBox() const { return m_bbox; }
100
101 const SFVEC2F& GetCentroid() const { return m_centroid; }
102
104
105protected:
109
111};
112
113
114
116{
117public:
119 {
120 memset( m_counter, 0, sizeof( unsigned int ) * static_cast<int>( OBJECT_2D_TYPE::MAX ) );
121 }
122
123 unsigned int GetCountOf( OBJECT_2D_TYPE aObjType ) const
124 {
125 return m_counter[static_cast<int>( aObjType )];
126 }
127
128 void AddOne( OBJECT_2D_TYPE aObjType )
129 {
130 m_counter[static_cast<int>( aObjType )]++;
131 }
132
134 {
135 if( !s_instance )
137
138 return *s_instance;
139 }
140
141private:
146
147 unsigned int m_counter[static_cast<int>( OBJECT_2D_TYPE::MAX )];
148
150};
151
152#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:81
void AddOne(OBJECT_2D_TYPE aObjType)
Definition object_2d.h:128
static OBJECT_2D_STATS * s_instance
Definition object_2d.h:149
unsigned int GetCountOf(OBJECT_2D_TYPE aObjType) const
Definition object_2d.h:123
unsigned int m_counter[static_cast< int >(OBJECT_2D_TYPE::MAX)]
Definition object_2d.h:147
static OBJECT_2D_STATS & Instance()
Definition object_2d.h:133
OBJECT_2D_STATS(const OBJECT_2D_STATS &old)
void ResetStats()
Definition object_2d.h:118
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:106
const SFVEC2F & GetCentroid() const
Definition object_2d.h:101
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:99
virtual bool Intersect(const RAYSEG2D &aSegRay, float *aOutT, SFVEC2F *aNormalOut) const =0
OBJECT_2D_TYPE m_obj_type
Definition object_2d.h:108
virtual ~OBJECT_2D()
Definition object_2d.h:60
const BOARD_ITEM & m_boardItem
Definition object_2d.h:110
SFVEC2F m_centroid
Definition object_2d.h:107
const BOARD_ITEM & GetBoardItem() const
Definition object_2d.h:62
OBJECT_2D_TYPE GetObjectType() const
Definition object_2d.h:103
OBJECT_2D(OBJECT_2D_TYPE aObjType, const BOARD_ITEM &aBoardItem)
Definition object_2d.cpp:27
virtual bool IsPointInside(const SFVEC2F &aPoint) const =0
A triangle object.
Definition triangle_3d.h:39
@ MAX
OBJECT_2D_TYPE
Definition object_2d.h:41
INTERSECTION_RESULT
Definition object_2d.h:33
Manage a bounding box defined by two SFVEC2F min max points.
Definition bbox_2d.h:38
glm::vec2 SFVEC2F
Definition xv3d_types.h:38