2017-01-13 17:51:22 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2018-08-28 15:48:13 +00:00
|
|
|
* Copyright (C) 2018 Jean-Pierre Charras, jp.charras at wanadoo.fr
|
2019-05-22 13:33:48 +00:00
|
|
|
* Copyright (C) 1992-2019 KiCad Developers, see AUTHORS.txt for contributors.
|
2017-01-13 17:51:22 +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
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @file class_pad_custom_shape_functions.cpp
|
|
|
|
* class D_PAD functions specific to custom shaped pads.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <fctsys.h>
|
|
|
|
#include <trigo.h>
|
|
|
|
|
|
|
|
#include <pcbnew.h>
|
|
|
|
|
2019-05-22 14:47:38 +00:00
|
|
|
#include <bezier_curves.h>
|
|
|
|
#include <class_board.h>
|
2019-07-11 08:48:11 +00:00
|
|
|
#include <class_board_item.h>
|
2017-01-13 17:51:22 +00:00
|
|
|
#include <class_drawsegment.h>
|
2017-10-21 06:48:26 +00:00
|
|
|
#include <class_edge_mod.h>
|
2019-05-22 14:47:38 +00:00
|
|
|
#include <class_pad.h>
|
2017-01-13 17:51:22 +00:00
|
|
|
#include <convert_basic_shapes_to_polygon.h>
|
|
|
|
#include <geometry/convex_hull.h>
|
2019-04-14 17:58:35 +00:00
|
|
|
#include <geometry/geometry_utils.h>
|
2019-05-22 14:47:38 +00:00
|
|
|
#include <geometry/shape_rect.h>
|
2017-01-13 17:51:22 +00:00
|
|
|
|
|
|
|
|
|
|
|
void PAD_CS_PRIMITIVE::ExportTo( DRAWSEGMENT* aTarget )
|
|
|
|
{
|
|
|
|
aTarget->SetShape( m_Shape );
|
|
|
|
aTarget->SetWidth( m_Thickness );
|
|
|
|
aTarget->SetStart( m_Start );
|
|
|
|
aTarget->SetEnd( m_End );
|
2019-04-14 17:58:35 +00:00
|
|
|
aTarget->SetBezControl1( m_Ctrl1 );
|
|
|
|
aTarget->SetBezControl2( m_Ctrl2 );
|
2017-01-13 17:51:22 +00:00
|
|
|
|
|
|
|
// in a DRAWSEGMENT the radius of a circle is calculated from the
|
|
|
|
// center and one point on the circle outline (stored in m_End)
|
|
|
|
if( m_Shape == S_CIRCLE )
|
|
|
|
{
|
|
|
|
wxPoint end = m_Start;
|
|
|
|
end.x += m_Radius;
|
|
|
|
aTarget->SetEnd( end );
|
|
|
|
}
|
|
|
|
|
|
|
|
aTarget->SetAngle( m_ArcAngle );
|
|
|
|
aTarget->SetPolyPoints( m_Poly );
|
|
|
|
}
|
|
|
|
|
2017-10-21 06:48:26 +00:00
|
|
|
|
|
|
|
void PAD_CS_PRIMITIVE::ExportTo( EDGE_MODULE* aTarget )
|
|
|
|
{
|
|
|
|
ExportTo( static_cast<DRAWSEGMENT*>( aTarget ) );
|
|
|
|
// Initialize coordinates specific to the EDGE_MODULE (m_Start0 and m_End0)
|
|
|
|
aTarget->SetLocalCoord();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-10-21 09:00:59 +00:00
|
|
|
void PAD_CS_PRIMITIVE::Move( wxPoint aMoveVector )
|
|
|
|
{
|
|
|
|
m_Start += aMoveVector;
|
|
|
|
m_End += aMoveVector;
|
2019-04-14 17:58:35 +00:00
|
|
|
m_Ctrl1 += aMoveVector;
|
|
|
|
m_Ctrl2 += aMoveVector;
|
2017-10-21 09:00:59 +00:00
|
|
|
|
|
|
|
for( auto& corner : m_Poly )
|
|
|
|
{
|
|
|
|
corner += aMoveVector;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-07-11 08:48:11 +00:00
|
|
|
void PAD_CS_PRIMITIVE::Rotate( const wxPoint& aRotCentre, double aAngle )
|
|
|
|
{
|
|
|
|
switch( m_Shape )
|
|
|
|
{
|
|
|
|
case S_ARC:
|
|
|
|
case S_SEGMENT:
|
|
|
|
case S_CIRCLE:
|
|
|
|
// these can all be done by just rotating the start and end points
|
|
|
|
RotatePoint( &m_Start, aRotCentre, aAngle );
|
|
|
|
RotatePoint( &m_End, aRotCentre, aAngle );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case S_POLYGON:
|
|
|
|
for( auto& pt : m_Poly )
|
|
|
|
RotatePoint( &pt, aRotCentre, aAngle );
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case S_CURVE:
|
|
|
|
RotatePoint( &m_Start, aRotCentre, aAngle );
|
|
|
|
RotatePoint( &m_End, aRotCentre, aAngle );
|
|
|
|
RotatePoint( &m_Ctrl1, aRotCentre, aAngle );
|
|
|
|
RotatePoint( &m_Ctrl2, aRotCentre, aAngle );
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case S_RECT:
|
|
|
|
default:
|
|
|
|
// un-handled edge transform
|
|
|
|
wxASSERT_MSG( false, wxT( "PAD_CS_PRIMITIVE::Rotate not implemented for "
|
|
|
|
+ BOARD_ITEM::ShowShape( m_Shape ) ) );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-01-13 17:51:22 +00:00
|
|
|
/*
|
|
|
|
* Has meaning only for free shape pads.
|
|
|
|
* add a free shape to the shape list.
|
|
|
|
* the shape is a polygon (can be with thick outline), segment, circle or arc
|
|
|
|
*/
|
2017-10-19 21:16:06 +00:00
|
|
|
|
|
|
|
void D_PAD::AddPrimitive( const SHAPE_POLY_SET& aPoly, int aThickness )
|
|
|
|
{
|
|
|
|
std::vector<wxPoint> points;
|
|
|
|
|
2018-08-28 15:48:13 +00:00
|
|
|
// If aPoly has holes, convert it to a polygon with no holes.
|
|
|
|
SHAPE_POLY_SET poly_no_hole;
|
|
|
|
poly_no_hole.Append( aPoly );
|
|
|
|
poly_no_hole.Fracture( SHAPE_POLY_SET::PM_STRICTLY_SIMPLE );
|
|
|
|
|
|
|
|
for( auto iter = poly_no_hole.CIterate(); iter; iter++ )
|
2017-10-19 21:16:06 +00:00
|
|
|
points.push_back( wxPoint( iter->x, iter->y ) );
|
|
|
|
|
|
|
|
AddPrimitive( points, aThickness );
|
|
|
|
}
|
|
|
|
|
|
|
|
void D_PAD::AddPrimitive( const std::vector<wxPoint>& aPoly, int aThickness )
|
2017-01-13 17:51:22 +00:00
|
|
|
{
|
|
|
|
PAD_CS_PRIMITIVE shape( S_POLYGON );
|
|
|
|
shape.m_Poly = aPoly;
|
|
|
|
shape.m_Thickness = aThickness;
|
|
|
|
m_basicShapes.push_back( shape );
|
|
|
|
|
2017-09-20 08:28:52 +00:00
|
|
|
MergePrimitivesAsPolygon();
|
2017-01-13 17:51:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-09-20 08:28:52 +00:00
|
|
|
void D_PAD::AddPrimitive( wxPoint aStart, wxPoint aEnd, int aThickness )
|
2017-01-13 17:51:22 +00:00
|
|
|
{
|
|
|
|
PAD_CS_PRIMITIVE shape( S_SEGMENT );
|
|
|
|
shape.m_Start = aStart;
|
|
|
|
shape.m_End = aEnd;
|
|
|
|
shape.m_Thickness = aThickness;
|
|
|
|
m_basicShapes.push_back( shape );
|
|
|
|
|
2017-09-20 08:28:52 +00:00
|
|
|
MergePrimitivesAsPolygon();
|
2017-01-13 17:51:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-09-20 08:28:52 +00:00
|
|
|
void D_PAD::AddPrimitive( wxPoint aCenter, wxPoint aStart, int aArcAngle, int aThickness )
|
2017-01-13 17:51:22 +00:00
|
|
|
{
|
|
|
|
PAD_CS_PRIMITIVE shape( S_ARC );
|
|
|
|
shape.m_Start = aCenter;
|
|
|
|
shape.m_End = aStart;
|
|
|
|
shape.m_ArcAngle = aArcAngle;
|
|
|
|
shape.m_Thickness = aThickness;
|
|
|
|
m_basicShapes.push_back( shape );
|
|
|
|
|
2017-09-20 08:28:52 +00:00
|
|
|
MergePrimitivesAsPolygon();
|
2017-01-13 17:51:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-04-14 17:58:35 +00:00
|
|
|
void D_PAD::AddPrimitive( wxPoint aStart, wxPoint aEnd, wxPoint aCtrl1, wxPoint aCtrl2, int aThickness )
|
|
|
|
{
|
|
|
|
PAD_CS_PRIMITIVE shape( S_CURVE );
|
|
|
|
shape.m_Start = aStart;
|
|
|
|
shape.m_End = aEnd;
|
|
|
|
shape.m_Ctrl1 = aCtrl1;
|
|
|
|
shape.m_Ctrl2 = aCtrl2;
|
|
|
|
shape.m_Thickness = aThickness;
|
|
|
|
m_basicShapes.push_back( shape );
|
|
|
|
|
|
|
|
MergePrimitivesAsPolygon();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-09-20 08:28:52 +00:00
|
|
|
void D_PAD::AddPrimitive( wxPoint aCenter, int aRadius, int aThickness )
|
2017-01-13 17:51:22 +00:00
|
|
|
{
|
|
|
|
PAD_CS_PRIMITIVE shape( S_CIRCLE );
|
|
|
|
shape.m_Start = aCenter;
|
|
|
|
shape.m_Radius = aRadius;
|
|
|
|
shape.m_Thickness = aThickness;
|
|
|
|
m_basicShapes.push_back( shape );
|
|
|
|
|
2017-09-20 08:28:52 +00:00
|
|
|
MergePrimitivesAsPolygon();
|
2017-01-13 17:51:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-09-20 08:28:52 +00:00
|
|
|
bool D_PAD::SetPrimitives( const std::vector<PAD_CS_PRIMITIVE>& aPrimitivesList )
|
2017-01-13 17:51:22 +00:00
|
|
|
{
|
|
|
|
// clear old list
|
|
|
|
m_basicShapes.clear();
|
|
|
|
|
|
|
|
// Import to the basic shape list
|
2017-09-20 08:28:52 +00:00
|
|
|
if( aPrimitivesList.size() )
|
|
|
|
m_basicShapes = aPrimitivesList;
|
2017-01-13 17:51:22 +00:00
|
|
|
|
|
|
|
// Only one polygon is expected (pad area = only one copper area)
|
2017-09-20 08:28:52 +00:00
|
|
|
return MergePrimitivesAsPolygon();
|
2017-01-13 17:51:22 +00:00
|
|
|
}
|
|
|
|
|
2018-03-06 13:58:25 +00:00
|
|
|
bool D_PAD::AddPrimitives( const std::vector<PAD_CS_PRIMITIVE>& aPrimitivesList )
|
|
|
|
{
|
|
|
|
for( const auto& prim : aPrimitivesList )
|
|
|
|
m_basicShapes.push_back( prim );
|
|
|
|
|
|
|
|
return MergePrimitivesAsPolygon();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-01-13 17:51:22 +00:00
|
|
|
// clear the basic shapes list and associated data
|
2017-09-20 08:28:52 +00:00
|
|
|
void D_PAD::DeletePrimitivesList()
|
2017-01-13 17:51:22 +00:00
|
|
|
{
|
|
|
|
m_basicShapes.clear();
|
|
|
|
m_customShapeAsPolygon.RemoveAllContours();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-05-14 12:39:34 +00:00
|
|
|
bool D_PAD::buildCustomPadPolygon( SHAPE_POLY_SET* aMergedPolygon, int aError )
|
2017-01-13 17:51:22 +00:00
|
|
|
|
2017-10-19 21:16:06 +00:00
|
|
|
{
|
2017-01-13 17:51:22 +00:00
|
|
|
SHAPE_POLY_SET aux_polyset;
|
|
|
|
|
|
|
|
for( unsigned cnt = 0; cnt < m_basicShapes.size(); ++cnt )
|
|
|
|
{
|
|
|
|
const PAD_CS_PRIMITIVE& bshape = m_basicShapes[cnt];
|
|
|
|
|
|
|
|
switch( bshape.m_Shape )
|
|
|
|
{
|
2019-04-14 17:58:35 +00:00
|
|
|
case S_CURVE:
|
|
|
|
{
|
|
|
|
std::vector<wxPoint> ctrlPoints = { bshape.m_Start, bshape.m_Ctrl1, bshape.m_Ctrl2, bshape.m_End };
|
|
|
|
BEZIER_POLY converter( ctrlPoints );
|
|
|
|
std::vector< wxPoint> poly;
|
|
|
|
converter.GetPoly( poly, bshape.m_Thickness );
|
|
|
|
|
|
|
|
for( unsigned ii = 1; ii < poly.size(); ii++ )
|
|
|
|
{
|
2019-05-14 12:39:34 +00:00
|
|
|
TransformRoundedEndsSegmentToPolygon(
|
2019-05-22 13:33:48 +00:00
|
|
|
aux_polyset, poly[ii - 1], poly[ii], aError, bshape.m_Thickness );
|
2019-04-14 17:58:35 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2017-01-13 17:51:22 +00:00
|
|
|
case S_SEGMENT: // usual segment : line with rounded ends
|
2019-05-14 12:39:34 +00:00
|
|
|
{
|
|
|
|
TransformRoundedEndsSegmentToPolygon(
|
2019-05-22 13:33:48 +00:00
|
|
|
aux_polyset, bshape.m_Start, bshape.m_End, aError, bshape.m_Thickness );
|
2017-01-13 17:51:22 +00:00
|
|
|
break;
|
2019-05-14 12:39:34 +00:00
|
|
|
}
|
2017-01-13 17:51:22 +00:00
|
|
|
|
|
|
|
case S_ARC: // Arc with rounded ends
|
2019-05-14 12:39:34 +00:00
|
|
|
{
|
|
|
|
TransformArcToPolygon( aux_polyset, bshape.m_Start, bshape.m_End, bshape.m_ArcAngle,
|
2019-05-22 13:33:48 +00:00
|
|
|
aError, bshape.m_Thickness );
|
2017-01-13 17:51:22 +00:00
|
|
|
break;
|
2019-05-14 12:39:34 +00:00
|
|
|
}
|
2017-01-13 17:51:22 +00:00
|
|
|
|
|
|
|
case S_CIRCLE: // ring or circle
|
2019-05-14 12:39:34 +00:00
|
|
|
{
|
2017-01-13 17:51:22 +00:00
|
|
|
if( bshape.m_Thickness ) // ring
|
2019-05-14 12:39:34 +00:00
|
|
|
TransformRingToPolygon(
|
2019-05-22 13:33:48 +00:00
|
|
|
aux_polyset, bshape.m_Start, bshape.m_Radius, aError, bshape.m_Thickness );
|
2017-01-13 17:51:22 +00:00
|
|
|
else // Filled circle
|
2019-05-22 13:33:48 +00:00
|
|
|
TransformCircleToPolygon( aux_polyset, bshape.m_Start, bshape.m_Radius, aError );
|
2017-01-13 17:51:22 +00:00
|
|
|
break;
|
2019-05-14 12:39:34 +00:00
|
|
|
}
|
2017-01-13 17:51:22 +00:00
|
|
|
|
|
|
|
case S_POLYGON: // polygon
|
|
|
|
if( bshape.m_Poly.size() < 2 )
|
|
|
|
break; // Malformed polygon.
|
|
|
|
{
|
|
|
|
// Insert the polygon:
|
|
|
|
const std::vector< wxPoint>& poly = bshape.m_Poly;
|
|
|
|
aux_polyset.NewOutline();
|
|
|
|
|
|
|
|
if( bshape.m_Thickness )
|
|
|
|
{
|
|
|
|
SHAPE_POLY_SET polyset;
|
|
|
|
polyset.NewOutline();
|
|
|
|
|
|
|
|
for( unsigned ii = 0; ii < poly.size(); ii++ )
|
2017-10-19 21:16:06 +00:00
|
|
|
{
|
2017-01-13 17:51:22 +00:00
|
|
|
polyset.Append( poly[ii].x, poly[ii].y );
|
2017-10-19 21:16:06 +00:00
|
|
|
}
|
2017-01-13 17:51:22 +00:00
|
|
|
|
2019-05-14 12:39:34 +00:00
|
|
|
int numSegs = std::max(
|
|
|
|
GetArcToSegmentCount( bshape.m_Thickness / 2, aError, 360.0 ), 6 );
|
|
|
|
polyset.Inflate( bshape.m_Thickness / 2, numSegs );
|
2017-01-13 17:51:22 +00:00
|
|
|
|
|
|
|
aux_polyset.Append( polyset );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
for( unsigned ii = 0; ii < poly.size(); ii++ )
|
|
|
|
aux_polyset.Append( poly[ii].x, poly[ii].y );
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-10-19 21:16:06 +00:00
|
|
|
aux_polyset.Simplify( SHAPE_POLY_SET::PM_FAST );
|
|
|
|
|
2018-05-18 06:38:03 +00:00
|
|
|
// Merge all polygons with the initial pad anchor shape
|
2017-01-13 17:51:22 +00:00
|
|
|
if( aux_polyset.OutlineCount() )
|
|
|
|
{
|
2018-05-18 06:38:03 +00:00
|
|
|
aMergedPolygon->BooleanAdd( aux_polyset, SHAPE_POLY_SET::PM_STRICTLY_SIMPLE );
|
|
|
|
aMergedPolygon->Fracture( SHAPE_POLY_SET::PM_STRICTLY_SIMPLE );
|
2017-01-13 17:51:22 +00:00
|
|
|
}
|
|
|
|
|
2017-10-19 21:16:06 +00:00
|
|
|
return aMergedPolygon->OutlineCount() <= 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Merge all basic shapes, converted to a polygon in one polygon,
|
|
|
|
* return true if OK, false in there is more than one polygon
|
|
|
|
* in aMergedPolygon
|
|
|
|
*/
|
2019-05-14 12:39:34 +00:00
|
|
|
bool D_PAD::MergePrimitivesAsPolygon( SHAPE_POLY_SET* aMergedPolygon )
|
2017-10-19 21:16:06 +00:00
|
|
|
{
|
2019-05-22 14:47:38 +00:00
|
|
|
auto board = GetBoard();
|
|
|
|
int maxError = ARC_HIGH_DEF;
|
|
|
|
|
|
|
|
if( board )
|
|
|
|
maxError = board->GetDesignSettings().m_MaxError;
|
|
|
|
|
2017-10-19 21:16:06 +00:00
|
|
|
// if aMergedPolygon == NULL, use m_customShapeAsPolygon as target
|
|
|
|
|
|
|
|
if( !aMergedPolygon )
|
|
|
|
aMergedPolygon = &m_customShapeAsPolygon;
|
|
|
|
|
|
|
|
aMergedPolygon->RemoveAllContours();
|
|
|
|
|
|
|
|
// Add the anchor pad shape in aMergedPolygon, others in aux_polyset:
|
|
|
|
// The anchor pad is always at 0,0
|
|
|
|
switch( GetAnchorPadShape() )
|
|
|
|
{
|
|
|
|
default:
|
|
|
|
case PAD_SHAPE_CIRCLE:
|
2019-05-22 14:47:38 +00:00
|
|
|
TransformCircleToPolygon( *aMergedPolygon, wxPoint( 0, 0 ), GetSize().x / 2, maxError );
|
2017-10-19 21:16:06 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case PAD_SHAPE_RECT:
|
2019-05-14 12:39:34 +00:00
|
|
|
{
|
|
|
|
SHAPE_RECT rect( -GetSize().x / 2, -GetSize().y / 2, GetSize().x, GetSize().y );
|
2017-10-19 21:16:06 +00:00
|
|
|
aMergedPolygon->AddOutline( rect.Outline() );
|
2019-05-14 12:39:34 +00:00
|
|
|
|
2017-10-19 21:16:06 +00:00
|
|
|
break;
|
|
|
|
}
|
2019-05-14 12:39:34 +00:00
|
|
|
}
|
2017-10-19 21:16:06 +00:00
|
|
|
|
2019-05-22 14:47:38 +00:00
|
|
|
if( !buildCustomPadPolygon( aMergedPolygon, maxError ) )
|
2017-10-19 21:16:06 +00:00
|
|
|
return false;
|
|
|
|
|
2019-08-20 17:22:30 +00:00
|
|
|
m_boundingRadius = -1; // The current bounding radius is no longer valid.
|
2017-01-13 17:51:22 +00:00
|
|
|
|
|
|
|
return aMergedPolygon->OutlineCount() <= 1;
|
|
|
|
}
|
|
|
|
|
2017-09-20 08:28:52 +00:00
|
|
|
void D_PAD::CustomShapeAsPolygonToBoardPosition( SHAPE_POLY_SET * aMergedPolygon,
|
2017-01-13 17:51:22 +00:00
|
|
|
wxPoint aPosition, double aRotation ) const
|
|
|
|
{
|
|
|
|
if( aMergedPolygon->OutlineCount() == 0 )
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Move, rotate, ... coordinates in aMergedPolygon according to the
|
|
|
|
// pad position and orientation
|
|
|
|
for( int cnt = 0; cnt < aMergedPolygon->OutlineCount(); ++cnt )
|
|
|
|
{
|
|
|
|
SHAPE_LINE_CHAIN& poly = aMergedPolygon->Outline( cnt );
|
|
|
|
|
|
|
|
for( int ii = 0; ii < poly.PointCount(); ++ii )
|
|
|
|
{
|
|
|
|
wxPoint corner( poly.Point( ii ).x, poly.Point( ii ).y );
|
|
|
|
RotatePoint( &corner, aRotation );
|
|
|
|
corner += aPosition;
|
|
|
|
|
|
|
|
poly.Point( ii ).x = corner.x;
|
|
|
|
poly.Point( ii ).y = corner.y;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-10-19 21:16:06 +00:00
|
|
|
|
|
|
|
bool D_PAD::GetBestAnchorPosition( VECTOR2I& aPos )
|
|
|
|
{
|
|
|
|
SHAPE_POLY_SET poly;
|
|
|
|
|
2019-05-14 12:39:34 +00:00
|
|
|
if( !buildCustomPadPolygon( &poly, ARC_LOW_DEF ) )
|
2017-10-19 21:16:06 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
const int minSteps = 10;
|
|
|
|
const int maxSteps = 50;
|
|
|
|
|
|
|
|
int stepsX, stepsY;
|
|
|
|
|
|
|
|
auto bbox = poly.BBox();
|
|
|
|
|
|
|
|
if( bbox.GetWidth() < bbox.GetHeight() )
|
|
|
|
{
|
|
|
|
stepsX = minSteps;
|
|
|
|
stepsY = minSteps * (double) bbox.GetHeight() / (double )(bbox.GetWidth() + 1);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
stepsY = minSteps;
|
|
|
|
stepsX = minSteps * (double) bbox.GetWidth() / (double )(bbox.GetHeight() + 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
stepsX = std::max(minSteps, std::min( maxSteps, stepsX ) );
|
|
|
|
stepsY = std::max(minSteps, std::min( maxSteps, stepsY ) );
|
|
|
|
|
|
|
|
auto center = bbox.Centre();
|
|
|
|
|
|
|
|
auto minDist = std::numeric_limits<int64_t>::max();
|
|
|
|
int64_t minDistEdge;
|
|
|
|
|
|
|
|
if( GetAnchorPadShape() == PAD_SHAPE_CIRCLE )
|
|
|
|
{
|
|
|
|
minDistEdge = GetSize().x;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
minDistEdge = std::max( GetSize().x, GetSize().y );
|
|
|
|
}
|
|
|
|
|
2018-01-12 16:58:25 +00:00
|
|
|
OPT<VECTOR2I> bestAnchor( []()->OPT<VECTOR2I> { return NULLOPT; }() );
|
2017-10-19 21:16:06 +00:00
|
|
|
|
|
|
|
for ( int y = 0; y < stepsY ; y++ )
|
2017-10-20 11:48:36 +00:00
|
|
|
{
|
2017-10-19 21:16:06 +00:00
|
|
|
for ( int x = 0; x < stepsX; x++ )
|
|
|
|
{
|
|
|
|
VECTOR2I p = bbox.GetPosition();
|
|
|
|
p.x += rescale( x, bbox.GetWidth(), (stepsX - 1) );
|
|
|
|
p.y += rescale( y, bbox.GetHeight(), (stepsY - 1) );
|
|
|
|
|
|
|
|
if ( poly.Contains(p) )
|
|
|
|
{
|
|
|
|
|
|
|
|
auto dist = (center - p).EuclideanNorm();
|
|
|
|
auto distEdge = poly.COutline(0).Distance( p, true );
|
|
|
|
if ( distEdge >= minDistEdge )
|
|
|
|
{
|
|
|
|
if ( dist < minDist )
|
|
|
|
{
|
|
|
|
bestAnchor = p;
|
|
|
|
minDist = dist;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-10-20 11:48:36 +00:00
|
|
|
}
|
2017-10-19 21:16:06 +00:00
|
|
|
|
2017-10-20 11:48:36 +00:00
|
|
|
if ( bestAnchor )
|
|
|
|
{
|
|
|
|
aPos = *bestAnchor;
|
|
|
|
return true;
|
|
|
|
}
|
2017-10-19 21:16:06 +00:00
|
|
|
|
2017-10-20 11:48:36 +00:00
|
|
|
return false;
|
2017-10-19 21:16:06 +00:00
|
|
|
}
|