2015-12-08 07:31:57 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2016-07-19 17:35:25 +00:00
|
|
|
* Copyright (C) 2015-2016 Mario Luzeiro <mrluzeiro@ua.pt>
|
2021-05-03 20:07:16 +00:00
|
|
|
* Copyright (C) 1992-2021 KiCad Developers, see AUTHORS.txt for contributors.
|
2015-12-08 07:31:57 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, you may find one here:
|
|
|
|
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
|
|
|
* or you may search the http://www.gnu.org website for the version 2 license,
|
|
|
|
* or you may write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2021-01-03 22:23:00 +00:00
|
|
|
* @file object_2d.h
|
2015-12-08 07:31:57 +00:00
|
|
|
*/
|
|
|
|
|
2021-01-02 21:05:29 +00:00
|
|
|
#ifndef _OBJECT_2D_H_
|
|
|
|
#define _OBJECT_2D_H_
|
2015-12-08 07:31:57 +00:00
|
|
|
|
2021-01-03 22:23:00 +00:00
|
|
|
#include "bbox_2d.h"
|
2015-12-08 07:31:57 +00:00
|
|
|
|
2021-01-05 22:19:00 +00:00
|
|
|
class BOARD_ITEM;
|
2015-12-08 07:31:57 +00:00
|
|
|
|
2019-12-30 13:01:06 +00:00
|
|
|
enum class INTERSECTION_RESULT
|
2015-12-08 07:31:57 +00:00
|
|
|
{
|
2019-12-30 13:01:06 +00:00
|
|
|
MISSES,
|
|
|
|
INTERSECTS,
|
|
|
|
FULL_INSIDE
|
2015-12-08 07:31:57 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2021-01-02 21:05:29 +00:00
|
|
|
enum class OBJECT_2D_TYPE
|
2015-12-08 07:31:57 +00:00
|
|
|
{
|
2019-12-30 13:01:06 +00:00
|
|
|
FILLED_CIRCLE,
|
|
|
|
CSG,
|
|
|
|
POLYGON,
|
|
|
|
DUMMYBLOCK,
|
|
|
|
POLYGON4PT,
|
|
|
|
RING,
|
|
|
|
ROUNDSEG,
|
|
|
|
TRIANGLE,
|
|
|
|
CONTAINER,
|
|
|
|
BVHCONTAINER,
|
|
|
|
MAX
|
2015-12-08 07:31:57 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2021-01-02 21:05:29 +00:00
|
|
|
class OBJECT_2D
|
2015-12-08 07:31:57 +00:00
|
|
|
{
|
|
|
|
public:
|
2021-01-02 21:05:29 +00:00
|
|
|
OBJECT_2D( OBJECT_2D_TYPE aObjType, const BOARD_ITEM& aBoardItem );
|
|
|
|
virtual ~OBJECT_2D() {}
|
2015-12-08 07:31:57 +00:00
|
|
|
|
2021-01-02 21:05:29 +00:00
|
|
|
const BOARD_ITEM& GetBoardItem() const { return m_boardItem; }
|
2015-12-08 07:31:57 +00:00
|
|
|
|
2020-12-11 13:51:42 +00:00
|
|
|
/**
|
|
|
|
* Test if the box overlaps the object.
|
|
|
|
*
|
2015-12-08 07:31:57 +00:00
|
|
|
* Conformance
|
2020-12-11 13:51:42 +00:00
|
|
|
* Implements the Overlaps function from the OGC Simple Feature Specification at
|
|
|
|
* http://www.opengeospatial.org/standards/sfa.
|
2015-12-08 07:31:57 +00:00
|
|
|
* a.Overlaps(b) ⇔ ( dim(I(a)) = dim(I(b)) = dim(I(a) ∩ I(b))) ∧ (a ∩ b ≠ a) ∧ (a ∩ b ≠ b)
|
2020-12-11 13:51:42 +00:00
|
|
|
* It means that the result dimension of an overlap is the same dimensions
|
2016-07-19 17:35:25 +00:00
|
|
|
* of the bounding box (so the overlap cannot be a point or a line) and one
|
|
|
|
* of the boxes cannot full contain the other box.
|
2020-12-11 13:51:42 +00:00
|
|
|
*
|
2021-01-02 21:05:29 +00:00
|
|
|
* @param aBBox is the bounding box to test.
|
|
|
|
* @return true if the BBox intersects the object or is inside it.
|
2015-12-08 07:31:57 +00:00
|
|
|
*/
|
2021-01-02 21:05:29 +00:00
|
|
|
virtual bool Overlaps( const BBOX_2D& aBBox ) const = 0;
|
2015-12-08 07:31:57 +00:00
|
|
|
|
2020-12-11 13:51:42 +00:00
|
|
|
/**
|
|
|
|
* a.Intersects(b) ⇔ !a.Disjoint(b) ⇔ !(a ∩ b = ∅)
|
2015-12-08 07:31:57 +00:00
|
|
|
*/
|
2021-01-02 21:05:29 +00:00
|
|
|
virtual bool Intersects( const BBOX_2D& aBBox ) const = 0;
|
2015-12-08 07:31:57 +00:00
|
|
|
|
2020-12-11 13:51:42 +00:00
|
|
|
/**
|
2021-01-02 21:05:29 +00:00
|
|
|
* @param aOutT a value between 0.0 and 1.0 in relation to the time of the hit of the segment.
|
2015-12-08 07:31:57 +00:00
|
|
|
*/
|
2021-01-02 21:05:29 +00:00
|
|
|
virtual bool Intersect( const RAYSEG2D& aSegRay, float* aOutT, SFVEC2F* aNormalOut ) const = 0;
|
2015-12-08 07:31:57 +00:00
|
|
|
|
2019-08-20 17:22:30 +00:00
|
|
|
/**
|
2020-12-11 13:51:42 +00:00
|
|
|
* Test this object if it's completely outside, intersects, or is completely inside \a aBBox.
|
|
|
|
*
|
2015-12-08 07:31:57 +00:00
|
|
|
* @return INTERSECTION_RESULT
|
|
|
|
*/
|
2021-01-02 21:05:29 +00:00
|
|
|
virtual INTERSECTION_RESULT IsBBoxInside( const BBOX_2D& aBBox ) const = 0;
|
2015-12-08 07:31:57 +00:00
|
|
|
|
2021-01-02 21:05:29 +00:00
|
|
|
virtual bool IsPointInside( const SFVEC2F& aPoint ) const = 0;
|
2015-12-08 07:31:57 +00:00
|
|
|
|
2021-01-02 21:05:29 +00:00
|
|
|
const BBOX_2D& GetBBox() const { return m_bbox; }
|
2015-12-08 07:31:57 +00:00
|
|
|
|
2021-01-02 21:05:29 +00:00
|
|
|
const SFVEC2F& GetCentroid() const { return m_centroid; }
|
2015-12-08 07:31:57 +00:00
|
|
|
|
2021-01-02 21:05:29 +00:00
|
|
|
OBJECT_2D_TYPE GetObjectType() const { return m_obj_type; }
|
2020-12-11 13:51:42 +00:00
|
|
|
|
|
|
|
protected:
|
2021-01-02 21:05:29 +00:00
|
|
|
BBOX_2D m_bbox;
|
2020-12-11 13:51:42 +00:00
|
|
|
SFVEC2F m_centroid;
|
2021-01-02 21:05:29 +00:00
|
|
|
OBJECT_2D_TYPE m_obj_type;
|
2020-12-11 13:51:42 +00:00
|
|
|
|
2021-01-02 21:05:29 +00:00
|
|
|
const BOARD_ITEM& m_boardItem;
|
2015-12-08 07:31:57 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
2021-01-02 21:05:29 +00:00
|
|
|
class OBJECT_2D_STATS
|
2015-12-08 07:31:57 +00:00
|
|
|
{
|
|
|
|
public:
|
2019-12-30 13:01:06 +00:00
|
|
|
void ResetStats()
|
|
|
|
{
|
2021-01-02 21:05:29 +00:00
|
|
|
memset( m_counter, 0, sizeof( unsigned int ) * static_cast<int>( OBJECT_2D_TYPE::MAX ) );
|
2019-12-30 13:01:06 +00:00
|
|
|
}
|
2015-12-08 07:31:57 +00:00
|
|
|
|
2021-01-02 21:05:29 +00:00
|
|
|
unsigned int GetCountOf( OBJECT_2D_TYPE aObjType ) const
|
2016-07-19 17:35:25 +00:00
|
|
|
{
|
2019-12-30 13:01:06 +00:00
|
|
|
return m_counter[static_cast<int>( aObjType )];
|
2016-07-19 17:35:25 +00:00
|
|
|
}
|
2015-12-08 07:31:57 +00:00
|
|
|
|
2021-01-02 21:05:29 +00:00
|
|
|
void AddOne( OBJECT_2D_TYPE aObjType )
|
2019-12-30 13:01:06 +00:00
|
|
|
{
|
|
|
|
m_counter[static_cast<int>( aObjType )]++;
|
|
|
|
}
|
2015-12-08 07:31:57 +00:00
|
|
|
|
2021-01-02 21:05:29 +00:00
|
|
|
static OBJECT_2D_STATS& Instance()
|
2015-12-08 07:31:57 +00:00
|
|
|
{
|
|
|
|
if( !s_instance )
|
2021-01-02 21:05:29 +00:00
|
|
|
s_instance = new OBJECT_2D_STATS;
|
2015-12-08 07:31:57 +00:00
|
|
|
|
|
|
|
return *s_instance;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2021-01-02 21:05:29 +00:00
|
|
|
OBJECT_2D_STATS(){ ResetStats(); }
|
|
|
|
OBJECT_2D_STATS( const OBJECT_2D_STATS& old );
|
|
|
|
const OBJECT_2D_STATS& operator=( const OBJECT_2D_STATS& old );
|
|
|
|
~OBJECT_2D_STATS(){}
|
2015-12-08 07:31:57 +00:00
|
|
|
|
2021-01-02 21:05:29 +00:00
|
|
|
unsigned int m_counter[static_cast<int>( OBJECT_2D_TYPE::MAX )];
|
2015-12-08 07:31:57 +00:00
|
|
|
|
2021-01-02 21:05:29 +00:00
|
|
|
static OBJECT_2D_STATS* s_instance;
|
2015-12-08 07:31:57 +00:00
|
|
|
};
|
|
|
|
|
2021-01-02 21:05:29 +00:00
|
|
|
#endif // _OBJECT_2D_H_
|