Commit dfdd2cfd authored by jean-pierre charras's avatar jean-pierre charras

Remove freepcb arc legacy code from PolyLine.

parent ae05cd80
...@@ -44,6 +44,7 @@ ...@@ -44,6 +44,7 @@
#include <class_board.h> #include <class_board.h>
#include <class_module.h> #include <class_module.h>
#include <polygon_test_point_inside.h>
int D_PAD::m_PadSketchModePenSize = 0; // Pen size used to draw pads in sketch mode int D_PAD::m_PadSketchModePenSize = 0; // Pen size used to draw pads in sketch mode
......
...@@ -47,6 +47,7 @@ ...@@ -47,6 +47,7 @@
#include <pcbnew.h> #include <pcbnew.h>
#include <zones.h> #include <zones.h>
#include <math_for_graphics.h> #include <math_for_graphics.h>
#include <polygon_test_point_inside.h>
ZONE_CONTAINER::ZONE_CONTAINER( BOARD* aBoard ) : ZONE_CONTAINER::ZONE_CONTAINER( BOARD* aBoard ) :
......
...@@ -45,6 +45,7 @@ ...@@ -45,6 +45,7 @@
#include <class_zone.h> #include <class_zone.h>
#include <class_marker_pcb.h> #include <class_marker_pcb.h>
#include <math_for_graphics.h> #include <math_for_graphics.h>
#include <polygon_test_point_inside.h>
/* compare 2 trapezoids (can be rectangle) and return true if distance > aDist /* compare 2 trapezoids (can be rectangle) and return true if distance > aDist
......
...@@ -35,6 +35,7 @@ ...@@ -35,6 +35,7 @@
#include <pcbnew.h> #include <pcbnew.h>
#include <zones.h> #include <zones.h>
#include <polygon_test_point_inside.h>
/** /**
......
...@@ -28,7 +28,6 @@ ...@@ -28,7 +28,6 @@
#include <algorithm> // sort #include <algorithm> // sort
#include <fctsys.h> #include <fctsys.h>
#include <common.h> #include <common.h>
#include <macros.h> #include <macros.h>
...@@ -40,6 +39,7 @@ ...@@ -40,6 +39,7 @@
#include <pcbnew.h> #include <pcbnew.h>
#include <zones.h> #include <zones.h>
#include <polygon_test_point_inside.h>
static bool CmpZoneSubnetValue( const BOARD_CONNECTED_ITEM* a, const BOARD_CONNECTED_ITEM* b ); static bool CmpZoneSubnetValue( const BOARD_CONNECTED_ITEM* a, const BOARD_CONNECTED_ITEM* b );
void Merge_SubNets_Connected_By_CopperAreas( BOARD* aPcb, int aNetcode ); void Merge_SubNets_Connected_By_CopperAreas( BOARD* aPcb, int aNetcode );
......
...@@ -43,6 +43,7 @@ ...@@ -43,6 +43,7 @@
#include <drc_stuff.h> #include <drc_stuff.h>
#include <math_for_graphics.h> #include <math_for_graphics.h>
#define STRAIGHT 0 // To be remove after math_for_graphics code cleanup
/** /**
* Function AddArea * Function AddArea
...@@ -386,8 +387,8 @@ bool BOARD::TestAreaIntersections( ZONE_CONTAINER* area_to_test ) ...@@ -386,8 +387,8 @@ bool BOARD::TestAreaIntersections( ZONE_CONTAINER* area_to_test )
yf2 = poly2->GetY( is2 ); yf2 = poly2->GetY( is2 );
} }
int n_int = FindSegmentIntersections( xi1, yi1, xf1, yf1, CPolyLine::STRAIGHT, int n_int = FindSegmentIntersections( xi1, yi1, xf1, yf1, STRAIGHT,
xi2, yi2, xf2, yf2, CPolyLine::STRAIGHT ); xi2, yi2, xf2, yf2, STRAIGHT );
if( n_int ) if( n_int )
return true; return true;
} }
...@@ -497,8 +498,8 @@ int BOARD::TestAreaIntersection( ZONE_CONTAINER* area_ref, ZONE_CONTAINER* area_ ...@@ -497,8 +498,8 @@ int BOARD::TestAreaIntersection( ZONE_CONTAINER* area_ref, ZONE_CONTAINER* area_
yf2 = poly2->GetY( is2 ); yf2 = poly2->GetY( is2 );
} }
int n_int = FindSegmentIntersections( xi1, yi1, xf1, yf1, CPolyLine::STRAIGHT, int n_int = FindSegmentIntersections( xi1, yi1, xf1, yf1, STRAIGHT,
xi2, yi2, xf2, yf2, CPolyLine::STRAIGHT ); xi2, yi2, xf2, yf2, STRAIGHT );
if( n_int ) if( n_int )
{ {
bInt = true; bInt = true;
...@@ -843,10 +844,10 @@ int BOARD::Test_Drc_Areas_Outlines_To_Areas_Outlines( ZONE_CONTAINER* aArea_To_E ...@@ -843,10 +844,10 @@ int BOARD::Test_Drc_Areas_Outlines_To_Areas_Outlines( ZONE_CONTAINER* aArea_To_E
int x, y; int x, y;
int d = GetClearanceBetweenSegments( bx1, by1, bx2, by2, int d = GetClearanceBetweenSegments( bx1, by1, bx2, by2,
CPolyLine::STRAIGHT, STRAIGHT,
0, 0,
ax1, ay1, ax2, ay2, ax1, ay1, ax2, ay2,
CPolyLine::STRAIGHT, STRAIGHT,
0, 0,
zone2zoneClearance, zone2zoneClearance,
&x, &y ); &x, &y );
...@@ -986,9 +987,9 @@ bool DRC::doEdgeZoneDrc( ZONE_CONTAINER* aArea, int aCornerIndex ) ...@@ -986,9 +987,9 @@ bool DRC::doEdgeZoneDrc( ZONE_CONTAINER* aArea, int aCornerIndex )
} }
int x, y; // variables containing the intersecting point coordinates int x, y; // variables containing the intersecting point coordinates
int d = GetClearanceBetweenSegments( bx1, by1, bx2, by2, CPolyLine::STRAIGHT, int d = GetClearanceBetweenSegments( bx1, by1, bx2, by2, STRAIGHT,
0, 0,
ax1, ay1, ax2, ay2, CPolyLine::STRAIGHT, ax1, ay1, ax2, ay2, STRAIGHT,
0, 0,
zone_clearance, zone_clearance,
&x, &y ); &x, &y );
......
...@@ -14,6 +14,10 @@ ...@@ -14,6 +14,10 @@
#include <bezier_curves.h> #include <bezier_curves.h>
#include <polygon_test_point_inside.h> #include <polygon_test_point_inside.h>
#include <math_for_graphics.h> #include <math_for_graphics.h>
#include <polygon_test_point_inside.h>
enum m_SideStyle { STRAIGHT }; // side styles
CPolyLine::CPolyLine() CPolyLine::CPolyLine()
{ {
...@@ -62,7 +66,6 @@ void armBoolEng( Bool_Engine* aBooleng, bool aConvertHoles = false ); ...@@ -62,7 +66,6 @@ void armBoolEng( Bool_Engine* aBooleng, bool aConvertHoles = false );
*/ */
int CPolyLine::NormalizeWithKbool( std::vector<CPolyLine*>* aExtraPolyList ) int CPolyLine::NormalizeWithKbool( std::vector<CPolyLine*>* aExtraPolyList )
{ {
std::vector<CArc> arc_array;
std::vector <void*> hole_array; // list of holes std::vector <void*> hole_array; // list of holes
std::vector<int>* hole; // used to store corners for a given hole std::vector<int>* hole; // used to store corners for a given hole
CPolyLine* polyline; CPolyLine* polyline;
...@@ -108,7 +111,6 @@ int CPolyLine::NormalizeWithKbool( std::vector<CPolyLine*>* aExtraPolyList ) ...@@ -108,7 +111,6 @@ int CPolyLine::NormalizeWithKbool( std::vector<CPolyLine*>* aExtraPolyList )
{ {
// first external contour, replace this poly // first external contour, replace this poly
m_CornersList.clear(); m_CornersList.clear();
m_SideStyle.clear();
bool first = true; bool first = true;
while( m_Kbool_Poly_Engine->PolygonHasMorePoints() ) while( m_Kbool_Poly_Engine->PolygonHasMorePoints() )
...@@ -257,8 +259,7 @@ int CPolyLine::AddPolygonsToBoolEng( Bool_Engine* aBooleng, GroupType aGroup ) ...@@ -257,8 +259,7 @@ int CPolyLine::AddPolygonsToBoolEng( Bool_Engine* aBooleng, GroupType aGroup )
/** /**
* Function MakeKboolPoly * Function MakeKboolPoly
* fill a kbool engine with a closed polyline contour * fill a kbool engine with a closed polyline contour
* approximates arcs with multiple straight-line segments * normalize self-intersecting contours
* combining intersecting contours if possible
* @return error: 0 if Ok, 1 if error * @return error: 0 if Ok, 1 if error
*/ */
int CPolyLine::MakeKboolPoly() int CPolyLine::MakeKboolPoly()
...@@ -269,20 +270,12 @@ int CPolyLine::MakeKboolPoly() ...@@ -269,20 +270,12 @@ int CPolyLine::MakeKboolPoly()
m_Kbool_Poly_Engine = NULL; m_Kbool_Poly_Engine = NULL;
} }
std::vector<CArc>* arc_array = NULL; // Remove me
if( !GetClosed() ) if( !GetClosed() )
return 1; // error return 1; // error
int n_arcs = 0;
int polycount = GetContoursCount(); int polycount = GetContoursCount();
int last_contour = polycount - 1; int last_contour = polycount - 1;
if( arc_array )
arc_array->clear();
int iarc = 0;
for( int icont = 0; icont <= last_contour; icont++ ) for( int icont = 0; icont <= last_contour; icont++ )
{ {
// Fill a kbool engine for this contour, // Fill a kbool engine for this contour,
...@@ -309,8 +302,6 @@ int CPolyLine::MakeKboolPoly() ...@@ -309,8 +302,6 @@ int CPolyLine::MakeKboolPoly()
} }
} }
// first, calculate number of vertices in contour
int n_vertices = 0;
int ic_st = GetContourStart( icont ); int ic_st = GetContourStart( icont );
int ic_end = GetContourEnd( icont ); int ic_end = GetContourEnd( icont );
...@@ -320,159 +311,12 @@ int CPolyLine::MakeKboolPoly() ...@@ -320,159 +311,12 @@ int CPolyLine::MakeKboolPoly()
return 1; // error return 1; // error
} }
for( int ic = ic_st; ic<=ic_end; ic++ ) // Enter this contour to booleng
for( int ic = ic_st; ic <= ic_end; ic++ )
{ {
int style = m_SideStyle[ic];
if( style == STRAIGHT )
n_vertices++;
else
{
// style is ARC_CW or ARC_CCW
int n = CArc::ARC_STEPS;
n_vertices += n;
n_arcs++;
}
}
// now enter this contour to booleng
int ivtx = 0;
for( int ic = ic_st; ic<=ic_end; ic++ )
{
int style = m_SideStyle[ic];
int x1 = m_CornersList[ic].x; int x1 = m_CornersList[ic].x;
int y1 = m_CornersList[ic].y; int y1 = m_CornersList[ic].y;
int x2, y2; booleng->AddPoint( x1, y1 );
if( ic < ic_end )
{
x2 = m_CornersList[ic + 1].x;
y2 = m_CornersList[ic + 1].y;
}
else
{
x2 = m_CornersList[ic_st].x;
y2 = m_CornersList[ic_st].y;
}
if( style == STRAIGHT )
{
booleng->AddPoint( x1, y1 );
ivtx++;
}
else
{
// style is arc_cw or arc_ccw
int n; // number of steps for arcs
n = CArc::ARC_STEPS;
double xo, yo, theta1, theta2, a, b;
a = fabs( (double) (x1 - x2) );
b = fabs( (double) (y1 - y2) );
if( style == CPolyLine::ARC_CW )
{
// clockwise arc (ie.quadrant of ellipse)
if( x2 > x1 && y2 > y1 )
{
// first quadrant, draw second quadrant of ellipse
xo = x2;
yo = y1;
theta1 = M_PI;
theta2 = M_PI / 2.0;
}
else if( x2 < x1 && y2 > y1 )
{
// second quadrant, draw third quadrant of ellipse
xo = x1;
yo = y2;
theta1 = 3.0 * M_PI / 2.0;
theta2 = M_PI;
}
else if( x2 < x1 && y2 < y1 )
{
// third quadrant, draw fourth quadrant of ellipse
xo = x2;
yo = y1;
theta1 = 2.0 * M_PI;
theta2 = 3.0 * M_PI / 2.0;
}
else
{
xo = x1; // fourth quadrant, draw first quadrant of ellipse
yo = y2;
theta1 = M_PI / 2.0;
theta2 = 0.0;
}
}
else
{
// counter-clockwise arc
if( x2 > x1 && y2 > y1 )
{
xo = x1; // first quadrant, draw fourth quadrant of ellipse
yo = y2;
theta1 = 3.0 * M_PI / 2.0;
theta2 = 2.0 * M_PI;
}
else if( x2 < x1 && y2 > y1 )
{
xo = x2; // second quadrant
yo = y1;
theta1 = 0.0;
theta2 = M_PI / 2.0;
}
else if( x2 < x1 && y2 < y1 )
{
xo = x1; // third quadrant
yo = y2;
theta1 = M_PI / 2.0;
theta2 = M_PI;
}
else
{
xo = x2; // fourth quadrant
yo = y1;
theta1 = M_PI;
theta2 = 3.0 * M_PI / 2.0;
}
}
// now write steps for arc
if( arc_array )
{
CArc new_arc;
new_arc.style = style;
new_arc.n_steps = n;
new_arc.xi = x1;
new_arc.yi = y1;
new_arc.xf = x2;
new_arc.yf = y2;
arc_array->push_back( new_arc );
iarc++;
}
for( int is = 0; is<n; is++ )
{
double theta = theta1 + ( (theta2 - theta1) * (double) is ) / n;
double x = xo + a* cos( theta );
double y = yo + b* sin( theta );
if( is == 0 )
{
x = x1;
y = y1;
}
booleng->AddPoint( x, y );
ivtx++;
}
}
}
if( n_vertices != ivtx )
{
wxASSERT( 0 );
} }
// close list added to the bool engine // close list added to the bool engine
...@@ -624,7 +468,6 @@ void CPolyLine::Start( int layer, int x, int y, int hatch ) ...@@ -624,7 +468,6 @@ void CPolyLine::Start( int layer, int x, int y, int hatch )
poly_pt.end_contour = false; poly_pt.end_contour = false;
m_CornersList.push_back( poly_pt ); m_CornersList.push_back( poly_pt );
m_SideStyle.push_back( 0 );
} }
...@@ -636,12 +479,8 @@ void CPolyLine::AppendCorner( int x, int y ) ...@@ -636,12 +479,8 @@ void CPolyLine::AppendCorner( int x, int y )
CPolyPt poly_pt( x, y ); CPolyPt poly_pt( x, y );
poly_pt.end_contour = false; poly_pt.end_contour = false;
// add entries for new corner and side // add entries for new corner
m_CornersList.push_back( poly_pt ); m_CornersList.push_back( poly_pt );
m_SideStyle.push_back( STRAIGHT );
if( m_CornersList.size() > 0 && !m_CornersList[m_CornersList.size() - 1].end_contour )
m_SideStyle[m_CornersList.size() - 1] = STRAIGHT;
} }
...@@ -670,29 +509,24 @@ void CPolyLine::DeleteCorner( int ic ) ...@@ -670,29 +509,24 @@ void CPolyLine::DeleteCorner( int ic )
{ {
UnHatch(); UnHatch();
int icont = GetContour( ic ); int icont = GetContour( ic );
int istart = GetContourStart( icont );
int iend = GetContourEnd( icont ); int iend = GetContourEnd( icont );
bool bClosed = icont < GetContoursCount() - 1 || GetClosed(); bool closed = icont < GetContoursCount() - 1 || GetClosed();
if( !bClosed ) if( !closed )
{ {
// open contour, must be last contour // open contour, must be last contour
m_CornersList.erase( m_CornersList.begin() + ic ); m_CornersList.erase( m_CornersList.begin() + ic );
if( ic != istart )
m_SideStyle.erase( m_SideStyle.begin() + ic - 1 );
} }
else else
{ {
// closed contour // closed contour
m_CornersList.erase( m_CornersList.begin() + ic ); m_CornersList.erase( m_CornersList.begin() + ic );
m_SideStyle.erase( m_SideStyle.begin() + ic );
if( ic == iend ) if( ic == iend )
m_CornersList[ic - 1].end_contour = true; m_CornersList[ic - 1].end_contour = true;
} }
if( bClosed && GetContourSize( icont ) < 3 ) if( closed && GetContourSize( icont ) < 3 )
{ {
// delete the entire contour // delete the entire contour
RemoveContour( icont ); RemoveContour( icont );
...@@ -725,7 +559,6 @@ void CPolyLine::RemoveContour( int icont ) ...@@ -725,7 +559,6 @@ void CPolyLine::RemoveContour( int icont )
{ {
// remove last contour // remove last contour
m_CornersList.erase( m_CornersList.begin() + istart, m_CornersList.end() ); m_CornersList.erase( m_CornersList.begin() + istart, m_CornersList.end() );
m_SideStyle.erase( m_SideStyle.begin() + istart, m_SideStyle.end() );
} }
else else
{ {
...@@ -733,7 +566,6 @@ void CPolyLine::RemoveContour( int icont ) ...@@ -733,7 +566,6 @@ void CPolyLine::RemoveContour( int icont )
for( int ic = iend; ic>=istart; ic-- ) for( int ic = iend; ic>=istart; ic-- )
{ {
m_CornersList.erase( m_CornersList.begin() + ic ); m_CornersList.erase( m_CornersList.begin() + ic );
m_SideStyle.erase( m_SideStyle.begin() + ic );
} }
} }
...@@ -958,7 +790,6 @@ void CPolyLine::RemoveAllContours( void ) ...@@ -958,7 +790,6 @@ void CPolyLine::RemoveAllContours( void )
*/ */
{ {
m_CornersList.clear(); m_CornersList.clear();
m_SideStyle.clear();
} }
...@@ -975,12 +806,10 @@ void CPolyLine::InsertCorner( int ic, int x, int y ) ...@@ -975,12 +806,10 @@ void CPolyLine::InsertCorner( int ic, int x, int y )
if( (unsigned) (ic) >= m_CornersList.size() ) if( (unsigned) (ic) >= m_CornersList.size() )
{ {
m_CornersList.push_back( CPolyPt( x, y ) ); m_CornersList.push_back( CPolyPt( x, y ) );
m_SideStyle.push_back( STRAIGHT );
} }
else else
{ {
m_CornersList.insert( m_CornersList.begin() + ic + 1, CPolyPt( x, y ) ); m_CornersList.insert( m_CornersList.begin() + ic + 1, CPolyPt( x, y ) );
m_SideStyle.insert( m_SideStyle.begin() + ic + 1, STRAIGHT );
} }
if( (unsigned) (ic + 1) < m_CornersList.size() ) if( (unsigned) (ic + 1) < m_CornersList.size() )
...@@ -1166,41 +995,6 @@ int CPolyLine::GetContourSize( int icont ) ...@@ -1166,41 +995,6 @@ int CPolyLine::GetContourSize( int icont )
} }
void CPolyLine::SetSideStyle( int is, int style )
{
UnHatch();
wxPoint p1, p2;
if( is == (int) (m_CornersList.size() - 1) )
{
p1.x = m_CornersList[m_CornersList.size() - 1].x;
p1.y = m_CornersList[m_CornersList.size() - 1].y;
p2.x = m_CornersList[0].x;
p2.y = m_CornersList[0].y;
}
else
{
p1.x = m_CornersList[is].x;
p1.y = m_CornersList[is].y;
p2.x = m_CornersList[is + 1].x;
p2.y = m_CornersList[is + 1].y;
}
if( p1.x == p2.x || p1.y == p2.y )
m_SideStyle[is] = STRAIGHT;
else
m_SideStyle[is] = style;
Hatch();
}
int CPolyLine::GetSideStyle( int is )
{
return m_SideStyle[is];
}
int CPolyLine::GetClosed() int CPolyLine::GetClosed()
{ {
if( m_CornersList.size() == 0 ) if( m_CornersList.size() == 0 )
...@@ -1318,7 +1112,7 @@ void CPolyLine::Hatch() ...@@ -1318,7 +1112,7 @@ void CPolyLine::Hatch()
m_CornersList[ic].x, m_CornersList[ic].y, m_CornersList[ic].x, m_CornersList[ic].y,
m_CornersList[i_start_contour].x, m_CornersList[i_start_contour].x,
m_CornersList[i_start_contour].y, m_CornersList[i_start_contour].y,
m_SideStyle[ic], STRAIGHT,
&x, &y, &x2, &y2 ); &x, &y, &x2, &y2 );
i_start_contour = ic + 1; i_start_contour = ic + 1;
} }
...@@ -1327,7 +1121,7 @@ void CPolyLine::Hatch() ...@@ -1327,7 +1121,7 @@ void CPolyLine::Hatch()
ok = FindLineSegmentIntersection( a, slope, ok = FindLineSegmentIntersection( a, slope,
m_CornersList[ic].x, m_CornersList[ic].y, m_CornersList[ic].x, m_CornersList[ic].y,
m_CornersList[ic + 1].x, m_CornersList[ic + 1].y, m_CornersList[ic + 1].x, m_CornersList[ic + 1].y,
m_SideStyle[ic], STRAIGHT,
&x, &y, &x2, &y2 ); &x, &y, &x2, &y2 );
} }
...@@ -1443,8 +1237,6 @@ void CPolyLine::Copy( CPolyLine* src ) ...@@ -1443,8 +1237,6 @@ void CPolyLine::Copy( CPolyLine* src )
m_hatchPitch = src->m_hatchPitch; m_hatchPitch = src->m_hatchPitch;
// copy corners, using vector copy // copy corners, using vector copy
m_CornersList = src->m_CornersList; m_CornersList = src->m_CornersList;
// copy side styles, using vector copy
m_SideStyle = src->m_SideStyle;
} }
...@@ -1595,10 +1387,9 @@ int CPolyLine::Distance( wxPoint aStart, wxPoint aEnd, int aWidth ) ...@@ -1595,10 +1387,9 @@ int CPolyLine::Distance( wxPoint aStart, wxPoint aEnd, int aWidth )
by2 = GetY( ic2 + 1 ); by2 = GetY( ic2 + 1 );
} }
int bstyle = GetSideStyle( ic2 ); int d = GetClearanceBetweenSegments( bx1, by1, bx2, by2, STRAIGHT, 0,
int d = GetClearanceBetweenSegments( bx1, by1, bx2, by2, bstyle, 0,
aStart.x, aStart.y, aEnd.x, aEnd.y, aStart.x, aStart.y, aEnd.x, aEnd.y,
CPolyLine::STRAIGHT, aWidth, STRAIGHT, aWidth,
1, // min clearance, should be > 0 1, // min clearance, should be > 0
NULL, NULL ); NULL, NULL );
...@@ -1654,12 +1445,9 @@ int CPolyLine::Distance( const wxPoint& aPoint ) ...@@ -1654,12 +1445,9 @@ int CPolyLine::Distance( const wxPoint& aPoint )
by2 = GetY( ic2 + 1 ); by2 = GetY( ic2 + 1 );
} }
// Here we expect only straight lines for vertices
// (no arcs, not yet supported in Pcbnew)
int d = KiROUND( GetPointToLineSegmentDistance( aPoint.x, aPoint.y, int d = KiROUND( GetPointToLineSegmentDistance( aPoint.x, aPoint.y,
bx1, by1, bx2, by2 ) ); bx1, by1, bx2, by2 ) );
if( distance > d ) if( distance > d )
distance = d; distance = d;
...@@ -1901,9 +1689,9 @@ bool CPolyLine::IsPolygonSelfIntersecting() ...@@ -1901,9 +1689,9 @@ bool CPolyLine::IsPolygonSelfIntersecting()
int x2f = GetX( is2_next ); int x2f = GetX( is2_next );
int y2f = GetY( is2_next ); int y2f = GetY( is2_next );
int ret = FindSegmentIntersections( x1i, y1i, x1f, y1f, int ret = FindSegmentIntersections( x1i, y1i, x1f, y1f,
CPolyLine::STRAIGHT, STRAIGHT,
x2i, y2i, x2f, y2f, x2i, y2i, x2f, y2f,
CPolyLine::STRAIGHT ); STRAIGHT );
if( ret ) if( ret )
{ {
// intersection between non-adjacent sides // intersection between non-adjacent sides
......
...@@ -24,13 +24,13 @@ ...@@ -24,13 +24,13 @@
#include <polygons_defs.h> #include <polygons_defs.h>
// inflection modes for DS_LINE and DS_LINE_VERTEX, used in math_for_graphics.cpp // inflection modes for DS_LINE and DS_LINE_VERTEX, used in math_for_graphics.cpp
enum { /*enum {
IM_NONE = 0, IM_NONE = 0,
IM_90_45, IM_90_45,
IM_45_90, IM_45_90,
IM_90 IM_90
}; };
*/
class CRect class CRect
{ {
...@@ -58,6 +58,7 @@ public: ...@@ -58,6 +58,7 @@ public:
} }
}; };
/*
class CArc class CArc
{ {
public: public:
...@@ -67,7 +68,7 @@ public: ...@@ -67,7 +68,7 @@ public:
int n_steps; // number of straight-line segments in gpc_poly int n_steps; // number of straight-line segments in gpc_poly
bool bFound; bool bFound;
}; };
*/
class CPolyPt : public wxPoint class CPolyPt : public wxPoint
{ {
...@@ -98,12 +99,9 @@ public: ...@@ -98,12 +99,9 @@ public:
}; };
#include <polygon_test_point_inside.h>
class CPolyLine class CPolyLine
{ {
public: public:
enum m_SideStyle { STRAIGHT, ARC_CW, ARC_CCW }; // side styles
enum HATCH_STYLE { NO_HATCH, DIAGONAL_FULL, DIAGONAL_EDGE }; // hatch styles enum HATCH_STYLE { NO_HATCH, DIAGONAL_FULL, DIAGONAL_EDGE }; // hatch styles
// constructors/destructor // constructors/destructor
...@@ -197,7 +195,6 @@ public: ...@@ -197,7 +195,6 @@ public:
int GetUtility( int ic ) { return m_CornersList[ic].m_utility; }; int GetUtility( int ic ) { return m_CornersList[ic].m_utility; };
void SetUtility( int ic, int utility ) { m_CornersList[ic].m_utility = utility; }; void SetUtility( int ic, int utility ) { m_CornersList[ic].m_utility = utility; };
int GetSideStyle( int is );
int GetHatchPitch() { return m_hatchPitch; } int GetHatchPitch() { return m_hatchPitch; }
static int GetDefaultHatchPitchMils() { return 20; } // default hatch pitch value in mils static int GetDefaultHatchPitchMils() { return 20; } // default hatch pitch value in mils
...@@ -214,7 +211,6 @@ public: ...@@ -214,7 +211,6 @@ public:
void SetX( int ic, int x ); void SetX( int ic, int x );
void SetY( int ic, int y ); void SetY( int ic, int y );
void SetEndContour( int ic, bool end_contour ); void SetEndContour( int ic, bool end_contour );
void SetSideStyle( int is, int style );
void SetHatchStyle( enum HATCH_STYLE style ) void SetHatchStyle( enum HATCH_STYLE style )
{ {
...@@ -299,7 +295,6 @@ private: ...@@ -299,7 +295,6 @@ private:
Bool_Engine* m_Kbool_Poly_Engine; // polygons set in kbool engine data Bool_Engine* m_Kbool_Poly_Engine; // polygons set in kbool engine data
public: public:
std::vector <CPolyPt> m_CornersList; // array of points for corners std::vector <CPolyPt> m_CornersList; // array of points for corners
std::vector <int> m_SideStyle; // array of styles for sides
std::vector <CSegment> m_HatchLines; // hatch lines showing the polygon area std::vector <CSegment> m_HatchLines; // hatch lines showing the polygon area
}; };
......
...@@ -34,12 +34,17 @@ double Distance( double x1, double y1, double x2, double y2 ) ...@@ -34,12 +34,17 @@ double Distance( double x1, double y1, double x2, double y2 )
return d; return d;
} }
static bool Quadratic( double a, double b, double c, double *x1, double *x2 );
static bool FindLineEllipseIntersections( double a, double b, double c, double d, double *x1, double *x2 );
static bool FindVerticalLineEllipseIntersections( double a, double b, double x, double *y1, double *y2 );
static int GetArcIntersections( EllipseKH * el1, EllipseKH * el2, static int GetArcIntersections( EllipseKH * el1, EllipseKH * el2,
double * x1=NULL, double * y1=NULL, double * x1=NULL, double * y1=NULL,
double * x2=NULL, double * y2=NULL ); double * x2=NULL, double * y2=NULL );
static bool InRange( double x, double xi, double xf ); static bool InRange( double x, double xi, double xf );
enum m_SideStyle { STRAIGHT, ARC_CW, ARC_CCW }; // side styles
/** /**
...@@ -112,7 +117,7 @@ int MakeEllipseFromArc( int xi, int yi, int xf, int yf, int style, EllipseKH* el ...@@ -112,7 +117,7 @@ int MakeEllipseFromArc( int xi, int yi, int xf, int yf, int style, EllipseKH* el
// convert to clockwise arc // convert to clockwise arc
int xxi, xxf, yyi, yyf; int xxi, xxf, yyi, yyf;
if( style == CPolyLine::ARC_CCW ) if( style == ARC_CCW )
{ {
xxi = xf; xxi = xf;
xxf = xi; xxf = xi;
...@@ -199,7 +204,7 @@ int FindSegmentIntersections( int xi, int yi, int xf, int yf, int style, ...@@ -199,7 +204,7 @@ int FindSegmentIntersections( int xi, int yi, int xf, int yf, int style,
|| min( yi, yf ) > max( yi2, yf2 ) ) || min( yi, yf ) > max( yi2, yf2 ) )
return 0; return 0;
if( style != CPolyLine::STRAIGHT && style2 != CPolyLine::STRAIGHT ) if( style != STRAIGHT && style2 != STRAIGHT )
{ {
// two identical arcs intersect // two identical arcs intersect
if( style == style2 && xi == xi2 && yi == yi2 && xf == xf2 && yf == yf2 ) if( style == style2 && xi == xi2 && yi == yi2 && xf == xf2 && yf == yf2 )
...@@ -224,7 +229,7 @@ int FindSegmentIntersections( int xi, int yi, int xf, int yf, int style, ...@@ -224,7 +229,7 @@ int FindSegmentIntersections( int xi, int yi, int xf, int yf, int style,
} }
} }
if( style == CPolyLine::STRAIGHT && style2 == CPolyLine::STRAIGHT ) if( style == STRAIGHT && style2 == STRAIGHT )
{ {
// both straight-line segments // both straight-line segments
int x, y; int x, y;
...@@ -246,7 +251,7 @@ int FindSegmentIntersections( int xi, int yi, int xf, int yf, int style, ...@@ -246,7 +251,7 @@ int FindSegmentIntersections( int xi, int yi, int xf, int yf, int style,
yr[0] = y; yr[0] = y;
iret = 1; iret = 1;
} }
else if( style == CPolyLine::STRAIGHT ) else if( style == STRAIGHT )
{ {
// first segment is straight, second segment is an arc // first segment is straight, second segment is an arc
int ret; int ret;
...@@ -288,7 +293,7 @@ int FindSegmentIntersections( int xi, int yi, int xf, int yf, int style, ...@@ -288,7 +293,7 @@ int FindSegmentIntersections( int xi, int yi, int xf, int yf, int style,
} }
} }
} }
else if( style2 == CPolyLine::STRAIGHT ) else if( style2 == STRAIGHT )
{ {
// first segment is an arc, second segment is straight // first segment is an arc, second segment is straight
int ret; int ret;
...@@ -381,7 +386,7 @@ int FindLineSegmentIntersection( double a, double b, int xi, int yi, int xf, int ...@@ -381,7 +386,7 @@ int FindLineSegmentIntersection( double a, double b, int xi, int yi, int xf, int
if( xf != xi ) if( xf != xi )
{ {
// non-vertical segment, get intersection // non-vertical segment, get intersection
if( style == CPolyLine::STRAIGHT || yf == yi ) if( style == STRAIGHT || yf == yi )
{ {
// horizontal or oblique straight segment // horizontal or oblique straight segment
// put into form y = c + dx; // put into form y = c + dx;
...@@ -436,13 +441,13 @@ int FindLineSegmentIntersection( double a, double b, int xi, int yi, int xf, int ...@@ -436,13 +441,13 @@ int FindLineSegmentIntersection( double a, double b, int xi, int yi, int xf, int
return 0; return 0;
} }
} }
else if( style == CPolyLine::ARC_CW || style == CPolyLine::ARC_CCW ) else if( style == ARC_CW || style == ARC_CCW )
{ {
// arc (quadrant of ellipse) // arc (quadrant of ellipse)
// convert to clockwise arc // convert to clockwise arc
int xxi, xxf, yyi, yyf; int xxi, xxf, yyi, yyf;
if( style == CPolyLine::ARC_CCW ) if( style == ARC_CCW )
{ {
xxi = xf; xxi = xf;
xxf = xi; xxf = xi;
...@@ -640,7 +645,7 @@ bool TestForIntersectionOfStraightLineSegments( int x1i, int y1i, int x1f, int y ...@@ -640,7 +645,7 @@ bool TestForIntersectionOfStraightLineSegments( int x1i, int y1i, int x1f, int y
a = (double) y2i - b * x2i; a = (double) y2i - b * x2i;
double x1, y1, x2, y2; double x1, y1, x2, y2;
int test = FindLineSegmentIntersection( a, b, x1i, y1i, x1f, y1f, CPolyLine::STRAIGHT, int test = FindLineSegmentIntersection( a, b, x1i, y1i, x1f, y1f, STRAIGHT,
&x1, &y1, &x2, &y2 ); &x1, &y1, &x2, &y2 );
if( test ) if( test )
...@@ -668,7 +673,7 @@ bool TestForIntersectionOfStraightLineSegments( int x1i, int y1i, int x1f, int y ...@@ -668,7 +673,7 @@ bool TestForIntersectionOfStraightLineSegments( int x1i, int y1i, int x1f, int y
a = (double) y2i - b * x2i; a = (double) y2i - b * x2i;
double x1, y1, x2, y2; double x1, y1, x2, y2;
int test = FindLineSegmentIntersection( a, b, x1i, y1i, x1f, y1f, CPolyLine::STRAIGHT, int test = FindLineSegmentIntersection( a, b, x1i, y1i, x1f, y1f, STRAIGHT,
&x1, &y1, &x2, &y2 ); &x1, &y1, &x2, &y2 );
if( test ) if( test )
...@@ -696,7 +701,7 @@ bool TestForIntersectionOfStraightLineSegments( int x1i, int y1i, int x1f, int y ...@@ -696,7 +701,7 @@ bool TestForIntersectionOfStraightLineSegments( int x1i, int y1i, int x1f, int y
a = (double) y1i - b * x1i; a = (double) y1i - b * x1i;
double x1, y1, x2, y2; double x1, y1, x2, y2;
int test = FindLineSegmentIntersection( a, b, x2i, y2i, x2f, y2f, CPolyLine::STRAIGHT, int test = FindLineSegmentIntersection( a, b, x2i, y2i, x2f, y2f, STRAIGHT,
&x1, &y1, &x2, &y2 ); &x1, &y1, &x2, &y2 );
if( test ) if( test )
...@@ -724,7 +729,7 @@ bool TestForIntersectionOfStraightLineSegments( int x1i, int y1i, int x1f, int y ...@@ -724,7 +729,7 @@ bool TestForIntersectionOfStraightLineSegments( int x1i, int y1i, int x1f, int y
a = (double) y1i - b * x1i; a = (double) y1i - b * x1i;
double x1, y1, x2, y2; double x1, y1, x2, y2;
int test = FindLineSegmentIntersection( a, b, x2i, y2i, x2f, y2f, CPolyLine::STRAIGHT, int test = FindLineSegmentIntersection( a, b, x2i, y2i, x2f, y2f, STRAIGHT,
&x1, &y1, &x2, &y2 ); &x1, &y1, &x2, &y2 );
if( test ) if( test )
...@@ -760,7 +765,7 @@ bool TestForIntersectionOfStraightLineSegments( int x1i, int y1i, int x1f, int y ...@@ -760,7 +765,7 @@ bool TestForIntersectionOfStraightLineSegments( int x1i, int y1i, int x1f, int y
y2i, y2i,
x2f, x2f,
y2f, y2f,
CPolyLine::STRAIGHT, STRAIGHT,
&x1, &x1,
&y1, &y1,
&x2, &x2,
...@@ -904,7 +909,7 @@ int GetClearanceBetweenSegments( int x1i, int y1i, int x1f, int y1f, int style1, ...@@ -904,7 +909,7 @@ int GetClearanceBetweenSegments( int x1i, int y1i, int x1f, int y1f, int style1,
if( min( y2i, y2f ) - max( y1i, y1f ) > min_dist ) if( min( y2i, y2f ) - max( y1i, y1f ) > min_dist )
return max_cl+1; return max_cl+1;
if( style1 == CPolyLine::STRAIGHT && style1 == CPolyLine::STRAIGHT ) if( style1 == STRAIGHT && style1 == STRAIGHT )
{ {
// both segments are straight lines // both segments are straight lines
int xx, yy; int xx, yy;
...@@ -948,7 +953,7 @@ int GetClearanceBetweenSegments( int x1i, int y1i, int x1f, int y1f, int style1, ...@@ -948,7 +953,7 @@ int GetClearanceBetweenSegments( int x1i, int y1i, int x1f, int y1f, int style1,
bool bArcs; bool bArcs;
int xi = 0, yi = 0, xf = 0, yf = 0; int xi = 0, yi = 0, xf = 0, yf = 0;
if( style2 == CPolyLine::STRAIGHT ) if( style2 == STRAIGHT )
{ {
// style1 = arc, style2 = straight // style1 = arc, style2 = straight
MakeEllipseFromArc( x1i, y1i, x1f, y1f, style1, &el1 ); MakeEllipseFromArc( x1i, y1i, x1f, y1f, style1, &el1 );
...@@ -958,7 +963,7 @@ int GetClearanceBetweenSegments( int x1i, int y1i, int x1f, int y1f, int style1, ...@@ -958,7 +963,7 @@ int GetClearanceBetweenSegments( int x1i, int y1i, int x1f, int y1f, int style1,
yf = y2f; yf = y2f;
bArcs = false; bArcs = false;
} }
else if( style1 == CPolyLine::STRAIGHT ) else if( style1 == STRAIGHT )
{ {
// style2 = arc, style1 = straight // style2 = arc, style1 = straight
xi = x1i; xi = x1i;
......
// math stuff for graphics, from FreePCB // math stuff for graphics, from FreePCB
// math stuff for graphics
bool Quadratic( double a, double b, double c, double *x1, double *x2 );
/** /**
* Function TestLineHit * Function TestLineHit
* test for hit on line segment i.e. a point within a given distance from segment * test for hit on line segment i.e. a point within a given distance from segment
...@@ -16,11 +12,10 @@ bool TestLineHit( int xi, int yi, int xf, int yf, int x, int y, double dist ); ...@@ -16,11 +12,10 @@ bool TestLineHit( int xi, int yi, int xf, int yf, int x, int y, double dist );
int FindLineSegmentIntersection( double a, double b, int xi, int yi, int xf, int yf, int style, int FindLineSegmentIntersection( double a, double b, int xi, int yi, int xf, int yf, int style,
double * x1, double * y1, double * x2, double * y2, double * dist=NULL ); double * x1, double * y1, double * x2, double * y2, double * dist=NULL );
int FindSegmentIntersections( int xi, int yi, int xf, int yf, int style, int FindSegmentIntersections( int xi, int yi, int xf, int yf, int style,
int xi2, int yi2, int xf2, int yf2, int style2, int xi2, int yi2, int xf2, int yf2, int style2,
double x[]=NULL, double y[]=NULL ); double x[]=NULL, double y[]=NULL );
bool FindLineEllipseIntersections( double a, double b, double c, double d, double *x1, double *x2 );
bool FindVerticalLineEllipseIntersections( double a, double b, double x, double *y1, double *y2 );
/** /**
* Function TestForIntersectionOfStraightLineSegments * Function TestForIntersectionOfStraightLineSegments
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment