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>
|
2020-12-11 13:51:42 +00:00
|
|
|
* Copyright (C) 1992-2020 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 polygon_2d.h
|
2015-12-08 07:31:57 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _CPOLYGON2D_H_
|
|
|
|
#define _CPOLYGON2D_H_
|
|
|
|
|
2021-01-03 22:23:00 +00:00
|
|
|
#include "object_2d.h"
|
|
|
|
#include "../accelerators/container_2d.h"
|
2015-12-08 07:31:57 +00:00
|
|
|
#include <geometry/shape_poly_set.h>
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
|
2021-07-01 22:28:41 +00:00
|
|
|
struct POLYSEGMENT
|
2015-12-08 07:31:57 +00:00
|
|
|
{
|
|
|
|
SFVEC2F m_Start;
|
2021-06-10 08:34:27 +00:00
|
|
|
float m_inv_JY_minus_IY = 0.0;
|
|
|
|
float m_JX_minus_IX = 0.0;
|
2021-07-01 22:28:41 +00:00
|
|
|
};
|
2015-12-08 07:31:57 +00:00
|
|
|
|
|
|
|
|
2021-07-01 22:28:41 +00:00
|
|
|
struct SEG_NORMALS
|
2015-12-08 07:31:57 +00:00
|
|
|
{
|
|
|
|
SFVEC2F m_Start;
|
|
|
|
SFVEC2F m_End;
|
2021-07-01 22:28:41 +00:00
|
|
|
};
|
2015-12-08 07:31:57 +00:00
|
|
|
|
|
|
|
|
2021-07-01 22:28:41 +00:00
|
|
|
struct SEGMENT_WITH_NORMALS
|
2015-12-08 07:31:57 +00:00
|
|
|
{
|
|
|
|
SFVEC2F m_Start;
|
|
|
|
SFVEC2F m_Precalc_slope;
|
|
|
|
SEG_NORMALS m_Normals;
|
2021-07-01 22:28:41 +00:00
|
|
|
};
|
2015-12-08 07:31:57 +00:00
|
|
|
|
|
|
|
|
|
|
|
typedef std::vector< POLYSEGMENT > SEGMENTS;
|
|
|
|
|
|
|
|
|
2020-12-11 13:51:42 +00:00
|
|
|
/**
|
|
|
|
* List used to test ray2d intersections.
|
|
|
|
*
|
|
|
|
* It will be a subset of an original polygon. The normals will be passed already interpolated.
|
|
|
|
*/
|
2015-12-08 07:31:57 +00:00
|
|
|
typedef std::vector< SEGMENT_WITH_NORMALS > SEGMENTS_WIDTH_NORMALS;
|
|
|
|
|
|
|
|
|
2020-12-11 13:51:42 +00:00
|
|
|
/**
|
|
|
|
* Handle a subset of a polygon.
|
|
|
|
*
|
|
|
|
* It can contain multiple closed polygons and holes and us used to test if points are inside.
|
|
|
|
* A point will be inside the polygon if it is not inside a hole and it is inside an outer polygon.
|
|
|
|
*/
|
2021-07-01 22:28:41 +00:00
|
|
|
struct OUTERS_AND_HOLES
|
2015-12-08 07:31:57 +00:00
|
|
|
{
|
|
|
|
std::vector<SEGMENTS> m_Outers;
|
|
|
|
std::vector<SEGMENTS> m_Holes;
|
2021-07-01 22:28:41 +00:00
|
|
|
};
|
2015-12-08 07:31:57 +00:00
|
|
|
|
|
|
|
|
2020-12-11 13:51:42 +00:00
|
|
|
/**
|
|
|
|
* Represent a sub polygon block.
|
|
|
|
*
|
|
|
|
* This polygon block was created from a general polygon definition that was sub divided and
|
|
|
|
* to create blocks of polygons. This polygon class represent a sub part of that main polygon.
|
|
|
|
* There is information for the contours (used to test the ray2d intersection) and a close
|
|
|
|
* definition of the block polygon to test if a point is inside.
|
|
|
|
*/
|
2021-01-02 21:05:29 +00:00
|
|
|
class POLYGON_2D : public OBJECT_2D
|
2015-12-08 07:31:57 +00:00
|
|
|
{
|
|
|
|
public:
|
2021-01-02 21:05:29 +00:00
|
|
|
POLYGON_2D( const SEGMENTS_WIDTH_NORMALS& aOpenSegmentList,
|
2021-01-07 19:33:43 +00:00
|
|
|
const OUTERS_AND_HOLES& aOuterAndHoles, const BOARD_ITEM& aBoardItem );
|
2015-12-08 07:31:57 +00:00
|
|
|
|
2021-01-02 21:05:29 +00:00
|
|
|
bool Overlaps( const BBOX_2D& aBBox ) const override;
|
|
|
|
bool Intersects( const BBOX_2D& aBBox ) const override;
|
|
|
|
bool Intersect( const RAYSEG2D& aSegRay, float* aOutT, SFVEC2F* aNormalOut ) const override;
|
|
|
|
INTERSECTION_RESULT IsBBoxInside( const BBOX_2D& aBBox ) const override;
|
|
|
|
bool IsPointInside( const SFVEC2F& aPoint ) const override;
|
2020-12-11 13:51:42 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
/**
|
|
|
|
* The outer part of the polygon.
|
|
|
|
*
|
|
|
|
* This list is used to test a ray intersection with the boundaries of this sub polygon.
|
|
|
|
* It contains also the interpolated normals that are passed from the main polygon.
|
|
|
|
*/
|
|
|
|
SEGMENTS_WIDTH_NORMALS m_open_segments;
|
|
|
|
|
|
|
|
///< A polygon block can have multiple polygon and holes
|
|
|
|
OUTERS_AND_HOLES m_outers_and_holes;
|
2015-12-08 07:31:57 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2020-12-11 13:51:42 +00:00
|
|
|
/**
|
|
|
|
* A dummy block defined by a 2d box size.
|
|
|
|
*
|
|
|
|
* If the point is inside the bounding box it will return always true. However, the
|
|
|
|
* intersection with a ray will return always false. This is used as a sub block
|
2021-01-02 21:05:29 +00:00
|
|
|
* extracted from polygon (pcb polygon areas) and represents an area that is fully filled.
|
2020-12-11 13:51:42 +00:00
|
|
|
*/
|
2021-01-02 21:05:29 +00:00
|
|
|
class DUMMY_BLOCK_2D : public OBJECT_2D
|
2015-12-08 07:31:57 +00:00
|
|
|
{
|
|
|
|
public:
|
2021-01-02 21:05:29 +00:00
|
|
|
DUMMY_BLOCK_2D( const SFVEC2F& aPbMin, const SFVEC2F& aPbMax, const BOARD_ITEM& aBoardItem );
|
|
|
|
|
|
|
|
DUMMY_BLOCK_2D( const BBOX_2D& aBBox, const BOARD_ITEM& aBoardItem );
|
|
|
|
|
|
|
|
bool Overlaps( const BBOX_2D& aBBox ) const override;
|
|
|
|
bool Intersects( const BBOX_2D& aBBox ) const override;
|
|
|
|
bool Intersect( const RAYSEG2D& aSegRay, float* aOutT, SFVEC2F* aNormalOut ) const override;
|
|
|
|
INTERSECTION_RESULT IsBBoxInside( const BBOX_2D& aBBox ) const override;
|
|
|
|
bool IsPointInside( const SFVEC2F& aPoint ) const override;
|
2015-12-08 07:31:57 +00:00
|
|
|
};
|
|
|
|
|
2020-12-11 13:51:42 +00:00
|
|
|
|
2015-12-08 07:31:57 +00:00
|
|
|
/**
|
2020-12-11 13:51:42 +00:00
|
|
|
* Use a polygon in the format of the ClipperLib::Path and process it and create multiple 2d
|
2021-01-02 21:05:29 +00:00
|
|
|
* objects (POLYGON_2D and DUMMY_BLOCK_2D) that can be used to represent this polygon area.
|
2020-12-11 13:51:42 +00:00
|
|
|
*
|
|
|
|
* @param aMainPath the polygon are that was converted from the pcb board
|
|
|
|
* @param aDstContainer the destination container to put the created sub blocks
|
2021-01-05 22:19:00 +00:00
|
|
|
* @param aBiuTo3dUnitsScale the rendering target 3d scale
|
2020-12-11 13:51:42 +00:00
|
|
|
* @param aDivFactor a division factor (in 3Dunits) to divide the polygon plane,
|
|
|
|
* 0.0f will use the internal polygon segm statistics
|
2015-12-08 07:31:57 +00:00
|
|
|
*/
|
2021-06-10 01:24:15 +00:00
|
|
|
void ConvertPolygonToBlocks( const SHAPE_POLY_SET& aMainPath, CONTAINER_2D_BASE& aDstContainer,
|
2021-01-05 22:19:00 +00:00
|
|
|
float aBiuTo3dUnitsScale, float aDivFactor,
|
|
|
|
const BOARD_ITEM& aBoardItem, int aPolyIndex );
|
2015-12-08 07:31:57 +00:00
|
|
|
|
|
|
|
void Polygon2d_TestModule();
|
|
|
|
|
|
|
|
#endif // _CPOLYGON2D_H_
|