2015-06-12 15:12:02 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2019-07-05 22:45:57 +00:00
|
|
|
* Copyright (C) 2015-2019 CERN
|
2022-01-20 20:54:22 +00:00
|
|
|
* Copyright (C) 2021-2022 KiCad Developers, see AUTHORS.txt for contributors.
|
2021-01-25 12:42:36 +00:00
|
|
|
*
|
2015-06-12 15:12:02 +00:00
|
|
|
* @author Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
|
2017-03-07 12:06:00 +00:00
|
|
|
* @author Alejandro García Montoro <alejandro.garciamontoro@gmail.com>
|
2015-06-12 15:12:02 +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
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __SHAPE_POLY_SET_H
|
|
|
|
#define __SHAPE_POLY_SET_H
|
|
|
|
|
|
|
|
#include <cstdio>
|
2020-01-07 17:12:59 +00:00
|
|
|
#include <deque> // for deque
|
2020-09-18 14:22:30 +00:00
|
|
|
#include <vector> // for vector
|
2020-01-07 17:12:59 +00:00
|
|
|
#include <iosfwd> // for string, stringstream
|
2017-12-08 11:20:02 +00:00
|
|
|
#include <memory>
|
2020-01-07 17:12:59 +00:00
|
|
|
#include <set> // for set
|
|
|
|
#include <stdexcept> // for out_of_range
|
|
|
|
#include <stdlib.h> // for abs
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
#include <clipper.hpp> // for ClipType, PolyTree (ptr only)
|
2022-10-19 23:25:45 +00:00
|
|
|
#include <clipper2/clipper.h>
|
2020-01-07 17:12:59 +00:00
|
|
|
#include <geometry/seg.h> // for SEG
|
2015-06-12 15:12:02 +00:00
|
|
|
#include <geometry/shape.h>
|
|
|
|
#include <geometry/shape_line_chain.h>
|
2020-01-07 17:12:59 +00:00
|
|
|
#include <math/box2.h> // for BOX2I
|
|
|
|
#include <math/vector2d.h> // for VECTOR2I
|
2017-11-23 16:20:27 +00:00
|
|
|
#include <md5_hash.h>
|
|
|
|
|
2015-07-27 19:45:57 +00:00
|
|
|
|
2015-06-12 15:12:02 +00:00
|
|
|
/**
|
2021-01-25 12:42:36 +00:00
|
|
|
* Represent a set of closed polygons. Polygons may be nonconvex, self-intersecting
|
2015-06-12 15:12:02 +00:00
|
|
|
* and have holes. Provides boolean operations (using Clipper library as the backend).
|
|
|
|
*
|
2017-03-07 12:06:00 +00:00
|
|
|
* Let us define the terms used on this class to clarify methods names and comments:
|
|
|
|
* - Polygon: each polygon in the set.
|
|
|
|
* - Outline: first polyline in each polygon; represents its outer contour.
|
|
|
|
* - Hole: second and following polylines in the polygon.
|
|
|
|
* - Contour: each polyline of each polygon in the set, whether or not it is an
|
|
|
|
* outline or a hole.
|
|
|
|
* - Vertex (or corner): each one of the points that define a contour.
|
|
|
|
*
|
2015-07-27 19:45:57 +00:00
|
|
|
* TODO: add convex partitioning & spatial index
|
2015-06-12 15:12:02 +00:00
|
|
|
*/
|
|
|
|
class SHAPE_POLY_SET : public SHAPE
|
|
|
|
{
|
2020-12-12 03:43:16 +00:00
|
|
|
public:
|
2021-01-25 12:42:36 +00:00
|
|
|
///< represents a single polygon outline with holes. The first entry is the outline,
|
|
|
|
///< the remaining (if any), are the holes
|
|
|
|
///< N.B. SWIG only supports typedef, so avoid c++ 'using' keyword
|
2020-12-12 03:43:16 +00:00
|
|
|
typedef std::vector<SHAPE_LINE_CHAIN> POLYGON;
|
|
|
|
|
|
|
|
class TRIANGULATED_POLYGON
|
|
|
|
{
|
2015-06-12 15:12:02 +00:00
|
|
|
public:
|
2020-12-12 03:43:16 +00:00
|
|
|
struct TRI : public SHAPE_LINE_CHAIN_BASE
|
2015-08-16 12:07:58 +00:00
|
|
|
{
|
2020-12-12 03:43:16 +00:00
|
|
|
TRI( int _a = 0, int _b = 0, int _c = 0, TRIANGULATED_POLYGON* aParent = nullptr ) :
|
|
|
|
SHAPE_LINE_CHAIN_BASE( SH_POLY_SET_TRIANGLE ),
|
|
|
|
a( _a ),
|
|
|
|
b( _b ),
|
|
|
|
c( _c ),
|
|
|
|
parent( aParent )
|
2015-08-16 12:07:58 +00:00
|
|
|
{
|
|
|
|
}
|
2015-07-27 19:45:57 +00:00
|
|
|
|
2022-01-20 20:54:22 +00:00
|
|
|
virtual void Rotate( const EDA_ANGLE& aAngle,
|
|
|
|
const VECTOR2I& aCenter = { 0, 0 } ) override {};
|
2015-07-27 19:45:57 +00:00
|
|
|
|
2020-12-12 03:43:16 +00:00
|
|
|
virtual void Move( const VECTOR2I& aVector ) override {};
|
2019-07-16 15:41:21 +00:00
|
|
|
|
2020-12-12 03:43:16 +00:00
|
|
|
virtual bool IsSolid() const override { return true; }
|
2019-07-16 15:41:21 +00:00
|
|
|
|
2020-12-12 03:43:16 +00:00
|
|
|
virtual bool IsClosed() const override { return true; }
|
2019-07-16 15:41:21 +00:00
|
|
|
|
2020-12-12 03:43:16 +00:00
|
|
|
virtual const BOX2I BBox( int aClearance = 0 ) const override;
|
2015-07-27 19:45:57 +00:00
|
|
|
|
2020-12-12 03:43:16 +00:00
|
|
|
virtual const VECTOR2I GetPoint( int aIndex ) const override
|
2015-08-16 12:07:58 +00:00
|
|
|
{
|
2020-12-12 03:43:16 +00:00
|
|
|
switch(aIndex)
|
2015-07-27 19:45:57 +00:00
|
|
|
{
|
2020-12-12 03:43:16 +00:00
|
|
|
case 0: return parent->m_vertices[a];
|
|
|
|
case 1: return parent->m_vertices[b];
|
|
|
|
case 2: return parent->m_vertices[c];
|
2022-02-13 00:29:12 +00:00
|
|
|
default: wxCHECK( false, VECTOR2I() );
|
2015-07-27 19:45:57 +00:00
|
|
|
}
|
2015-08-16 12:07:58 +00:00
|
|
|
}
|
2015-07-27 19:45:57 +00:00
|
|
|
|
2020-12-12 03:43:16 +00:00
|
|
|
virtual const SEG GetSegment( int aIndex ) const override
|
2017-03-07 12:06:00 +00:00
|
|
|
{
|
2020-12-12 03:43:16 +00:00
|
|
|
switch(aIndex)
|
2017-03-07 12:06:00 +00:00
|
|
|
{
|
2020-12-12 03:43:16 +00:00
|
|
|
case 0: return SEG( parent->m_vertices[a], parent->m_vertices[b] );
|
|
|
|
case 1: return SEG( parent->m_vertices[b], parent->m_vertices[c] );
|
|
|
|
case 2: return SEG( parent->m_vertices[c], parent->m_vertices[a] );
|
2022-02-13 00:29:12 +00:00
|
|
|
default: wxCHECK( false, SEG() );
|
2017-03-07 12:06:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-12 03:43:16 +00:00
|
|
|
virtual size_t GetPointCount() const override { return 3; }
|
|
|
|
virtual size_t GetSegmentCount() const override { return 3; }
|
2017-03-07 12:06:00 +00:00
|
|
|
|
2022-02-13 00:29:12 +00:00
|
|
|
int a;
|
|
|
|
int b;
|
|
|
|
int c;
|
2020-12-12 03:43:16 +00:00
|
|
|
TRIANGULATED_POLYGON* parent;
|
2017-03-07 12:06:00 +00:00
|
|
|
};
|
|
|
|
|
2022-02-15 12:17:31 +00:00
|
|
|
TRIANGULATED_POLYGON( int aSourceOutline );
|
2020-12-12 03:43:16 +00:00
|
|
|
TRIANGULATED_POLYGON( const TRIANGULATED_POLYGON& aOther );
|
|
|
|
~TRIANGULATED_POLYGON();
|
2017-03-07 12:06:00 +00:00
|
|
|
|
2020-12-12 03:43:16 +00:00
|
|
|
void Clear()
|
2015-08-24 13:55:22 +00:00
|
|
|
{
|
2020-12-12 03:43:16 +00:00
|
|
|
m_vertices.clear();
|
|
|
|
m_triangles.clear();
|
2015-08-24 13:55:22 +00:00
|
|
|
}
|
2015-07-27 19:45:57 +00:00
|
|
|
|
2020-12-12 03:43:16 +00:00
|
|
|
void GetTriangle( int index, VECTOR2I& a, VECTOR2I& b, VECTOR2I& c ) const
|
2015-07-27 19:45:57 +00:00
|
|
|
{
|
2020-12-12 03:43:16 +00:00
|
|
|
auto tri = m_triangles[ index ];
|
|
|
|
a = m_vertices[ tri.a ];
|
|
|
|
b = m_vertices[ tri.b ];
|
|
|
|
c = m_vertices[ tri.c ];
|
2015-07-27 19:45:57 +00:00
|
|
|
}
|
|
|
|
|
2020-12-12 03:43:16 +00:00
|
|
|
TRIANGULATED_POLYGON& operator=( const TRIANGULATED_POLYGON& aOther );
|
2017-03-07 12:06:00 +00:00
|
|
|
|
2020-12-12 03:43:16 +00:00
|
|
|
void AddTriangle( int a, int b, int c );
|
2015-07-27 19:45:57 +00:00
|
|
|
|
2020-12-12 03:43:16 +00:00
|
|
|
void AddVertex( const VECTOR2I& aP )
|
2015-07-14 11:36:24 +00:00
|
|
|
{
|
2020-12-12 03:43:16 +00:00
|
|
|
m_vertices.push_back( aP );
|
2015-07-14 11:36:24 +00:00
|
|
|
}
|
|
|
|
|
2022-02-13 00:29:12 +00:00
|
|
|
size_t GetTriangleCount() const { return m_triangles.size(); }
|
2017-11-23 16:20:27 +00:00
|
|
|
|
2022-02-15 12:17:31 +00:00
|
|
|
int GetSourceOutlineIndex() const { return m_sourceOutline; }
|
2022-02-16 17:00:54 +00:00
|
|
|
void SetSourceOutlineIndex( int aIndex ) { m_sourceOutline = aIndex; }
|
2022-02-15 12:17:31 +00:00
|
|
|
|
2022-02-13 00:29:12 +00:00
|
|
|
std::deque<TRI>& Triangles() { return m_triangles; }
|
|
|
|
const std::deque<TRI>& Triangles() const { return m_triangles; }
|
2017-11-23 16:20:27 +00:00
|
|
|
|
2020-12-12 03:43:16 +00:00
|
|
|
size_t GetVertexCount() const
|
2015-07-27 19:45:57 +00:00
|
|
|
{
|
2020-12-12 03:43:16 +00:00
|
|
|
return m_vertices.size();
|
2015-07-27 19:45:57 +00:00
|
|
|
}
|
|
|
|
|
2020-12-12 03:43:16 +00:00
|
|
|
void Move( const VECTOR2I& aVec )
|
2015-07-27 19:45:57 +00:00
|
|
|
{
|
2022-02-13 00:29:12 +00:00
|
|
|
for( VECTOR2I& vertex : m_vertices )
|
2020-12-12 03:43:16 +00:00
|
|
|
vertex += aVec;
|
2015-07-27 19:45:57 +00:00
|
|
|
}
|
|
|
|
|
2020-12-12 03:43:16 +00:00
|
|
|
private:
|
2022-02-15 12:17:31 +00:00
|
|
|
int m_sourceOutline;
|
2020-12-12 03:43:16 +00:00
|
|
|
std::deque<TRI> m_triangles;
|
|
|
|
std::deque<VECTOR2I> m_vertices;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Structure to hold the necessary information in order to index a vertex on a
|
|
|
|
* SHAPE_POLY_SET object: the polygon index, the contour index relative to the polygon and
|
|
|
|
* the vertex index relative the contour.
|
|
|
|
*/
|
2021-07-01 22:28:41 +00:00
|
|
|
struct VERTEX_INDEX
|
2020-12-12 03:43:16 +00:00
|
|
|
{
|
|
|
|
int m_polygon; /*!< m_polygon is the index of the polygon. */
|
|
|
|
int m_contour; /*!< m_contour is the index of the contour relative to the polygon. */
|
|
|
|
int m_vertex; /*!< m_vertex is the index of the vertex relative to the contour. */
|
|
|
|
|
|
|
|
VERTEX_INDEX() :
|
|
|
|
m_polygon(-1),
|
|
|
|
m_contour(-1),
|
|
|
|
m_vertex(-1)
|
2015-07-27 19:45:57 +00:00
|
|
|
{
|
|
|
|
}
|
2021-07-01 22:28:41 +00:00
|
|
|
};
|
2020-12-12 03:43:16 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Base class for iterating over all vertices in a given SHAPE_POLY_SET.
|
|
|
|
*/
|
|
|
|
template <class T>
|
|
|
|
class ITERATOR_TEMPLATE
|
|
|
|
{
|
|
|
|
public:
|
2015-07-27 19:45:57 +00:00
|
|
|
|
2017-03-07 12:06:00 +00:00
|
|
|
/**
|
2021-01-25 12:42:36 +00:00
|
|
|
* @return true if the current vertex is the last one of the current contour
|
|
|
|
* (outline or hole); false otherwise.
|
2017-03-07 12:06:00 +00:00
|
|
|
*/
|
2020-12-12 03:43:16 +00:00
|
|
|
bool IsEndContour() const
|
2015-07-27 19:45:57 +00:00
|
|
|
{
|
2021-01-25 12:42:36 +00:00
|
|
|
return m_currentVertex + 1 ==
|
|
|
|
m_poly->CPolygon( m_currentPolygon )[m_currentContour].PointCount();
|
2015-07-27 19:45:57 +00:00
|
|
|
}
|
|
|
|
|
2017-03-07 12:06:00 +00:00
|
|
|
/**
|
2021-01-25 12:42:36 +00:00
|
|
|
* @return true if the current outline is the last one; false otherwise.
|
2017-03-07 12:06:00 +00:00
|
|
|
*/
|
2020-12-12 03:43:16 +00:00
|
|
|
bool IsLastPolygon() const
|
2015-07-27 19:45:57 +00:00
|
|
|
{
|
2020-12-12 03:43:16 +00:00
|
|
|
return m_currentPolygon == m_lastPolygon;
|
2015-07-27 19:45:57 +00:00
|
|
|
}
|
|
|
|
|
2020-12-12 03:43:16 +00:00
|
|
|
operator bool() const
|
2017-03-07 12:06:00 +00:00
|
|
|
{
|
2020-12-12 03:43:16 +00:00
|
|
|
if( m_currentPolygon < m_lastPolygon )
|
|
|
|
return true;
|
2017-03-07 12:06:00 +00:00
|
|
|
|
2020-12-12 03:43:16 +00:00
|
|
|
if( m_currentPolygon != m_poly->OutlineCount() - 1 )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
const auto& currentPolygon = m_poly->CPolygon( m_currentPolygon );
|
|
|
|
|
|
|
|
return m_currentContour < (int) currentPolygon.size() - 1
|
|
|
|
|| m_currentVertex < currentPolygon[m_currentContour].PointCount();
|
2015-07-27 19:45:57 +00:00
|
|
|
}
|
|
|
|
|
2017-03-07 12:06:00 +00:00
|
|
|
/**
|
2021-01-25 12:42:36 +00:00
|
|
|
* Advance the indices of the current vertex/outline/contour, checking whether the
|
|
|
|
* vertices in the holes have to be iterated through.
|
2017-03-07 12:06:00 +00:00
|
|
|
*/
|
2020-12-12 03:43:16 +00:00
|
|
|
void Advance()
|
2017-03-07 12:06:00 +00:00
|
|
|
{
|
2020-12-12 03:43:16 +00:00
|
|
|
// Advance vertex index
|
|
|
|
m_currentVertex ++;
|
2017-03-07 12:06:00 +00:00
|
|
|
|
2020-12-12 03:43:16 +00:00
|
|
|
// Check whether the user wants to iterate through the vertices of the holes
|
|
|
|
// and behave accordingly
|
|
|
|
if( m_iterateHoles )
|
|
|
|
{
|
|
|
|
// If the last vertex of the contour was reached, advance the contour index
|
2021-01-25 12:42:36 +00:00
|
|
|
if( m_currentVertex >=
|
|
|
|
m_poly->CPolygon( m_currentPolygon )[m_currentContour].PointCount() )
|
2020-12-12 03:43:16 +00:00
|
|
|
{
|
|
|
|
m_currentVertex = 0;
|
|
|
|
m_currentContour++;
|
2017-03-07 12:06:00 +00:00
|
|
|
|
2020-12-12 03:43:16 +00:00
|
|
|
// If the last contour of the current polygon was reached, advance the
|
|
|
|
// outline index
|
|
|
|
int totalContours = m_poly->CPolygon( m_currentPolygon ).size();
|
2015-07-27 19:45:57 +00:00
|
|
|
|
2020-12-12 03:43:16 +00:00
|
|
|
if( m_currentContour >= totalContours )
|
|
|
|
{
|
|
|
|
m_currentContour = 0;
|
|
|
|
m_currentPolygon++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// If the last vertex of the outline was reached, advance to the following polygon
|
|
|
|
if( m_currentVertex >= m_poly->CPolygon( m_currentPolygon )[0].PointCount() )
|
|
|
|
{
|
|
|
|
m_currentVertex = 0;
|
|
|
|
m_currentPolygon++;
|
|
|
|
}
|
|
|
|
}
|
2015-07-27 19:45:57 +00:00
|
|
|
}
|
|
|
|
|
2020-12-12 03:43:16 +00:00
|
|
|
void operator++( int dummy )
|
2015-07-27 19:45:57 +00:00
|
|
|
{
|
2020-12-12 03:43:16 +00:00
|
|
|
Advance();
|
2015-07-27 19:45:57 +00:00
|
|
|
}
|
|
|
|
|
2020-12-12 03:43:16 +00:00
|
|
|
void operator++()
|
2017-03-07 12:06:00 +00:00
|
|
|
{
|
2020-12-12 03:43:16 +00:00
|
|
|
Advance();
|
2017-03-07 12:06:00 +00:00
|
|
|
}
|
|
|
|
|
2020-12-12 03:43:16 +00:00
|
|
|
const T& Get()
|
2015-07-27 19:45:57 +00:00
|
|
|
{
|
2020-12-12 03:43:16 +00:00
|
|
|
return m_poly->Polygon( m_currentPolygon )[m_currentContour].CPoint( m_currentVertex );
|
2015-07-27 19:45:57 +00:00
|
|
|
}
|
|
|
|
|
2020-12-12 03:43:16 +00:00
|
|
|
const T& operator*()
|
2017-03-07 12:06:00 +00:00
|
|
|
{
|
2020-12-12 03:43:16 +00:00
|
|
|
return Get();
|
2017-03-07 12:06:00 +00:00
|
|
|
}
|
|
|
|
|
2020-12-12 03:43:16 +00:00
|
|
|
const T* operator->()
|
2017-03-07 12:06:00 +00:00
|
|
|
{
|
2020-12-12 03:43:16 +00:00
|
|
|
return &Get();
|
2017-03-07 12:06:00 +00:00
|
|
|
}
|
|
|
|
|
2020-12-12 03:43:16 +00:00
|
|
|
/**
|
2021-01-25 12:42:36 +00:00
|
|
|
* @return the indices of the current polygon, contour and vertex.
|
2020-12-12 03:43:16 +00:00
|
|
|
*/
|
|
|
|
VERTEX_INDEX GetIndex()
|
2017-03-07 12:06:00 +00:00
|
|
|
{
|
2020-12-12 03:43:16 +00:00
|
|
|
VERTEX_INDEX index;
|
2017-03-07 12:06:00 +00:00
|
|
|
|
2020-12-12 03:43:16 +00:00
|
|
|
index.m_polygon = m_currentPolygon;
|
|
|
|
index.m_contour = m_currentContour;
|
|
|
|
index.m_vertex = m_currentVertex;
|
2017-03-07 12:06:00 +00:00
|
|
|
|
2020-12-12 03:43:16 +00:00
|
|
|
return index;
|
2017-03-07 12:06:00 +00:00
|
|
|
}
|
|
|
|
|
2020-12-12 03:43:16 +00:00
|
|
|
private:
|
|
|
|
friend class SHAPE_POLY_SET;
|
|
|
|
|
|
|
|
SHAPE_POLY_SET* m_poly;
|
|
|
|
int m_currentPolygon;
|
|
|
|
int m_currentContour;
|
|
|
|
int m_currentVertex;
|
|
|
|
int m_lastPolygon;
|
|
|
|
bool m_iterateHoles;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Base class for iterating over all segments in a given SHAPE_POLY_SET.
|
|
|
|
*/
|
|
|
|
template <class T>
|
|
|
|
class SEGMENT_ITERATOR_TEMPLATE
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
/**
|
2021-01-25 12:42:36 +00:00
|
|
|
* @return true if the current outline is the last one.
|
2020-12-12 03:43:16 +00:00
|
|
|
*/
|
|
|
|
bool IsLastPolygon() const
|
2019-07-14 12:46:59 +00:00
|
|
|
{
|
2020-12-12 03:43:16 +00:00
|
|
|
return m_currentPolygon == m_lastPolygon;
|
2019-07-14 12:46:59 +00:00
|
|
|
}
|
|
|
|
|
2020-12-12 03:43:16 +00:00
|
|
|
operator bool() const
|
2017-03-07 12:06:00 +00:00
|
|
|
{
|
2020-12-12 03:43:16 +00:00
|
|
|
return m_currentPolygon <= m_lastPolygon;
|
2017-03-07 12:06:00 +00:00
|
|
|
}
|
|
|
|
|
2020-12-12 03:43:16 +00:00
|
|
|
/**
|
2021-01-25 12:42:36 +00:00
|
|
|
* Advance the indices of the current vertex/outline/contour, checking whether the
|
|
|
|
* vertices in the holes have to be iterated through.
|
2020-12-12 03:43:16 +00:00
|
|
|
*/
|
|
|
|
void Advance()
|
2019-07-14 12:46:59 +00:00
|
|
|
{
|
2020-12-12 03:43:16 +00:00
|
|
|
// Advance vertex index
|
|
|
|
m_currentSegment++;
|
|
|
|
int last;
|
2019-07-14 12:46:59 +00:00
|
|
|
|
2020-12-12 03:43:16 +00:00
|
|
|
// Check whether the user wants to iterate through the vertices of the holes
|
2021-01-25 12:42:36 +00:00
|
|
|
// and behave accordingly.
|
2020-12-12 03:43:16 +00:00
|
|
|
if( m_iterateHoles )
|
|
|
|
{
|
|
|
|
last = m_poly->CPolygon( m_currentPolygon )[m_currentContour].SegmentCount();
|
2017-03-07 12:06:00 +00:00
|
|
|
|
2021-01-25 12:42:36 +00:00
|
|
|
// If the last vertex of the contour was reached, advance the contour index.
|
2020-12-12 03:43:16 +00:00
|
|
|
if( m_currentSegment >= last )
|
|
|
|
{
|
|
|
|
m_currentSegment = 0;
|
|
|
|
m_currentContour++;
|
2017-03-07 12:06:00 +00:00
|
|
|
|
2020-12-12 03:43:16 +00:00
|
|
|
// If the last contour of the current polygon was reached, advance the
|
2021-01-25 12:42:36 +00:00
|
|
|
// outline index.
|
2020-12-12 03:43:16 +00:00
|
|
|
int totalContours = m_poly->CPolygon( m_currentPolygon ).size();
|
2019-07-14 12:46:59 +00:00
|
|
|
|
2020-12-12 03:43:16 +00:00
|
|
|
if( m_currentContour >= totalContours )
|
|
|
|
{
|
|
|
|
m_currentContour = 0;
|
|
|
|
m_currentPolygon++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
last = m_poly->CPolygon( m_currentPolygon )[0].SegmentCount();
|
|
|
|
// If the last vertex of the outline was reached, advance to the following
|
|
|
|
// polygon
|
|
|
|
if( m_currentSegment >= last )
|
|
|
|
{
|
|
|
|
m_currentSegment = 0;
|
|
|
|
m_currentPolygon++;
|
|
|
|
}
|
|
|
|
}
|
2020-06-27 11:57:40 +00:00
|
|
|
}
|
|
|
|
|
2020-12-12 03:43:16 +00:00
|
|
|
void operator++( int dummy )
|
2019-07-14 12:46:59 +00:00
|
|
|
{
|
2020-12-12 03:43:16 +00:00
|
|
|
Advance();
|
2017-03-07 12:06:00 +00:00
|
|
|
}
|
|
|
|
|
2020-12-12 03:43:16 +00:00
|
|
|
void operator++()
|
2019-07-12 12:56:02 +00:00
|
|
|
{
|
2020-12-12 03:43:16 +00:00
|
|
|
Advance();
|
2019-05-21 02:36:12 +00:00
|
|
|
}
|
2015-06-12 15:12:02 +00:00
|
|
|
|
2020-12-12 03:43:16 +00:00
|
|
|
T Get()
|
2015-06-12 15:12:02 +00:00
|
|
|
{
|
2020-12-12 03:43:16 +00:00
|
|
|
return m_poly->Polygon( m_currentPolygon )[m_currentContour].Segment( m_currentSegment );
|
2015-06-12 15:12:02 +00:00
|
|
|
}
|
|
|
|
|
2020-12-12 03:43:16 +00:00
|
|
|
T operator*()
|
2015-07-27 19:45:57 +00:00
|
|
|
{
|
2020-12-12 03:43:16 +00:00
|
|
|
return Get();
|
2015-07-27 19:45:57 +00:00
|
|
|
}
|
|
|
|
|
2017-03-07 12:06:00 +00:00
|
|
|
/**
|
2021-01-25 12:42:36 +00:00
|
|
|
* @return the indices of the current polygon, contour and vertex.
|
2015-08-16 12:07:58 +00:00
|
|
|
*/
|
2021-03-06 09:27:41 +00:00
|
|
|
VERTEX_INDEX GetIndex() const
|
2020-12-12 03:43:16 +00:00
|
|
|
{
|
|
|
|
VERTEX_INDEX index;
|
2015-06-12 15:12:02 +00:00
|
|
|
|
2020-12-12 03:43:16 +00:00
|
|
|
index.m_polygon = m_currentPolygon;
|
|
|
|
index.m_contour = m_currentContour;
|
|
|
|
index.m_vertex = m_currentSegment;
|
2015-08-24 13:55:22 +00:00
|
|
|
|
2020-12-12 03:43:16 +00:00
|
|
|
return index;
|
|
|
|
}
|
2017-03-07 12:06:00 +00:00
|
|
|
|
|
|
|
/**
|
2021-01-25 12:42:36 +00:00
|
|
|
* @param aOther is an iterator pointing to another segment.
|
|
|
|
* @return true if both iterators point to the same segment of the same contour of
|
|
|
|
* the same polygon of the same polygon set; false otherwise.
|
2017-03-07 12:06:00 +00:00
|
|
|
*/
|
2021-03-06 09:27:41 +00:00
|
|
|
bool IsAdjacent( SEGMENT_ITERATOR_TEMPLATE<T> aOther ) const
|
2017-03-07 12:06:00 +00:00
|
|
|
{
|
2020-12-12 03:43:16 +00:00
|
|
|
// Check that both iterators point to the same contour of the same polygon of the
|
2021-01-25 12:42:36 +00:00
|
|
|
// same polygon set.
|
2020-12-12 03:43:16 +00:00
|
|
|
if( m_poly == aOther.m_poly && m_currentPolygon == aOther.m_currentPolygon &&
|
|
|
|
m_currentContour == aOther.m_currentContour )
|
|
|
|
{
|
2021-01-25 12:42:36 +00:00
|
|
|
// Compute the total number of segments.
|
2020-12-12 03:43:16 +00:00
|
|
|
int numSeg;
|
|
|
|
numSeg = m_poly->CPolygon( m_currentPolygon )[m_currentContour].SegmentCount();
|
2018-04-06 10:24:23 +00:00
|
|
|
|
2020-12-12 03:43:16 +00:00
|
|
|
// Compute the difference of the segment indices. If it is exactly one, they
|
|
|
|
// are adjacent. The only missing case where they also are adjacent is when
|
|
|
|
// the segments are the first and last one, in which case the difference
|
|
|
|
// always equals the total number of segments minus one.
|
2021-03-06 09:27:41 +00:00
|
|
|
int indexDiff = std::abs( m_currentSegment - aOther.m_currentSegment );
|
2020-09-18 14:22:30 +00:00
|
|
|
|
2020-12-12 03:43:16 +00:00
|
|
|
return ( indexDiff == 1 ) || ( indexDiff == (numSeg - 1) );
|
|
|
|
}
|
2020-09-18 14:22:30 +00:00
|
|
|
|
2020-12-12 03:43:16 +00:00
|
|
|
return false;
|
|
|
|
}
|
2020-09-18 14:22:30 +00:00
|
|
|
|
2017-11-23 16:20:27 +00:00
|
|
|
private:
|
2020-12-12 03:43:16 +00:00
|
|
|
friend class SHAPE_POLY_SET;
|
|
|
|
|
|
|
|
SHAPE_POLY_SET* m_poly;
|
|
|
|
int m_currentPolygon;
|
|
|
|
int m_currentContour;
|
|
|
|
int m_currentSegment;
|
|
|
|
int m_lastPolygon;
|
|
|
|
bool m_iterateHoles;
|
|
|
|
};
|
|
|
|
|
|
|
|
// Iterator and const iterator types to visit polygon's points.
|
|
|
|
typedef ITERATOR_TEMPLATE<VECTOR2I> ITERATOR;
|
|
|
|
typedef ITERATOR_TEMPLATE<const VECTOR2I> CONST_ITERATOR;
|
|
|
|
|
|
|
|
// Iterator and const iterator types to visit polygon's edges.
|
|
|
|
typedef SEGMENT_ITERATOR_TEMPLATE<SEG> SEGMENT_ITERATOR;
|
|
|
|
typedef SEGMENT_ITERATOR_TEMPLATE<const SEG> CONST_SEGMENT_ITERATOR;
|
|
|
|
|
|
|
|
SHAPE_POLY_SET();
|
|
|
|
|
2021-09-25 14:31:19 +00:00
|
|
|
SHAPE_POLY_SET( const BOX2D& aRect );
|
|
|
|
|
2020-12-12 03:43:16 +00:00
|
|
|
/**
|
|
|
|
* Construct a SHAPE_POLY_SET with the first outline given by aOutline.
|
|
|
|
*
|
|
|
|
* @param aOutline is a closed outline
|
|
|
|
*/
|
|
|
|
SHAPE_POLY_SET( const SHAPE_LINE_CHAIN& aOutline );
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Copy constructor SHAPE_POLY_SET
|
|
|
|
* Performs a deep copy of \p aOther into \p this.
|
2021-01-25 12:42:36 +00:00
|
|
|
*
|
2020-12-12 03:43:16 +00:00
|
|
|
* @param aOther is the SHAPE_POLY_SET object that will be copied.
|
|
|
|
*/
|
|
|
|
SHAPE_POLY_SET( const SHAPE_POLY_SET& aOther );
|
|
|
|
|
|
|
|
~SHAPE_POLY_SET();
|
|
|
|
|
2021-03-06 09:27:41 +00:00
|
|
|
SHAPE_POLY_SET& operator=( const SHAPE_POLY_SET& aOther );
|
2020-12-12 03:43:16 +00:00
|
|
|
|
2022-05-13 16:09:22 +00:00
|
|
|
/**
|
|
|
|
* Build a polygon triangulation, needed to draw a polygon on OpenGL and in some
|
|
|
|
* other calculations
|
|
|
|
* @param aPartition = true to created a trinagulation in a partition on a grid
|
|
|
|
* false to create a more basic triangulation of the polygons
|
|
|
|
* Note
|
|
|
|
* in partition calculations the grid size is hard coded to 1e7.
|
|
|
|
* This is a good value for Pcbnew: 1cm, in internal units.
|
|
|
|
* But not good for Gerbview (1e7 = 10cm), however using a partition is not useful.
|
2022-11-28 22:54:53 +00:00
|
|
|
* @param aSimplify = force the algorithm to simplify the POLY_SET before triangulating
|
2022-05-13 16:09:22 +00:00
|
|
|
*/
|
2022-11-28 22:54:53 +00:00
|
|
|
void CacheTriangulation( bool aPartition = true, bool aSimplify = false );
|
2020-12-12 03:43:16 +00:00
|
|
|
bool IsTriangulationUpToDate() const;
|
|
|
|
|
|
|
|
MD5_HASH GetHash() const;
|
|
|
|
|
|
|
|
virtual bool HasIndexableSubshapes() const override;
|
|
|
|
|
|
|
|
virtual size_t GetIndexableSubshapeCount() const override;
|
|
|
|
|
2022-07-21 22:01:50 +00:00
|
|
|
virtual void GetIndexableSubshapes( std::vector<const SHAPE*>& aSubshapes ) const override;
|
2020-12-12 03:43:16 +00:00
|
|
|
|
|
|
|
/**
|
2021-01-25 12:42:36 +00:00
|
|
|
* Convert a global vertex index ---i.e., a number that globally identifies a vertex in a
|
2020-12-12 03:43:16 +00:00
|
|
|
* concatenated list of all vertices in all contours--- and get the index of the vertex
|
|
|
|
* relative to the contour relative to the polygon in which it is.
|
2021-01-25 12:42:36 +00:00
|
|
|
*
|
|
|
|
* @param aGlobalIdx is the global index of the corner whose structured index wants to
|
|
|
|
* be found
|
2020-12-12 03:43:16 +00:00
|
|
|
* @param aRelativeIndices is a pointer to the set of relative indices to store.
|
2021-01-25 12:42:36 +00:00
|
|
|
* @return true if the global index is correct and the information in \a aRelativeIndices
|
|
|
|
* is valid; false otherwise.
|
2020-12-12 03:43:16 +00:00
|
|
|
*/
|
2021-01-25 12:42:36 +00:00
|
|
|
bool GetRelativeIndices( int aGlobalIdx, VERTEX_INDEX* aRelativeIndices ) const;
|
2020-12-12 03:43:16 +00:00
|
|
|
|
|
|
|
/**
|
2021-01-25 12:42:36 +00:00
|
|
|
* Compute the global index of a vertex from the relative indices of polygon, contour and
|
2020-12-12 03:43:16 +00:00
|
|
|
* vertex.
|
2021-01-25 12:42:36 +00:00
|
|
|
*
|
2020-12-12 03:43:16 +00:00
|
|
|
* @param aRelativeIndices is the set of relative indices.
|
2021-01-25 12:42:36 +00:00
|
|
|
* @param aGlobalIdx [out] is the computed global index.
|
|
|
|
* @return true if the relative indices are correct; false otherwise. The computed
|
|
|
|
* global index is returned in the \p aGlobalIdx reference.
|
2020-12-12 03:43:16 +00:00
|
|
|
*/
|
2021-03-06 09:27:41 +00:00
|
|
|
bool GetGlobalIndex( VERTEX_INDEX aRelativeIndices, int& aGlobalIdx ) const;
|
2020-12-12 03:43:16 +00:00
|
|
|
|
|
|
|
/// @copydoc SHAPE::Clone()
|
|
|
|
SHAPE* Clone() const override;
|
|
|
|
|
2022-03-14 15:52:12 +00:00
|
|
|
SHAPE_POLY_SET CloneDropTriangulation() const;
|
|
|
|
|
2021-01-25 12:42:36 +00:00
|
|
|
///< Creates a new empty polygon in the set and returns its index
|
2020-12-12 03:43:16 +00:00
|
|
|
int NewOutline();
|
|
|
|
|
2021-01-25 12:42:36 +00:00
|
|
|
///< Creates a new hole in a given outline
|
2020-12-12 03:43:16 +00:00
|
|
|
int NewHole( int aOutline = -1 );
|
|
|
|
|
2021-01-25 12:42:36 +00:00
|
|
|
///< Adds a new outline to the set and returns its index
|
2020-12-12 03:43:16 +00:00
|
|
|
int AddOutline( const SHAPE_LINE_CHAIN& aOutline );
|
|
|
|
|
2021-01-25 12:42:36 +00:00
|
|
|
///< Adds a new hole to the given outline (default: last) and returns its index
|
2020-12-12 03:43:16 +00:00
|
|
|
int AddHole( const SHAPE_LINE_CHAIN& aHole, int aOutline = -1 );
|
|
|
|
|
2021-02-08 10:40:32 +00:00
|
|
|
///< Return the area of this poly set
|
|
|
|
double Area();
|
|
|
|
|
2021-06-19 14:53:49 +00:00
|
|
|
///< Count the number of arc shapes present
|
|
|
|
int ArcCount() const;
|
|
|
|
|
2021-05-04 19:13:41 +00:00
|
|
|
///< Appends all the arcs in this polyset to \a aArcBuffer
|
|
|
|
void GetArcs( std::vector<SHAPE_ARC>& aArcBuffer ) const;
|
|
|
|
|
2021-06-19 14:53:49 +00:00
|
|
|
///< Removes all arc references from all the outlines and holes in the polyset
|
|
|
|
void ClearArcs();
|
|
|
|
|
2021-01-25 12:42:36 +00:00
|
|
|
///< Appends a vertex at the end of the given outline/hole (default: the last outline)
|
2020-12-12 03:43:16 +00:00
|
|
|
/**
|
2021-01-25 12:42:36 +00:00
|
|
|
* Add a new vertex to the contour indexed by \p aOutline and \p aHole (defaults to the
|
2020-12-12 03:43:16 +00:00
|
|
|
* outline of the last polygon).
|
2021-01-25 12:42:36 +00:00
|
|
|
*
|
2020-12-12 03:43:16 +00:00
|
|
|
* @param x is the x coordinate of the new vertex.
|
|
|
|
* @param y is the y coordinate of the new vertex.
|
|
|
|
* @param aOutline is the index of the polygon.
|
|
|
|
* @param aHole is the index of the hole (-1 for the main outline),
|
|
|
|
* @param aAllowDuplication is a flag to indicate whether it is allowed to add this
|
|
|
|
* corner even if it is duplicated.
|
2021-01-25 12:42:36 +00:00
|
|
|
* @return the number of corners of the selected contour after the addition.
|
2020-12-12 03:43:16 +00:00
|
|
|
*/
|
2021-01-25 12:42:36 +00:00
|
|
|
int Append( int x, int y, int aOutline = -1, int aHole = -1, bool aAllowDuplication = false );
|
2020-12-12 03:43:16 +00:00
|
|
|
|
2021-01-25 12:42:36 +00:00
|
|
|
///< Merge polygons from two sets.
|
2020-12-12 03:43:16 +00:00
|
|
|
void Append( const SHAPE_POLY_SET& aSet );
|
|
|
|
|
2021-01-25 12:42:36 +00:00
|
|
|
///< Append a vertex at the end of the given outline/hole (default: the last outline)
|
2020-12-12 03:43:16 +00:00
|
|
|
void Append( const VECTOR2I& aP, int aOutline = -1, int aHole = -1 );
|
2020-08-14 00:10:40 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Append a new arc to the contour indexed by \p aOutline and \p aHole (defaults to the
|
|
|
|
* outline of the last polygon).
|
|
|
|
* @param aArc The arc to be inserted
|
|
|
|
* @param aOutline Index of the polygon
|
|
|
|
* @param aHole Index of the hole (-1 for the main outline)
|
|
|
|
* @return the number of points in the arc (including the interpolated points from the arc)
|
|
|
|
*/
|
|
|
|
int Append( SHAPE_ARC& aArc, int aOutline = -1, int aHole = -1 );
|
2020-12-12 03:43:16 +00:00
|
|
|
|
|
|
|
/**
|
2021-01-25 12:42:36 +00:00
|
|
|
* Adds a vertex in the globally indexed position \a aGlobalIndex.
|
|
|
|
*
|
|
|
|
* @param aGlobalIndex is the global index of the position in which the new vertex will be
|
2020-12-12 03:43:16 +00:00
|
|
|
* inserted.
|
|
|
|
* @param aNewVertex is the new inserted vertex.
|
|
|
|
*/
|
2021-07-26 23:47:26 +00:00
|
|
|
void InsertVertex( int aGlobalIndex, const VECTOR2I& aNewVertex );
|
2020-12-12 03:43:16 +00:00
|
|
|
|
2021-01-25 12:42:36 +00:00
|
|
|
///< Return the index-th vertex in a given hole outline within a given outline
|
2020-12-12 03:43:16 +00:00
|
|
|
const VECTOR2I& CVertex( int aIndex, int aOutline, int aHole ) const;
|
|
|
|
|
2021-01-25 12:42:36 +00:00
|
|
|
///< Return the aGlobalIndex-th vertex in the poly set
|
2020-12-12 03:43:16 +00:00
|
|
|
const VECTOR2I& CVertex( int aGlobalIndex ) const;
|
|
|
|
|
2021-01-25 12:42:36 +00:00
|
|
|
///< Return the index-th vertex in a given hole outline within a given outline
|
2020-12-12 03:43:16 +00:00
|
|
|
const VECTOR2I& CVertex( VERTEX_INDEX aIndex ) const;
|
|
|
|
|
|
|
|
/**
|
2021-01-25 12:42:36 +00:00
|
|
|
* Return the global indexes of the previous and the next corner of the \a aGlobalIndex-th
|
|
|
|
* corner of a contour in the polygon set.
|
|
|
|
*
|
|
|
|
* They are often aGlobalIndex-1 and aGlobalIndex+1, but not for the first and last
|
2020-12-12 03:43:16 +00:00
|
|
|
* corner of the contour.
|
2021-01-25 12:42:36 +00:00
|
|
|
*
|
2020-12-12 03:43:16 +00:00
|
|
|
* @param aGlobalIndex is index of the corner, globally indexed between all edges in all
|
|
|
|
* contours
|
2021-01-25 12:42:36 +00:00
|
|
|
* @param aPrevious is the globalIndex of the previous corner of the same contour.
|
|
|
|
* @param aNext is the globalIndex of the next corner of the same contour.
|
2020-12-12 03:43:16 +00:00
|
|
|
* @return true if OK, false if aGlobalIndex is out of range
|
|
|
|
*/
|
|
|
|
bool GetNeighbourIndexes( int aGlobalIndex, int* aPrevious, int* aNext );
|
|
|
|
|
|
|
|
/**
|
2021-01-25 12:42:36 +00:00
|
|
|
* Check whether the aPolygonIndex-th polygon in the set is self intersecting.
|
|
|
|
*
|
|
|
|
* @param aPolygonIndex is the index of the polygon that wants to be checked.
|
|
|
|
* @return true if the \a aPolygonIndex-th polygon is self intersecting, false otherwise.
|
2020-12-12 03:43:16 +00:00
|
|
|
*/
|
|
|
|
bool IsPolygonSelfIntersecting( int aPolygonIndex ) const;
|
|
|
|
|
|
|
|
/**
|
2021-01-25 12:42:36 +00:00
|
|
|
* Check whether any of the polygons in the set is self intersecting.
|
|
|
|
*
|
|
|
|
* @return true if any of the polygons is self intersecting, false otherwise.
|
2020-12-12 03:43:16 +00:00
|
|
|
*/
|
|
|
|
bool IsSelfIntersecting() const;
|
|
|
|
|
2021-01-25 12:42:36 +00:00
|
|
|
///< Return the number of triangulated polygons
|
2020-12-12 03:43:16 +00:00
|
|
|
unsigned int TriangulatedPolyCount() const { return m_triangulatedPolys.size(); }
|
|
|
|
|
2021-01-25 12:42:36 +00:00
|
|
|
///< Return the number of outlines in the set
|
2020-12-12 03:43:16 +00:00
|
|
|
int OutlineCount() const { return m_polys.size(); }
|
|
|
|
|
2021-01-25 12:42:36 +00:00
|
|
|
///< Return the number of vertices in a given outline/hole
|
2020-12-12 03:43:16 +00:00
|
|
|
int VertexCount( int aOutline = -1, int aHole = -1 ) const;
|
|
|
|
|
2021-10-24 12:41:58 +00:00
|
|
|
///< Return the number of points in the shape poly set.
|
|
|
|
///< mainly for reports
|
|
|
|
int FullPointCount() const;
|
|
|
|
|
2021-01-25 12:42:36 +00:00
|
|
|
///< Returns the number of holes in a given outline
|
2020-12-12 03:43:16 +00:00
|
|
|
int HoleCount( int aOutline ) const
|
|
|
|
{
|
2021-01-25 12:42:36 +00:00
|
|
|
if( ( aOutline < 0 ) || ( aOutline >= (int) m_polys.size() )
|
|
|
|
|| ( m_polys[aOutline].size() < 2 ) )
|
2020-12-12 03:43:16 +00:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
// the first polygon in m_polys[aOutline] is the main contour,
|
|
|
|
// only others are holes:
|
|
|
|
return m_polys[aOutline].size() - 1;
|
|
|
|
}
|
|
|
|
|
2021-01-25 12:42:36 +00:00
|
|
|
///< Return the reference to aIndex-th outline in the set
|
2020-12-12 03:43:16 +00:00
|
|
|
SHAPE_LINE_CHAIN& Outline( int aIndex )
|
|
|
|
{
|
|
|
|
return m_polys[aIndex][0];
|
|
|
|
}
|
|
|
|
|
2020-12-20 18:44:13 +00:00
|
|
|
const SHAPE_LINE_CHAIN& Outline( int aIndex ) const
|
|
|
|
{
|
|
|
|
return m_polys[aIndex][0];
|
|
|
|
}
|
|
|
|
|
2020-12-12 03:43:16 +00:00
|
|
|
/**
|
2021-01-25 12:42:36 +00:00
|
|
|
* Return a subset of the polygons in this set, the ones between \a aFirstPolygon and
|
|
|
|
* \a aLastPolygon.
|
|
|
|
*
|
2020-12-12 03:43:16 +00:00
|
|
|
* @param aFirstPolygon is the first polygon to be included in the returned set.
|
2021-01-25 12:42:36 +00:00
|
|
|
* @param aLastPolygon is the last polygon to be excluded of the returned set.
|
|
|
|
* @return a set containing the polygons between \a aFirstPolygon (included)
|
|
|
|
* and \a aLastPolygon (excluded).
|
2020-12-12 03:43:16 +00:00
|
|
|
*/
|
|
|
|
SHAPE_POLY_SET Subset( int aFirstPolygon, int aLastPolygon );
|
|
|
|
|
|
|
|
SHAPE_POLY_SET UnitSet( int aPolygonIndex )
|
|
|
|
{
|
|
|
|
return Subset( aPolygonIndex, aPolygonIndex + 1 );
|
|
|
|
}
|
|
|
|
|
2021-01-25 12:42:36 +00:00
|
|
|
///< Return the reference to aHole-th hole in the aIndex-th outline
|
2020-12-12 03:43:16 +00:00
|
|
|
SHAPE_LINE_CHAIN& Hole( int aOutline, int aHole )
|
|
|
|
{
|
|
|
|
return m_polys[aOutline][aHole + 1];
|
|
|
|
}
|
|
|
|
|
2021-01-25 12:42:36 +00:00
|
|
|
///< Return the aIndex-th subpolygon in the set
|
2020-12-12 03:43:16 +00:00
|
|
|
POLYGON& Polygon( int aIndex )
|
|
|
|
{
|
|
|
|
return m_polys[aIndex];
|
|
|
|
}
|
|
|
|
|
|
|
|
const POLYGON& Polygon( int aIndex ) const
|
|
|
|
{
|
|
|
|
return m_polys[aIndex];
|
|
|
|
}
|
|
|
|
|
|
|
|
const TRIANGULATED_POLYGON* TriangulatedPolygon( int aIndex ) const
|
|
|
|
{
|
|
|
|
return m_triangulatedPolys[aIndex].get();
|
|
|
|
}
|
|
|
|
|
|
|
|
const SHAPE_LINE_CHAIN& COutline( int aIndex ) const
|
|
|
|
{
|
|
|
|
return m_polys[aIndex][0];
|
|
|
|
}
|
|
|
|
|
|
|
|
const SHAPE_LINE_CHAIN& CHole( int aOutline, int aHole ) const
|
|
|
|
{
|
|
|
|
return m_polys[aOutline][aHole + 1];
|
|
|
|
}
|
|
|
|
|
|
|
|
const POLYGON& CPolygon( int aIndex ) const
|
|
|
|
{
|
|
|
|
return m_polys[aIndex];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-01-25 12:42:36 +00:00
|
|
|
* Return an object to iterate through the points of the polygons between \p aFirst and
|
2020-12-12 03:43:16 +00:00
|
|
|
* \p aLast.
|
2021-01-25 12:42:36 +00:00
|
|
|
*
|
2020-12-12 03:43:16 +00:00
|
|
|
* @param aFirst is the first polygon whose points will be iterated.
|
|
|
|
* @param aLast is the last polygon whose points will be iterated.
|
|
|
|
* @param aIterateHoles is a flag to indicate whether the points of the holes should be
|
|
|
|
* iterated.
|
|
|
|
* @return ITERATOR - the iterator object.
|
|
|
|
*/
|
|
|
|
ITERATOR Iterate( int aFirst, int aLast, bool aIterateHoles = false )
|
|
|
|
{
|
|
|
|
ITERATOR iter;
|
|
|
|
|
|
|
|
iter.m_poly = this;
|
|
|
|
iter.m_currentPolygon = aFirst;
|
|
|
|
iter.m_lastPolygon = aLast < 0 ? OutlineCount() - 1 : aLast;
|
|
|
|
iter.m_currentContour = 0;
|
|
|
|
iter.m_currentVertex = 0;
|
|
|
|
iter.m_iterateHoles = aIterateHoles;
|
|
|
|
|
|
|
|
return iter;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-01-25 12:42:36 +00:00
|
|
|
* @param aOutline is the index of the polygon to be iterated.
|
|
|
|
* @return an iterator object to visit all points in the main outline of the
|
|
|
|
* \a aOutline-th polygon, without visiting the points in the holes.
|
2020-12-12 03:43:16 +00:00
|
|
|
*/
|
|
|
|
ITERATOR Iterate( int aOutline )
|
|
|
|
{
|
|
|
|
return Iterate( aOutline, aOutline );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-01-25 12:42:36 +00:00
|
|
|
* @param aOutline the index of the polygon to be iterated.
|
|
|
|
* @return an iterator object to visit all points in the main outline of the
|
|
|
|
* \a aOutline-th polygon, visiting also the points in the holes.
|
2020-12-12 03:43:16 +00:00
|
|
|
*/
|
|
|
|
ITERATOR IterateWithHoles( int aOutline )
|
|
|
|
{
|
|
|
|
return Iterate( aOutline, aOutline, true );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-01-25 12:42:36 +00:00
|
|
|
* @return an iterator object to visit all points in all outlines of the set,
|
|
|
|
* without visiting the points in the holes.
|
2020-12-12 03:43:16 +00:00
|
|
|
*/
|
|
|
|
ITERATOR Iterate()
|
|
|
|
{
|
|
|
|
return Iterate( 0, OutlineCount() - 1 );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-01-25 12:42:36 +00:00
|
|
|
* @return an iterator object to visit all points in all outlines of the set,
|
|
|
|
* visiting also the points in the holes.
|
2020-12-12 03:43:16 +00:00
|
|
|
*/
|
|
|
|
ITERATOR IterateWithHoles()
|
|
|
|
{
|
|
|
|
return Iterate( 0, OutlineCount() - 1, true );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
CONST_ITERATOR CIterate( int aFirst, int aLast, bool aIterateHoles = false ) const
|
|
|
|
{
|
|
|
|
CONST_ITERATOR iter;
|
|
|
|
|
|
|
|
iter.m_poly = const_cast<SHAPE_POLY_SET*>( this );
|
|
|
|
iter.m_currentPolygon = aFirst;
|
|
|
|
iter.m_lastPolygon = aLast < 0 ? OutlineCount() - 1 : aLast;
|
|
|
|
iter.m_currentContour = 0;
|
|
|
|
iter.m_currentVertex = 0;
|
|
|
|
iter.m_iterateHoles = aIterateHoles;
|
|
|
|
|
|
|
|
return iter;
|
|
|
|
}
|
|
|
|
|
|
|
|
CONST_ITERATOR CIterate( int aOutline ) const
|
|
|
|
{
|
|
|
|
return CIterate( aOutline, aOutline );
|
|
|
|
}
|
|
|
|
|
|
|
|
CONST_ITERATOR CIterateWithHoles( int aOutline ) const
|
|
|
|
{
|
|
|
|
return CIterate( aOutline, aOutline, true );
|
|
|
|
}
|
|
|
|
|
|
|
|
CONST_ITERATOR CIterate() const
|
|
|
|
{
|
|
|
|
return CIterate( 0, OutlineCount() - 1 );
|
|
|
|
}
|
|
|
|
|
|
|
|
CONST_ITERATOR CIterateWithHoles() const
|
|
|
|
{
|
|
|
|
return CIterate( 0, OutlineCount() - 1, true );
|
|
|
|
}
|
|
|
|
|
|
|
|
ITERATOR IterateFromVertexWithHoles( int aGlobalIdx )
|
|
|
|
{
|
|
|
|
// Build iterator
|
|
|
|
ITERATOR iter = IterateWithHoles();
|
|
|
|
|
|
|
|
// Get the relative indices of the globally indexed vertex
|
|
|
|
VERTEX_INDEX indices;
|
|
|
|
|
|
|
|
if( !GetRelativeIndices( aGlobalIdx, &indices ) )
|
|
|
|
throw( std::out_of_range( "aGlobalIndex-th vertex does not exist" ) );
|
|
|
|
|
|
|
|
// Adjust where the iterator is pointing
|
|
|
|
iter.m_currentPolygon = indices.m_polygon;
|
|
|
|
iter.m_currentContour = indices.m_contour;
|
|
|
|
iter.m_currentVertex = indices.m_vertex;
|
|
|
|
|
|
|
|
return iter;
|
|
|
|
}
|
|
|
|
|
2021-01-25 12:42:36 +00:00
|
|
|
///< Return an iterator object, for iterating between aFirst and aLast outline, with or
|
|
|
|
///< without holes (default: without)
|
2020-12-12 03:43:16 +00:00
|
|
|
SEGMENT_ITERATOR IterateSegments( int aFirst, int aLast, bool aIterateHoles = false )
|
|
|
|
{
|
|
|
|
SEGMENT_ITERATOR iter;
|
|
|
|
|
|
|
|
iter.m_poly = this;
|
|
|
|
iter.m_currentPolygon = aFirst;
|
|
|
|
iter.m_lastPolygon = aLast < 0 ? OutlineCount() - 1 : aLast;
|
|
|
|
iter.m_currentContour = 0;
|
|
|
|
iter.m_currentSegment = 0;
|
|
|
|
iter.m_iterateHoles = aIterateHoles;
|
|
|
|
|
|
|
|
return iter;
|
|
|
|
}
|
|
|
|
|
2021-01-25 12:42:36 +00:00
|
|
|
///< Return an iterator object, for iterating between aFirst and aLast outline, with or
|
|
|
|
///< without holes (default: without)
|
2020-12-12 03:43:16 +00:00
|
|
|
CONST_SEGMENT_ITERATOR CIterateSegments( int aFirst, int aLast,
|
|
|
|
bool aIterateHoles = false ) const
|
|
|
|
{
|
|
|
|
CONST_SEGMENT_ITERATOR iter;
|
|
|
|
|
|
|
|
iter.m_poly = const_cast<SHAPE_POLY_SET*>( this );
|
|
|
|
iter.m_currentPolygon = aFirst;
|
|
|
|
iter.m_lastPolygon = aLast < 0 ? OutlineCount() - 1 : aLast;
|
|
|
|
iter.m_currentContour = 0;
|
|
|
|
iter.m_currentSegment = 0;
|
|
|
|
iter.m_iterateHoles = aIterateHoles;
|
|
|
|
|
|
|
|
return iter;
|
|
|
|
}
|
|
|
|
|
2021-01-25 12:42:36 +00:00
|
|
|
///< Return an iterator object, for iterating aPolygonIdx-th polygon edges.
|
2020-12-12 03:43:16 +00:00
|
|
|
SEGMENT_ITERATOR IterateSegments( int aPolygonIdx )
|
|
|
|
{
|
|
|
|
return IterateSegments( aPolygonIdx, aPolygonIdx );
|
|
|
|
}
|
|
|
|
|
2021-01-25 12:42:36 +00:00
|
|
|
///< Return an iterator object, for iterating aPolygonIdx-th polygon edges.
|
2020-12-12 03:43:16 +00:00
|
|
|
CONST_SEGMENT_ITERATOR CIterateSegments( int aPolygonIdx ) const
|
|
|
|
{
|
|
|
|
return CIterateSegments( aPolygonIdx, aPolygonIdx );
|
|
|
|
}
|
|
|
|
|
2021-01-25 12:42:36 +00:00
|
|
|
///< Return an iterator object, for all outlines in the set (no holes).
|
2020-12-12 03:43:16 +00:00
|
|
|
SEGMENT_ITERATOR IterateSegments()
|
|
|
|
{
|
|
|
|
return IterateSegments( 0, OutlineCount() - 1 );
|
|
|
|
}
|
|
|
|
|
2021-03-06 09:27:41 +00:00
|
|
|
///< Returns an iterator object, for all outlines in the set (no holes)
|
|
|
|
CONST_SEGMENT_ITERATOR CIterateSegments() const
|
|
|
|
{
|
|
|
|
return CIterateSegments( 0, OutlineCount() - 1 );
|
|
|
|
}
|
|
|
|
|
|
|
|
///< Returns an iterator object, for all outlines in the set (with holes)
|
2020-12-12 03:43:16 +00:00
|
|
|
SEGMENT_ITERATOR IterateSegmentsWithHoles()
|
|
|
|
{
|
|
|
|
return IterateSegments( 0, OutlineCount() - 1, true );
|
|
|
|
}
|
|
|
|
|
2021-01-25 12:42:36 +00:00
|
|
|
///< Return an iterator object, for the \a aOutline-th outline in the set (with holes).
|
2020-12-12 03:43:16 +00:00
|
|
|
SEGMENT_ITERATOR IterateSegmentsWithHoles( int aOutline )
|
|
|
|
{
|
|
|
|
return IterateSegments( aOutline, aOutline, true );
|
|
|
|
}
|
|
|
|
|
2021-01-25 12:42:36 +00:00
|
|
|
///< Return an iterator object, for the \a aOutline-th outline in the set (with holes).
|
2020-12-12 03:43:16 +00:00
|
|
|
CONST_SEGMENT_ITERATOR CIterateSegmentsWithHoles() const
|
|
|
|
{
|
|
|
|
return CIterateSegments( 0, OutlineCount() - 1, true );
|
|
|
|
}
|
|
|
|
|
2021-01-25 12:42:36 +00:00
|
|
|
///< Return an iterator object, for the \a aOutline-th outline in the set (with holes).
|
2020-12-12 03:43:16 +00:00
|
|
|
CONST_SEGMENT_ITERATOR CIterateSegmentsWithHoles( int aOutline ) const
|
|
|
|
{
|
|
|
|
return CIterateSegments( aOutline, aOutline, true );
|
|
|
|
}
|
|
|
|
|
2021-01-25 12:42:36 +00:00
|
|
|
/**
|
|
|
|
* Operations on polygons use a \a aFastMode param
|
|
|
|
* if aFastMode is #PM_FAST (true) the result can be a weak polygon
|
|
|
|
* if aFastMode is #PM_STRICTLY_SIMPLE (false) (default) the result is (theoretically) a
|
|
|
|
* strictly simple polygon, but calculations can be really significantly time consuming
|
|
|
|
* Most of time #PM_FAST is preferable.
|
|
|
|
* #PM_STRICTLY_SIMPLE can be used in critical cases (Gerber output for instance)
|
2020-12-12 03:43:16 +00:00
|
|
|
*/
|
|
|
|
enum POLYGON_MODE
|
|
|
|
{
|
|
|
|
PM_FAST = true,
|
|
|
|
PM_STRICTLY_SIMPLE = false
|
|
|
|
};
|
|
|
|
|
2021-01-25 12:42:36 +00:00
|
|
|
///< Perform boolean polyset union
|
|
|
|
///< For \a aFastMode meaning, see function booleanOp
|
2020-12-12 03:43:16 +00:00
|
|
|
void BooleanAdd( const SHAPE_POLY_SET& b, POLYGON_MODE aFastMode );
|
|
|
|
|
2021-01-25 12:42:36 +00:00
|
|
|
///< Perform boolean polyset difference
|
|
|
|
///< For \a aFastMode meaning, see function booleanOp
|
2020-12-12 03:43:16 +00:00
|
|
|
void BooleanSubtract( const SHAPE_POLY_SET& b, POLYGON_MODE aFastMode );
|
|
|
|
|
2021-01-25 12:42:36 +00:00
|
|
|
///< Perform boolean polyset intersection
|
|
|
|
///< For \a aFastMode meaning, see function booleanOp
|
2020-12-12 03:43:16 +00:00
|
|
|
void BooleanIntersection( const SHAPE_POLY_SET& b, POLYGON_MODE aFastMode );
|
|
|
|
|
2021-01-25 12:42:36 +00:00
|
|
|
///< Perform boolean polyset union between a and b, store the result in it self
|
|
|
|
///< For \a aFastMode meaning, see function booleanOp
|
2020-12-12 03:43:16 +00:00
|
|
|
void BooleanAdd( const SHAPE_POLY_SET& a, const SHAPE_POLY_SET& b,
|
|
|
|
POLYGON_MODE aFastMode );
|
|
|
|
|
2021-01-25 12:42:36 +00:00
|
|
|
///< Perform boolean polyset difference between a and b, store the result in it self
|
|
|
|
///< For \a aFastMode meaning, see function booleanOp
|
2020-12-12 03:43:16 +00:00
|
|
|
void BooleanSubtract( const SHAPE_POLY_SET& a, const SHAPE_POLY_SET& b,
|
|
|
|
POLYGON_MODE aFastMode );
|
|
|
|
|
2021-01-25 12:42:36 +00:00
|
|
|
///< Perform boolean polyset intersection between a and b, store the result in it self
|
|
|
|
///< For \a aFastMode meaning, see function booleanOp
|
2020-12-12 03:43:16 +00:00
|
|
|
void BooleanIntersection( const SHAPE_POLY_SET& a, const SHAPE_POLY_SET& b,
|
|
|
|
POLYGON_MODE aFastMode );
|
2017-11-23 16:20:27 +00:00
|
|
|
|
2021-01-25 12:42:36 +00:00
|
|
|
enum CORNER_STRATEGY ///< define how inflate transform build inflated polygon
|
2020-12-12 03:43:16 +00:00
|
|
|
{
|
|
|
|
ALLOW_ACUTE_CORNERS, ///< just inflate the polygon. Acute angles create spikes
|
|
|
|
CHAMFER_ACUTE_CORNERS, ///< Acute angles are chamfered
|
|
|
|
ROUND_ACUTE_CORNERS, ///< Acute angles are rounded
|
|
|
|
CHAMFER_ALL_CORNERS, ///< All angles are chamfered.
|
|
|
|
///< The distance between new and old polygon edges is not
|
|
|
|
///< constant, but do not change a lot
|
|
|
|
ROUND_ALL_CORNERS ///< All angles are rounded.
|
|
|
|
///< The distance between new and old polygon edges is constant
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2021-01-25 12:42:36 +00:00
|
|
|
* Perform outline inflation/deflation.
|
|
|
|
*
|
|
|
|
* Polygons can have holes, but not linked holes with main outlines, if aFactor < 0. For
|
|
|
|
* those use InflateWithLinkedHoles() to avoid odd corners where the link segments meet
|
|
|
|
* the outline.
|
2020-12-12 03:43:16 +00:00
|
|
|
*
|
2021-01-25 12:42:36 +00:00
|
|
|
* @param aAmount is the number of units to offset edges.
|
2021-06-02 23:01:36 +00:00
|
|
|
* @param aCircleSegCount is the number of segments per 360 degrees to use in curve approx
|
2021-01-25 12:42:36 +00:00
|
|
|
* @param aCornerStrategy #ALLOW_ACUTE_CORNERS to preserve all angles,
|
2021-03-31 21:34:13 +00:00
|
|
|
* #CHAMFER_ACUTE_CORNERS to chop angles less than 90°,
|
2021-01-25 12:42:36 +00:00
|
|
|
* #ROUND_ACUTE_CORNERS to round off angles less than 90°,
|
|
|
|
* #ROUND_ALL_CORNERS to round regardless of angles
|
2020-12-12 03:43:16 +00:00
|
|
|
*/
|
2021-06-02 23:01:36 +00:00
|
|
|
void Inflate( int aAmount, int aCircleSegCount,
|
2020-12-12 03:43:16 +00:00
|
|
|
CORNER_STRATEGY aCornerStrategy = ROUND_ALL_CORNERS );
|
|
|
|
|
|
|
|
void Deflate( int aAmount, int aCircleSegmentsCount,
|
|
|
|
CORNER_STRATEGY aCornerStrategy = ROUND_ALL_CORNERS )
|
|
|
|
{
|
|
|
|
Inflate( -aAmount, aCircleSegmentsCount, aCornerStrategy );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-01-25 12:42:36 +00:00
|
|
|
* Perform outline inflation/deflation, using round corners.
|
|
|
|
*
|
|
|
|
* Polygons can have holes and/or linked holes with main outlines. The resulting
|
|
|
|
* polygons are also polygons with linked holes to main outlines. For \a aFastMode
|
|
|
|
* meaning, see function booleanOp .
|
2020-12-12 03:43:16 +00:00
|
|
|
*/
|
|
|
|
void InflateWithLinkedHoles( int aFactor, int aCircleSegmentsCount, POLYGON_MODE aFastMode );
|
|
|
|
|
2021-06-09 19:32:58 +00:00
|
|
|
///< Convert a set of polygons with holes to a single outline with "slits"/"fractures"
|
2021-01-25 12:42:36 +00:00
|
|
|
///< connecting the outer ring to the inner holes
|
|
|
|
///< For \a aFastMode meaning, see function booleanOp
|
2020-12-12 03:43:16 +00:00
|
|
|
void Fracture( POLYGON_MODE aFastMode );
|
|
|
|
|
2021-01-25 12:42:36 +00:00
|
|
|
///< Convert a single outline slitted ("fractured") polygon into a set ouf outlines
|
|
|
|
///< with holes.
|
2020-12-12 03:43:16 +00:00
|
|
|
void Unfracture( POLYGON_MODE aFastMode );
|
|
|
|
|
2021-01-25 12:42:36 +00:00
|
|
|
///< Return true if the polygon set has any holes.
|
2020-12-12 03:43:16 +00:00
|
|
|
bool HasHoles() const;
|
|
|
|
|
2021-01-25 12:42:36 +00:00
|
|
|
///< Return true if the polygon set has any holes that share a vertex.
|
2020-12-12 03:43:16 +00:00
|
|
|
bool HasTouchingHoles() const;
|
|
|
|
|
|
|
|
|
2021-01-25 12:42:36 +00:00
|
|
|
///< Simplify the polyset (merges overlapping polys, eliminates degeneracy/self-intersections)
|
|
|
|
///< For \a aFastMode meaning, see function booleanOp
|
2020-12-12 03:43:16 +00:00
|
|
|
void Simplify( POLYGON_MODE aFastMode );
|
|
|
|
|
|
|
|
/**
|
2021-01-25 12:42:36 +00:00
|
|
|
* Convert a self-intersecting polygon to one (or more) non self-intersecting polygon(s).
|
|
|
|
*
|
2020-12-12 03:43:16 +00:00
|
|
|
* Removes null segments.
|
2021-01-25 12:42:36 +00:00
|
|
|
*
|
|
|
|
* @return the polygon count (always >= 1, because there is at least one polygon)
|
|
|
|
* There are new polygons only if the polygon count is > 1.
|
2020-12-12 03:43:16 +00:00
|
|
|
*/
|
|
|
|
int NormalizeAreaOutlines();
|
|
|
|
|
|
|
|
/// @copydoc SHAPE::Format()
|
2022-10-23 22:20:02 +00:00
|
|
|
const std::string Format( bool aCplusPlus = true ) const override;
|
2020-12-12 03:43:16 +00:00
|
|
|
|
|
|
|
/// @copydoc SHAPE::Parse()
|
|
|
|
bool Parse( std::stringstream& aStream ) override;
|
|
|
|
|
|
|
|
/// @copydoc SHAPE::Move()
|
|
|
|
void Move( const VECTOR2I& aVector ) override;
|
|
|
|
|
|
|
|
/**
|
2021-01-25 12:42:36 +00:00
|
|
|
* Mirror the line points about y or x (or both)
|
|
|
|
*
|
2020-12-12 03:43:16 +00:00
|
|
|
* @param aX If true, mirror about the y axis (flip x coordinate)
|
|
|
|
* @param aY If true, mirror about the x axis
|
|
|
|
* @param aRef sets the reference point about which to mirror
|
|
|
|
*/
|
|
|
|
void Mirror( bool aX = true, bool aY = false, const VECTOR2I& aRef = { 0, 0 } );
|
|
|
|
|
|
|
|
/**
|
2021-01-25 12:42:36 +00:00
|
|
|
* Rotate all vertices by a given angle.
|
|
|
|
*
|
|
|
|
* @param aCenter is the rotation center.
|
2022-01-20 20:54:22 +00:00
|
|
|
* @param aAngle is the rotation angle.
|
2020-12-12 03:43:16 +00:00
|
|
|
*/
|
2022-01-20 20:54:22 +00:00
|
|
|
void Rotate( const EDA_ANGLE& aAngle, const VECTOR2I& aCenter = { 0, 0 } ) override;
|
2020-12-12 03:43:16 +00:00
|
|
|
|
|
|
|
/// @copydoc SHAPE::IsSolid()
|
|
|
|
bool IsSolid() const override
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
const BOX2I BBox( int aClearance = 0 ) const override;
|
|
|
|
|
|
|
|
/**
|
2021-01-25 12:42:36 +00:00
|
|
|
* Check if point \a aP lies on an edge or vertex of some of the outlines or holes.
|
2020-12-12 03:43:16 +00:00
|
|
|
*
|
|
|
|
* @param aP is the point to check.
|
2021-01-25 12:42:36 +00:00
|
|
|
* @return true if the point lies on the edge of any polygon.
|
2020-12-12 03:43:16 +00:00
|
|
|
*/
|
|
|
|
bool PointOnEdge( const VECTOR2I& aP ) const;
|
|
|
|
|
|
|
|
/**
|
2021-01-25 12:42:36 +00:00
|
|
|
* Check if the boundary of shape (this) lies closer to the shape \a aShape than \a aClearance,
|
2020-12-12 03:43:16 +00:00
|
|
|
* indicating a collision.
|
2021-01-25 12:42:36 +00:00
|
|
|
*
|
2020-12-12 03:43:16 +00:00
|
|
|
* @param aShape shape to check collision against
|
|
|
|
* @param aClearance minimum clearance
|
|
|
|
* @param aActual [out] an optional pointer to an int to store the actual distance in the
|
|
|
|
* event of a collision.
|
|
|
|
* @param aLocation [out] an option pointer to a point to store a nearby location in the
|
|
|
|
* event of a collision.
|
2021-01-25 12:42:36 +00:00
|
|
|
* @return true if there is a collision.
|
2020-12-12 03:43:16 +00:00
|
|
|
*/
|
|
|
|
bool Collide( const SHAPE* aShape, int aClearance = 0, int* aActual = nullptr,
|
|
|
|
VECTOR2I* aLocation = nullptr ) const override;
|
|
|
|
|
|
|
|
/**
|
2021-01-25 12:42:36 +00:00
|
|
|
* Check whether the point \a aP is either inside or on the edge of the polygon set.
|
2020-12-12 03:43:16 +00:00
|
|
|
*
|
|
|
|
* Note that prior to Jul 2020 we considered the edge to *not* be part of the polygon.
|
|
|
|
* However, most other shapes (rects, circles, segments, etc.) include their edges and
|
|
|
|
* the difference was causing issues when used for DRC.
|
|
|
|
*
|
|
|
|
* (FWIW, SHAPE_LINE_CHAIN was a split personality, with Collide() including its edges
|
|
|
|
* but PointInside() not. That has also been corrected.)
|
|
|
|
*
|
|
|
|
* @param aP is the VECTOR2I point whose collision with respect to the poly set
|
|
|
|
* will be tested.
|
|
|
|
* @param aClearance is the security distance; if the point lies closer to the polygon
|
|
|
|
* than aClearance distance, then there is a collision.
|
|
|
|
* @param aActual an optional pointer to an int to store the actual distance in the event
|
|
|
|
* of a collision.
|
2021-01-25 12:42:36 +00:00
|
|
|
* @return true if the point aP collides with the polygon; false in any other case.
|
2020-12-12 03:43:16 +00:00
|
|
|
*/
|
|
|
|
bool Collide( const VECTOR2I& aP, int aClearance = 0, int* aActual = nullptr,
|
|
|
|
VECTOR2I* aLocation = nullptr ) const override;
|
|
|
|
|
|
|
|
/**
|
2021-01-25 12:42:36 +00:00
|
|
|
* Check whether the segment \a aSeg collides with the polygon set (or its edge).
|
2020-12-12 03:43:16 +00:00
|
|
|
*
|
|
|
|
* Note that prior to Jul 2020 we considered the edge to *not* be part of the polygon.
|
|
|
|
* However, most other shapes (rects, circles, segments, etc.) include their edges and
|
|
|
|
* the difference was causing issues when used for DRC.
|
|
|
|
*
|
|
|
|
* (FWIW, SHAPE_LINE_CHAIN was a split personality, with Collide() including its edges
|
|
|
|
* but PointInside() not. That has also been corrected.)
|
|
|
|
*
|
|
|
|
* @param aSeg is the SEG segment whose collision with respect to the poly set
|
|
|
|
* will be tested.
|
|
|
|
* @param aClearance is the security distance; if the segment passes closer to the polygon
|
|
|
|
* than aClearance distance, then there is a collision.
|
|
|
|
* @param aActual an optional pointer to an int to store the actual distance in the event
|
|
|
|
* of a collision.
|
2021-01-25 12:42:36 +00:00
|
|
|
* @return true if the segment aSeg collides with the polygon, false in any other case.
|
2020-12-12 03:43:16 +00:00
|
|
|
*/
|
|
|
|
bool Collide( const SEG& aSeg, int aClearance = 0, int* aActual = nullptr,
|
|
|
|
VECTOR2I* aLocation = nullptr ) const override;
|
|
|
|
|
|
|
|
/**
|
2021-01-25 12:42:36 +00:00
|
|
|
* Check whether \a aPoint collides with any vertex of any of the contours of the polygon.
|
|
|
|
*
|
|
|
|
* @param aPoint is the #VECTOR2I point whose collision with respect to the polygon
|
2020-12-12 03:43:16 +00:00
|
|
|
* will be tested.
|
|
|
|
* @param aClearance is the security distance; if \p aPoint lies closer to a vertex than
|
|
|
|
* aClearance distance, then there is a collision.
|
|
|
|
* @param aClosestVertex is the index of the closes vertex to \p aPoint.
|
|
|
|
* @return bool - true if there is a collision, false in any other case.
|
|
|
|
*/
|
2022-07-16 17:41:59 +00:00
|
|
|
bool CollideVertex( const VECTOR2I& aPoint, VERTEX_INDEX* aClosestVertex = nullptr,
|
2020-12-12 03:43:16 +00:00
|
|
|
int aClearance = 0 ) const;
|
|
|
|
|
|
|
|
/**
|
2021-01-25 12:42:36 +00:00
|
|
|
* Check whether aPoint collides with any edge of any of the contours of the polygon.
|
|
|
|
*
|
2020-12-12 03:43:16 +00:00
|
|
|
* @param aPoint is the VECTOR2I point whose collision with respect to the polygon
|
|
|
|
* will be tested.
|
|
|
|
* @param aClearance is the security distance; if \p aPoint lies closer to a vertex than
|
|
|
|
* aClearance distance, then there is a collision.
|
|
|
|
* @param aClosestVertex is the index of the closes vertex to \p aPoint.
|
|
|
|
* @return bool - true if there is a collision, false in any other case.
|
|
|
|
*/
|
2022-07-16 17:41:59 +00:00
|
|
|
bool CollideEdge( const VECTOR2I& aPoint, VERTEX_INDEX* aClosestVertex = nullptr,
|
2020-12-12 03:43:16 +00:00
|
|
|
int aClearance = 0 ) const;
|
|
|
|
|
|
|
|
/**
|
2021-01-25 12:42:36 +00:00
|
|
|
* Construct BBoxCaches for Contains(), below.
|
|
|
|
*
|
|
|
|
* @note These caches **must** be built before a group of calls to Contains(). They are
|
|
|
|
* **not** kept up-to-date by editing actions.
|
2020-12-12 03:43:16 +00:00
|
|
|
*/
|
2021-02-20 13:25:16 +00:00
|
|
|
void BuildBBoxCaches() const;
|
2020-12-12 03:43:16 +00:00
|
|
|
|
|
|
|
const BOX2I BBoxFromCaches() const;
|
|
|
|
|
|
|
|
/**
|
2021-01-25 12:42:36 +00:00
|
|
|
* Return true if a given subpolygon contains the point \a aP.
|
2020-12-12 03:43:16 +00:00
|
|
|
*
|
|
|
|
* @param aP is the point to check
|
|
|
|
* @param aSubpolyIndex is the subpolygon to check, or -1 to check all
|
|
|
|
* @param aUseBBoxCaches gives faster performance when multiple calls are made with no
|
|
|
|
* editing in between, but the caller MUST cache the bbox caches
|
|
|
|
* before calling (via BuildBBoxCaches(), above)
|
|
|
|
* @return true if the polygon contains the point
|
|
|
|
*/
|
|
|
|
bool Contains( const VECTOR2I& aP, int aSubpolyIndex = -1, int aAccuracy = 0,
|
|
|
|
bool aUseBBoxCaches = false ) const;
|
|
|
|
|
2021-01-25 12:42:36 +00:00
|
|
|
///< Return true if the set is empty (no polygons at all)
|
2020-12-12 03:43:16 +00:00
|
|
|
bool IsEmpty() const
|
|
|
|
{
|
2021-03-06 09:27:41 +00:00
|
|
|
return m_polys.empty();
|
2020-12-12 03:43:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-01-25 12:42:36 +00:00
|
|
|
* Delete the \a aGlobalIndex-th vertex.
|
|
|
|
*
|
2020-12-12 03:43:16 +00:00
|
|
|
* @param aGlobalIndex is the global index of the to-be-removed vertex.
|
|
|
|
*/
|
|
|
|
void RemoveVertex( int aGlobalIndex );
|
|
|
|
|
|
|
|
/**
|
2021-01-25 12:42:36 +00:00
|
|
|
* Delete the vertex indexed by \a aRelativeIndex (index of polygon, contour and vertex).
|
|
|
|
*
|
2020-12-12 03:43:16 +00:00
|
|
|
* @param aRelativeIndices is the set of relative indices of the to-be-removed vertex.
|
|
|
|
*/
|
|
|
|
void RemoveVertex( VERTEX_INDEX aRelativeIndices );
|
|
|
|
|
2021-01-25 12:42:36 +00:00
|
|
|
///< Remove all outlines & holes (clears) the polygon set.
|
2020-12-12 03:43:16 +00:00
|
|
|
void RemoveAllContours();
|
|
|
|
|
|
|
|
/**
|
2021-01-25 12:42:36 +00:00
|
|
|
* Delete the \a aContourIdx-th contour of the \a aPolygonIdx-th polygon in the set.
|
|
|
|
*
|
2020-12-12 03:43:16 +00:00
|
|
|
* @param aContourIdx is the index of the contour in the aPolygonIdx-th polygon to be
|
|
|
|
* removed.
|
|
|
|
* @param aPolygonIdx is the index of the polygon in which the to-be-removed contour is.
|
|
|
|
* Defaults to the last polygon in the set.
|
|
|
|
*/
|
|
|
|
void RemoveContour( int aContourIdx, int aPolygonIdx = -1 );
|
|
|
|
|
|
|
|
/**
|
2021-01-25 12:42:36 +00:00
|
|
|
* Look for null segments; ie, segments whose ends are exactly the same and deletes them.
|
|
|
|
*
|
|
|
|
* @return the number of deleted segments.
|
2020-12-12 03:43:16 +00:00
|
|
|
*/
|
|
|
|
int RemoveNullSegments();
|
|
|
|
|
|
|
|
/**
|
2021-01-25 12:42:36 +00:00
|
|
|
* Accessor function to set the position of a specific point.
|
|
|
|
*
|
|
|
|
* @param aIndex #VERTEX_INDEX of the point to move.
|
|
|
|
* @param aPos destination position of the specified point.
|
2020-12-12 03:43:16 +00:00
|
|
|
*/
|
|
|
|
void SetVertex( const VERTEX_INDEX& aIndex, const VECTOR2I& aPos );
|
|
|
|
|
|
|
|
/**
|
2021-01-25 12:42:36 +00:00
|
|
|
* Set the vertex based on the global index.
|
|
|
|
*
|
|
|
|
* Throws if the index doesn't exist.
|
|
|
|
*
|
2020-12-12 03:43:16 +00:00
|
|
|
* @param aGlobalIndex global index of the to-be-moved vertex
|
|
|
|
* @param aPos New position on the vertex
|
|
|
|
*/
|
|
|
|
void SetVertex( int aGlobalIndex, const VECTOR2I& aPos );
|
|
|
|
|
2021-01-25 12:42:36 +00:00
|
|
|
///< Return total number of vertices stored in the set.
|
2020-12-12 03:43:16 +00:00
|
|
|
int TotalVertices() const;
|
|
|
|
|
2021-01-25 12:42:36 +00:00
|
|
|
///< Delete \a aIdx-th polygon from the set.
|
2020-12-12 03:43:16 +00:00
|
|
|
void DeletePolygon( int aIdx );
|
|
|
|
|
2022-02-16 17:00:54 +00:00
|
|
|
///< Delete \a aIdx-th polygon and its triangulation data from the set.
|
|
|
|
///< If called with \a aUpdateHash false, caller must call UpdateTriangulationDataHash().
|
|
|
|
void DeletePolygonAndTriangulationData( int aIdx, bool aUpdateHash = true );
|
|
|
|
|
|
|
|
void UpdateTriangulationDataHash();
|
|
|
|
|
2020-12-12 03:43:16 +00:00
|
|
|
/**
|
2021-01-25 12:42:36 +00:00
|
|
|
* Return a chamfered version of the \a aIndex-th polygon.
|
|
|
|
*
|
2020-12-12 03:43:16 +00:00
|
|
|
* @param aDistance is the chamfering distance.
|
|
|
|
* @param aIndex is the index of the polygon to be chamfered.
|
2021-01-25 12:42:36 +00:00
|
|
|
* @return A polygon containing the chamfered version of the \a aIndex-th polygon.
|
2020-12-12 03:43:16 +00:00
|
|
|
*/
|
|
|
|
POLYGON ChamferPolygon( unsigned int aDistance, int aIndex );
|
|
|
|
|
|
|
|
/**
|
2021-01-25 12:42:36 +00:00
|
|
|
* Return a filleted version of the \a aIndex-th polygon.
|
|
|
|
*
|
2020-12-12 03:43:16 +00:00
|
|
|
* @param aRadius is the fillet radius.
|
|
|
|
* @param aErrorMax is the maximum allowable deviation of the polygon from the circle
|
|
|
|
* @param aIndex is the index of the polygon to be filleted
|
2021-01-25 12:42:36 +00:00
|
|
|
* @return A polygon containing the filleted version of the \a aIndex-th polygon.
|
2020-12-12 03:43:16 +00:00
|
|
|
*/
|
|
|
|
POLYGON FilletPolygon( unsigned int aRadius, int aErrorMax, int aIndex );
|
|
|
|
|
|
|
|
/**
|
2021-01-25 12:42:36 +00:00
|
|
|
* Return a chamfered version of the polygon set.
|
|
|
|
*
|
2020-12-12 03:43:16 +00:00
|
|
|
* @param aDistance is the chamfering distance.
|
2021-01-25 12:42:36 +00:00
|
|
|
* @return A set containing the chamfered version of this set.
|
2020-12-12 03:43:16 +00:00
|
|
|
*/
|
|
|
|
SHAPE_POLY_SET Chamfer( int aDistance );
|
|
|
|
|
|
|
|
/**
|
2021-01-25 12:42:36 +00:00
|
|
|
* Return a filleted version of the polygon set.
|
|
|
|
*
|
2020-12-12 03:43:16 +00:00
|
|
|
* @param aRadius is the fillet radius.
|
|
|
|
* @param aErrorMax is the maximum allowable deviation of the polygon from the circle
|
2021-01-25 12:42:36 +00:00
|
|
|
* @return A set containing the filleted version of this set.
|
2020-12-12 03:43:16 +00:00
|
|
|
*/
|
|
|
|
SHAPE_POLY_SET Fillet( int aRadius, int aErrorMax );
|
|
|
|
|
|
|
|
/**
|
2021-01-25 12:42:36 +00:00
|
|
|
* Compute the minimum distance between the \a aIndex-th polygon and \a aPoint.
|
|
|
|
*
|
2020-12-12 03:43:16 +00:00
|
|
|
* @param aPoint is the point whose distance to the aIndex-th polygon has to be measured.
|
2021-01-25 12:42:36 +00:00
|
|
|
* @param aIndex is the index of the polygon whose distance to aPoint has to be measured.
|
2020-12-12 03:43:16 +00:00
|
|
|
* @param aNearest [out] an optional pointer to be filled in with the point on the
|
|
|
|
* polyset which is closest to aPoint.
|
2021-01-25 12:42:36 +00:00
|
|
|
* @return The minimum distance between \a aPoint and all the segments of the \a aIndex-th
|
|
|
|
* polygon. If the point is contained in the polygon, the distance is zero.
|
2020-12-12 03:43:16 +00:00
|
|
|
*/
|
|
|
|
SEG::ecoord SquaredDistanceToPolygon( VECTOR2I aPoint, int aIndex,
|
|
|
|
VECTOR2I* aNearest ) const;
|
|
|
|
|
|
|
|
/**
|
2021-01-25 12:42:36 +00:00
|
|
|
* Compute the minimum distance between the aIndex-th polygon and aSegment with a
|
2020-12-12 03:43:16 +00:00
|
|
|
* possible width.
|
2021-01-25 12:42:36 +00:00
|
|
|
*
|
2020-12-12 03:43:16 +00:00
|
|
|
* @param aSegment is the segment whose distance to the aIndex-th polygon has to be
|
|
|
|
* measured.
|
2021-01-25 12:42:36 +00:00
|
|
|
* @param aIndex is the index of the polygon whose distance to aPoint has to be measured.
|
2020-12-12 03:43:16 +00:00
|
|
|
* @param aNearest [out] an optional pointer to be filled in with the point on the
|
|
|
|
* polyset which is closest to aSegment.
|
2021-01-25 12:42:36 +00:00
|
|
|
* @return The minimum distance between \a aSegment and all the segments of the \a aIndex-th
|
|
|
|
* polygon. If the point is contained in the polygon, the distance is zero.
|
2020-12-12 03:43:16 +00:00
|
|
|
*/
|
|
|
|
SEG::ecoord SquaredDistanceToPolygon( const SEG& aSegment, int aIndex,
|
|
|
|
VECTOR2I* aNearest) const;
|
|
|
|
|
|
|
|
/**
|
2021-01-25 12:42:36 +00:00
|
|
|
* Compute the minimum distance squared between aPoint and all the polygons in the set.
|
2020-12-12 03:43:16 +00:00
|
|
|
* Squared distances are used because they avoid the cost of doing square-roots.
|
2021-01-25 12:42:36 +00:00
|
|
|
*
|
2020-12-12 03:43:16 +00:00
|
|
|
* @param aPoint is the point whose distance to the set has to be measured.
|
|
|
|
* @param aNearest [out] an optional pointer to be filled in with the point on the
|
|
|
|
* polyset which is closest to aPoint.
|
|
|
|
* @return The minimum distance squared between aPoint and all the polygons in the set.
|
|
|
|
* If the point is contained in any of the polygons, the distance is zero.
|
|
|
|
*/
|
|
|
|
SEG::ecoord SquaredDistance( VECTOR2I aPoint, VECTOR2I* aNearest = nullptr ) const;
|
|
|
|
|
|
|
|
/**
|
2021-01-25 12:42:36 +00:00
|
|
|
* Compute the minimum distance squared between aSegment and all the polygons in the set.
|
2020-12-12 03:43:16 +00:00
|
|
|
* Squared distances are used because they avoid the cost of doing square-roots.
|
2021-01-25 12:42:36 +00:00
|
|
|
*
|
2020-12-12 03:43:16 +00:00
|
|
|
* @param aSegment is the segment whose distance to the polygon set has to be measured.
|
|
|
|
* @param aSegmentWidth is the width of the segment; defaults to zero.
|
|
|
|
* @param aNearest [out] an optional pointer to be filled in with the point on the
|
|
|
|
* polyset which is closest to aSegment.
|
|
|
|
* @return The minimum distance squared between aSegment and all the polygons in the set.
|
|
|
|
* If the point is contained in the polygon, the distance is zero.
|
|
|
|
*/
|
|
|
|
SEG::ecoord SquaredDistance( const SEG& aSegment, VECTOR2I* aNearest = nullptr ) const;
|
|
|
|
|
|
|
|
/**
|
2021-01-25 12:42:36 +00:00
|
|
|
* Check whether the \a aGlobalIndex-th vertex belongs to a hole.
|
|
|
|
*
|
2020-12-12 03:43:16 +00:00
|
|
|
* @param aGlobalIdx is the index of the vertex.
|
2021-01-25 12:42:36 +00:00
|
|
|
* @return true if the globally indexed \a aGlobalIdx-th vertex belongs to a hole.
|
2020-12-12 03:43:16 +00:00
|
|
|
*/
|
|
|
|
bool IsVertexInHole( int aGlobalIdx );
|
|
|
|
|
2021-12-30 02:45:53 +00:00
|
|
|
/**
|
|
|
|
* Build a SHAPE_POLY_SET from a bunch of outlines in provided in random order.
|
2022-05-13 16:09:22 +00:00
|
|
|
*
|
2021-12-30 02:45:53 +00:00
|
|
|
* @param aPath set of closed outlines forming the polygon. Positive orientation = outline, negative = hole
|
|
|
|
* @param aReverseOrientation inverts the sign of the orientation of aPaths (so negative = outline)
|
|
|
|
* @param aEvenOdd forces the even-off fill rule (default is non zero)
|
|
|
|
* @return the constructed poly set
|
|
|
|
*/
|
|
|
|
static const SHAPE_POLY_SET BuildPolysetFromOrientedPaths( const std::vector<SHAPE_LINE_CHAIN>& aPaths, bool aReverseOrientation = false, bool aEvenOdd = false );
|
|
|
|
|
2020-12-12 03:43:16 +00:00
|
|
|
private:
|
2022-03-14 15:52:12 +00:00
|
|
|
enum DROP_TRIANGULATION_FLAG { SINGLETON };
|
|
|
|
|
|
|
|
SHAPE_POLY_SET( const SHAPE_POLY_SET& aOther, DROP_TRIANGULATION_FLAG );
|
|
|
|
|
2020-12-12 03:43:16 +00:00
|
|
|
void fractureSingle( POLYGON& paths );
|
|
|
|
void unfractureSingle ( POLYGON& path );
|
2021-06-19 09:56:22 +00:00
|
|
|
void importTree( ClipperLib::PolyTree* tree,
|
|
|
|
const std::vector<CLIPPER_Z_VALUE>& aZValueBuffer,
|
|
|
|
const std::vector<SHAPE_ARC>& aArcBuffe );
|
2022-10-19 23:25:45 +00:00
|
|
|
void importTree( Clipper2Lib::PolyTree64& tree,
|
|
|
|
const std::vector<CLIPPER_Z_VALUE>& aZValueBuffer,
|
|
|
|
const std::vector<SHAPE_ARC>& aArcBuffe );
|
2022-10-28 23:57:57 +00:00
|
|
|
void importPaths( Clipper2Lib::Paths64& paths,
|
2022-10-19 23:25:45 +00:00
|
|
|
const std::vector<CLIPPER_Z_VALUE>& aZValueBuffer,
|
|
|
|
const std::vector<SHAPE_ARC>& aArcBuffe );
|
2022-10-21 23:13:01 +00:00
|
|
|
void importPolyPath( Clipper2Lib::PolyPath64* aPolyPath,
|
|
|
|
const std::vector<CLIPPER_Z_VALUE>& aZValueBuffer,
|
|
|
|
const std::vector<SHAPE_ARC>& aArcBuffer );
|
2022-10-19 23:25:45 +00:00
|
|
|
|
|
|
|
void inflate1( int aAmount, int aCircleSegCount, CORNER_STRATEGY aCornerStrategy );
|
|
|
|
void inflate2( int aAmount, int aCircleSegCount, CORNER_STRATEGY aCornerStrategy );
|
2020-12-12 03:43:16 +00:00
|
|
|
|
2021-01-25 12:42:36 +00:00
|
|
|
/**
|
|
|
|
* This is the engine to execute all polygon boolean transforms (AND, OR, ... and polygon
|
|
|
|
* simplification (merging overlapping polygons).
|
|
|
|
*
|
2020-12-12 03:43:16 +00:00
|
|
|
* @param aType is the transform type ( see ClipperLib::ClipType )
|
|
|
|
* @param aOtherShape is the SHAPE_LINE_CHAIN to combine with me.
|
|
|
|
* @param aFastMode is an option to choose if the result can be a weak polygon
|
2021-01-25 12:42:36 +00:00
|
|
|
* or a strictly simple polygon.
|
2020-12-12 03:43:16 +00:00
|
|
|
* if aFastMode is PM_FAST the result can be a weak polygon
|
2021-01-25 12:42:36 +00:00
|
|
|
* if aFastMode is PM_STRICTLY_SIMPLE (default) the result is (theoretically) a strictly
|
2020-12-12 03:43:16 +00:00
|
|
|
* simple polygon, but calculations can be really significantly time consuming
|
|
|
|
*/
|
|
|
|
void booleanOp( ClipperLib::ClipType aType, const SHAPE_POLY_SET& aOtherShape,
|
|
|
|
POLYGON_MODE aFastMode );
|
|
|
|
|
|
|
|
void booleanOp( ClipperLib::ClipType aType, const SHAPE_POLY_SET& aShape,
|
|
|
|
const SHAPE_POLY_SET& aOtherShape, POLYGON_MODE aFastMode );
|
|
|
|
|
2022-10-19 23:25:45 +00:00
|
|
|
void booleanOp( Clipper2Lib::ClipType aType, const SHAPE_POLY_SET& aOtherShape );
|
|
|
|
|
|
|
|
void booleanOp( Clipper2Lib::ClipType aType, const SHAPE_POLY_SET& aShape,
|
|
|
|
const SHAPE_POLY_SET& aOtherShape );
|
|
|
|
|
2020-12-12 03:43:16 +00:00
|
|
|
/**
|
2021-01-25 12:42:36 +00:00
|
|
|
* Check whether the point \a aP is inside the \a aSubpolyIndex-th polygon of the polyset. If
|
2020-12-12 03:43:16 +00:00
|
|
|
* the points lies on an edge, the polygon is considered to contain it.
|
2021-01-25 12:42:36 +00:00
|
|
|
*
|
|
|
|
* @param aP is the #VECTOR2I point whose position with respect to the inside of
|
2020-12-12 03:43:16 +00:00
|
|
|
* the aSubpolyIndex-th polygon will be tested.
|
|
|
|
* @param aSubpolyIndex is an integer specifying which polygon in the set has to be
|
|
|
|
* checked.
|
|
|
|
* @param aAccuracy accuracy in internal units
|
|
|
|
* @param aUseBBoxCaches gives faster performance when multiple calls are made with no
|
|
|
|
* editing in between, but the caller MUST cache the bbox caches
|
|
|
|
* before calling (via BuildBBoxCaches(), above)
|
2021-01-25 12:42:36 +00:00
|
|
|
* @return true if \a aP is inside aSubpolyIndex-th polygon; false in any other case.
|
2020-12-12 03:43:16 +00:00
|
|
|
*/
|
|
|
|
bool containsSingle( const VECTOR2I& aP, int aSubpolyIndex, int aAccuracy,
|
|
|
|
bool aUseBBoxCaches = false ) const;
|
|
|
|
|
|
|
|
/**
|
2021-01-25 12:42:36 +00:00
|
|
|
* Operation ChamferPolygon and FilletPolygon are computed under the private chamferFillet
|
2020-12-12 03:43:16 +00:00
|
|
|
* method; this enum is defined to make the necessary distinction when calling this method
|
|
|
|
* from the public ChamferPolygon and FilletPolygon methods.
|
|
|
|
*/
|
|
|
|
enum CORNER_MODE
|
|
|
|
{
|
|
|
|
CHAMFERED,
|
|
|
|
FILLETED
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2021-01-25 12:42:36 +00:00
|
|
|
* Return the chamfered or filleted version of the \a aIndex-th polygon in the set, depending
|
|
|
|
* on the \a aMode selected
|
2020-12-12 03:43:16 +00:00
|
|
|
* @param aMode represent which action will be taken: CORNER_MODE::CHAMFERED will
|
|
|
|
* return a chamfered version of the polygon, CORNER_MODE::FILLETED will
|
|
|
|
* return a filleted version of the polygon.
|
|
|
|
* @param aDistance is the chamfering distance if aMode = CHAMFERED; if aMode = FILLETED,
|
|
|
|
* is the filleting radius.
|
|
|
|
* @param aIndex is the index of the polygon that will be chamfered/filleted.
|
|
|
|
* @param aErrorMax is the maximum allowable deviation of the polygon from the circle
|
|
|
|
* if aMode = FILLETED. If aMode = CHAMFERED, it is unused.
|
2021-01-25 12:42:36 +00:00
|
|
|
* @return the chamfered/filleted version of the polygon.
|
2020-12-12 03:43:16 +00:00
|
|
|
*/
|
|
|
|
POLYGON chamferFilletPolygon( CORNER_MODE aMode, unsigned int aDistance,
|
|
|
|
int aIndex, int aErrorMax );
|
|
|
|
|
2021-01-25 12:42:36 +00:00
|
|
|
///< Return true if the polygon set has any holes that touch share a vertex.
|
2020-12-12 03:43:16 +00:00
|
|
|
bool hasTouchingHoles( const POLYGON& aPoly ) const;
|
|
|
|
|
|
|
|
MD5_HASH checksum() const;
|
|
|
|
|
|
|
|
private:
|
2022-02-14 17:19:28 +00:00
|
|
|
std::vector<POLYGON> m_polys;
|
2020-12-12 03:43:16 +00:00
|
|
|
std::vector<std::unique_ptr<TRIANGULATED_POLYGON>> m_triangulatedPolys;
|
|
|
|
|
|
|
|
bool m_triangulationValid = false;
|
|
|
|
MD5_HASH m_hash;
|
2015-06-12 15:12:02 +00:00
|
|
|
};
|
|
|
|
|
2021-03-06 09:27:41 +00:00
|
|
|
#endif // __SHAPE_POLY_SET_H
|