diff --git a/libs/kimath/include/geometry/shape_poly_set.h b/libs/kimath/include/geometry/shape_poly_set.h index d372a7dbde..f8c7ad325a 100644 --- a/libs/kimath/include/geometry/shape_poly_set.h +++ b/libs/kimath/include/geometry/shape_poly_set.h @@ -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 * @author Alejandro García Montoro @@ -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& CPolygons() const { return m_polys; } + /** * Return an object to iterate through the points of the polygons between \p aFirst and * \p aLast. diff --git a/libs/kimath/src/geometry/shape_poly_set.cpp b/libs/kimath/src/geometry/shape_poly_set.cpp index 5172f74068..e5cb10e136 100644 --- a/libs/kimath/src/geometry/shape_poly_set.cpp +++ b/libs/kimath/src/geometry/shape_poly_set.cpp @@ -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 * @author Alejandro García Montoro @@ -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;