SHAPE_POLY_SET: allow constructing/adding/iterating with POLYGON

This commit is contained in:
Alex Shvartzkop 2023-07-29 10:11:33 +05:00
parent 712d61d2c1
commit 6d624ac1ff
2 changed files with 29 additions and 2 deletions

View File

@ -2,7 +2,7 @@
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2015-2019 CERN
* Copyright (C) 2021-2022 KiCad Developers, see AUTHORS.txt for contributors.
* Copyright (C) 2021-2023 KiCad Developers, see AUTHORS.txt for contributors.
*
* @author Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
* @author Alejandro García Montoro <alejandro.garciamontoro@gmail.com>
@ -486,6 +486,13 @@ public:
*/
SHAPE_POLY_SET( const SHAPE_LINE_CHAIN& aOutline );
/**
* Construct a SHAPE_POLY_SET with the first polygon given by aPolygon.
*
* @param aPolygon is a polygon
*/
SHAPE_POLY_SET( const POLYGON& aPolygon );
/**
* Copy constructor SHAPE_POLY_SET
* Performs a deep copy of \p aOther into \p this.
@ -561,6 +568,9 @@ public:
/// Adds a new hole to the given outline (default: last) and returns its index
int AddHole( const SHAPE_LINE_CHAIN& aHole, int aOutline = -1 );
/// Adds a polygon to the set
int AddPolygon( const POLYGON& apolygon );
/// Return the area of this poly set
double Area();
@ -743,6 +753,8 @@ public:
return m_polys[aIndex];
}
const std::vector<POLYGON>& CPolygons() const { return m_polys; }
/**
* Return an object to iterate through the points of the polygons between \p aFirst and
* \p aLast.

View File

@ -2,7 +2,7 @@
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2015-2019 CERN
* Copyright (C) 2021-2022 KiCad Developers, see AUTHORS.txt for contributors.
* Copyright (C) 2021-2023 KiCad Developers, see AUTHORS.txt for contributors.
*
* @author Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
* @author Alejandro García Montoro <alejandro.garciamontoro@gmail.com>
@ -89,6 +89,13 @@ SHAPE_POLY_SET::SHAPE_POLY_SET( const SHAPE_LINE_CHAIN& aOutline ) :
}
SHAPE_POLY_SET::SHAPE_POLY_SET( const POLYGON& aPolygon ) :
SHAPE( SH_POLY_SET )
{
AddPolygon( aPolygon );
}
SHAPE_POLY_SET::SHAPE_POLY_SET( const SHAPE_POLY_SET& aOther ) :
SHAPE( aOther ),
m_polys( aOther.m_polys )
@ -556,6 +563,14 @@ int SHAPE_POLY_SET::AddHole( const SHAPE_LINE_CHAIN& aHole, int aOutline )
}
int SHAPE_POLY_SET::AddPolygon( const POLYGON& apolygon )
{
m_polys.push_back( apolygon );
return m_polys.size() - 1;
}
double SHAPE_POLY_SET::Area()
{
double area = 0.0;