kimath/geometry: starting with SHAPE_COMPOUND
This commit is contained in:
parent
abe6ccf97e
commit
b03044d3d1
|
@ -16,6 +16,7 @@ set( KIMATH_SRCS
|
||||||
src/geometry/shape_line_chain.cpp
|
src/geometry/shape_line_chain.cpp
|
||||||
src/geometry/shape_poly_set.cpp
|
src/geometry/shape_poly_set.cpp
|
||||||
src/geometry/shape_rect.cpp
|
src/geometry/shape_rect.cpp
|
||||||
|
src/geometry/shape_compound.cpp
|
||||||
|
|
||||||
src/math/util.cpp
|
src/math/util.cpp
|
||||||
)
|
)
|
||||||
|
|
|
@ -0,0 +1,100 @@
|
||||||
|
/*
|
||||||
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
||||||
|
*
|
||||||
|
* Copyright (C) 2016-2020 CERN
|
||||||
|
*
|
||||||
|
* 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
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __SHAPE_COMPOUND_H
|
||||||
|
#define __SHAPE_COMPOUND_H
|
||||||
|
|
||||||
|
#include <geometry/shape.h>
|
||||||
|
#include <math/vector2d.h>
|
||||||
|
#include <math/box2.h>
|
||||||
|
#include <list>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
class SHAPE_COMPOUND : public SHAPE
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
SHAPE_COMPOUND() :
|
||||||
|
SHAPE( SH_COMPOUND ),
|
||||||
|
m_dirty( true )
|
||||||
|
{}
|
||||||
|
|
||||||
|
|
||||||
|
SHAPE_COMPOUND( const std::vector<SHAPE*>& aShapes );
|
||||||
|
|
||||||
|
SHAPE_COMPOUND( const SHAPE_COMPOUND& aOther );
|
||||||
|
~SHAPE_COMPOUND();
|
||||||
|
|
||||||
|
SHAPE_COMPOUND* Clone() const override;
|
||||||
|
const std::string Format() const override;
|
||||||
|
|
||||||
|
bool Collide( const SEG& aSeg, int aClearance = 0, int* aActual = nullptr ) const override;
|
||||||
|
|
||||||
|
bool Collide( const SHAPE* aShape, int aClearance, VECTOR2I* aMTV ) const override
|
||||||
|
{
|
||||||
|
return SHAPE::Collide( aShape, aClearance, aMTV );
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Collide( const SHAPE* aShape, int aClearance = 0, int* aActual = nullptr ) const override
|
||||||
|
{
|
||||||
|
return SHAPE::Collide( aShape, aClearance, aActual );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
const std::vector<SHAPE*>& Shapes() const
|
||||||
|
{
|
||||||
|
return m_shapes;
|
||||||
|
}
|
||||||
|
|
||||||
|
const BOX2I BBox( int aClearance = 0 ) const override;
|
||||||
|
|
||||||
|
int Distance( const SEG& aSeg ) const;
|
||||||
|
|
||||||
|
void Move ( const VECTOR2I& aVector ) override
|
||||||
|
{
|
||||||
|
for( auto& item : m_shapes )
|
||||||
|
item->Move( aVector );
|
||||||
|
}
|
||||||
|
|
||||||
|
void AddShape( SHAPE* aShape )
|
||||||
|
{
|
||||||
|
m_shapes.push_back( aShape );
|
||||||
|
m_dirty = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Empty() const
|
||||||
|
{
|
||||||
|
return m_shapes.empty();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Rotate( double aAngle, const VECTOR2I& aCenter = { 0, 0 } ) override;
|
||||||
|
|
||||||
|
bool IsSolid() const override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
BOX2I m_cachedBBox;
|
||||||
|
bool m_dirty;
|
||||||
|
std::vector<SHAPE*> m_shapes;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // __SHAPE_COMPOUND_H
|
|
@ -447,6 +447,9 @@ inline bool CollCaseReversed ( const SHAPE* aA, const SHAPE* aB, int aClearance,
|
||||||
|
|
||||||
bool collideShapes( const SHAPE* aA, const SHAPE* aB, int aClearance, int* aActual, VECTOR2I* aMTV )
|
bool collideShapes( const SHAPE* aA, const SHAPE* aB, int aClearance, int* aActual, VECTOR2I* aMTV )
|
||||||
{
|
{
|
||||||
|
//if( aA->Type() == SH_COMPOUND )
|
||||||
|
|
||||||
|
|
||||||
switch( aA->Type() )
|
switch( aA->Type() )
|
||||||
{
|
{
|
||||||
case SH_RECT:
|
case SH_RECT:
|
||||||
|
|
|
@ -0,0 +1,105 @@
|
||||||
|
/*
|
||||||
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
||||||
|
*
|
||||||
|
* Copyright (C) 2020 KiCad Developers
|
||||||
|
* @author Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
|
||||||
|
*
|
||||||
|
* 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
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <sstream>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
#include <geometry/shape_compound.h>
|
||||||
|
|
||||||
|
const std::string SHAPE_COMPOUND::Format() const
|
||||||
|
{
|
||||||
|
std::stringstream ss;
|
||||||
|
|
||||||
|
ss << "compound";
|
||||||
|
|
||||||
|
// fixme: implement
|
||||||
|
|
||||||
|
return ss.str();
|
||||||
|
}
|
||||||
|
|
||||||
|
SHAPE_COMPOUND::SHAPE_COMPOUND( const std::vector<SHAPE*>& aShapes ) :
|
||||||
|
SHAPE( SH_COMPOUND ),
|
||||||
|
m_dirty( true ),
|
||||||
|
m_shapes( aShapes )
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
SHAPE_COMPOUND::SHAPE_COMPOUND( const SHAPE_COMPOUND& aOther )
|
||||||
|
: SHAPE( SH_COMPOUND )
|
||||||
|
{
|
||||||
|
for ( auto shape : aOther.Shapes() )
|
||||||
|
m_shapes.push_back( shape->Clone() );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
SHAPE_COMPOUND::~SHAPE_COMPOUND()
|
||||||
|
{
|
||||||
|
for( auto shape : m_shapes )
|
||||||
|
delete shape;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
SHAPE_COMPOUND* SHAPE_COMPOUND::Clone() const
|
||||||
|
{
|
||||||
|
return new SHAPE_COMPOUND( *this );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
const BOX2I SHAPE_COMPOUND::BBox( int aClearance ) const
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int SHAPE_COMPOUND::Distance( const SEG& aSeg ) const
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void SHAPE_COMPOUND::Rotate( double aAngle, const VECTOR2I& aCenter )
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool SHAPE_COMPOUND::IsSolid() const
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool SHAPE_COMPOUND::Collide( const SEG& aSeg, int aClearance, int* aActual ) const
|
||||||
|
{
|
||||||
|
for( auto& item : m_shapes )
|
||||||
|
{
|
||||||
|
if( item->Collide( aSeg, aClearance ) )
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
Loading…
Reference in New Issue