File: cpolygon2d.h

package info (click to toggle)
kicad 5.0.2%2Bdfsg1-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 234,592 kB
  • sloc: cpp: 505,330; ansic: 57,038; python: 4,886; sh: 879; awk: 294; makefile: 253; xml: 103; perl: 5
file content (165 lines) | stat: -rw-r--r-- 6,024 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
/*
 * This program source code file is part of KiCad, a free EDA CAD application.
 *
 * Copyright (C) 2015-2016 Mario Luzeiro <mrluzeiro@ua.pt>
 * Copyright (C) 1992-2016 KiCad Developers, see AUTHORS.txt for contributors.
 *
 * 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
 */

/**
 * @file  cpolygon2d.h
 * @brief
 */

#ifndef _CPOLYGON2D_H_
#define _CPOLYGON2D_H_

#include "cobject2d.h"
#include "../accelerators/ccontainer2d.h"
#include <geometry/shape_poly_set.h>
#include <polygons_defs.h>
#include <vector>


typedef struct
{
    SFVEC2F m_Start;
    float   m_inv_JY_minus_IY;
    float   m_JX_minus_IX;
}POLYSEGMENT;


typedef struct
{
    SFVEC2F m_Start;
    SFVEC2F m_End;
}SEG_NORMALS;


typedef struct
{
    SFVEC2F     m_Start;
    SFVEC2F     m_Precalc_slope;
    SEG_NORMALS m_Normals;
}SEGMENT_WITH_NORMALS;


typedef std::vector< POLYSEGMENT > SEGMENTS;


/// This list will be used to test ray2d intersections. It will be a subset
/// of an original polygon. The normals will be passed already interpolated.
typedef std::vector< SEGMENT_WITH_NORMALS > SEGMENTS_WIDTH_NORMALS;


/// This structured will be used to handle a sub set of a polygon.
/// It can contain multiple closed polygons and holes.
/// It will be 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 a Outer polygon.
typedef struct
{
    std::vector<SEGMENTS> m_Outers;
    std::vector<SEGMENTS> m_Holes;
}OUTERS_AND_HOLES;


/// This class represents a sub polygon block. This polygon block was created
/// from a general polygon definition that was sub divided and 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.
class  CPOLYGONBLOCK2D : public COBJECT2D
{
private:
    /// This is the outter 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;

public:
    CPOLYGONBLOCK2D( const SEGMENTS_WIDTH_NORMALS &aOpenSegmentList,
                     const OUTERS_AND_HOLES &aOuter_and_holes,
                     const BOARD_ITEM &aBoardItem );

    // Imported from COBJECT2D
    bool Overlaps( const CBBOX2D &aBBox ) const override;
    bool Intersects( const CBBOX2D &aBBox ) const override;
    bool Intersect( const RAYSEG2D &aSegRay, float *aOutT, SFVEC2F *aNormalOut ) const override;
    INTERSECTION_RESULT IsBBoxInside( const CBBOX2D &aBBox ) const override;
    bool IsPointInside( const SFVEC2F &aPoint ) const override;
};


/// This dummy block will be defined by a 2d box size. If the point is inside
/// the bounding box it will return allways true. However, the intersection with
/// a ray will return allways false.
/// This is used as a sub block extrated from polygon (pcb polygon areas) and
/// represents an area that is full filled.
class  CDUMMYBLOCK2D : public COBJECT2D
{

public:
    CDUMMYBLOCK2D( const SFVEC2F &aPbMin,
                   const SFVEC2F &aPbMax,
                   const BOARD_ITEM &aBoardItem );

    CDUMMYBLOCK2D( const CBBOX2D &aBBox, const BOARD_ITEM &aBoardItem );

     // Imported from COBJECT2D
     bool Overlaps( const CBBOX2D &aBBox ) const override;
     bool Intersects( const CBBOX2D &aBBox ) const override;
     bool Intersect( const RAYSEG2D &aSegRay, float *aOutT, SFVEC2F *aNormalOut ) const override;
     INTERSECTION_RESULT IsBBoxInside( const CBBOX2D &aBBox ) const override;
     bool IsPointInside( const SFVEC2F &aPoint ) const override;
};

/**
 * @brief Convert_path_polygon_to_polygon_blocks_and_dummy_blocks
 * This function will use a polygon in the format of the ClipperLib::Path
 * will process it and will create multiple 2d objects (CPOLYGONBLOCK2D and
 * CDUMMYBLOCK2D) that can be used to represent this polygon area.
 * @param aMainPath - the polygon are that was converted from the pcb board
 * @param aDstContainer - the destination container to put the created sub blocks
 * @param aBiuTo3DunitsScale - the rendering target 3d scale
 * @param aDivFactor - a division factor (in 3Dunits) to divide the polygon plane,
 * 0.0f will use the internal polygon segm statistics
 */
void Convert_path_polygon_to_polygon_blocks_and_dummy_blocks(
        const SHAPE_POLY_SET &aMainPath,
        CGENERICCONTAINER2D &aDstContainer,
        float aBiuTo3DunitsScale,
        float aDivFactor,
        const BOARD_ITEM &aBoardItem );

void Polygon_Calc_BBox_3DU( const SHAPE_POLY_SET &aPolysList,
                            CBBOX2D &aOutBBox,
                            float aBiuTo3DunitsScale );

void Polygon_Convert( const KI_POLYGON &aPolygon,
                      ClipperLib::Path &aOutPath,
                      CBBOX2D &aOutBBox,
                      float aBiuTo3DunitsScale );

void Polygon2d_TestModule();

#endif // _CPOLYGON2D_H_