Commit 6a93777a authored by jean-pierre charras's avatar jean-pierre charras

Polyline.h: remove useless class CRect. Use the more powerful EDA_RECT...

Polyline.h: remove useless class CRect. Use the more powerful EDA_RECT instead. Clean and remove duplicate code.
parent 3764021e
...@@ -38,6 +38,7 @@ ...@@ -38,6 +38,7 @@
#include <bitmaps.h> #include <bitmaps.h>
#include <richio.h> #include <richio.h>
#include <view/view_item.h> #include <view/view_item.h>
#include <class_eda_rect.h>
#if defined(DEBUG) #if defined(DEBUG)
#include <iostream> // needed for Show() #include <iostream> // needed for Show()
...@@ -113,181 +114,6 @@ public: ...@@ -113,181 +114,6 @@ public:
}; };
/**
* Class EDA_RECT
* handles the component boundary box.
* This class is similar to wxRect, but some wxRect functions are very curious,
* and are working only if dimensions are >= 0 (not always the case in KiCad)
* and also KiCad needs some specific method.
* so I prefer this more suitable class
*/
class EDA_RECT
{
private:
wxPoint m_Pos; // Rectangle Origin
wxSize m_Size; // Rectangle Size
public:
EDA_RECT() { };
EDA_RECT( const wxPoint& aPos, const wxSize& aSize ) :
m_Pos( aPos ),
m_Size( aSize )
{ }
wxPoint Centre() const
{
return wxPoint( m_Pos.x + ( m_Size.x >> 1 ),
m_Pos.y + ( m_Size.y >> 1 ) );
}
/**
* Function Move
* moves the rectangle by the \a aMoveVector.
* @param aMoveVector A wxPoint that is the value to move this rectangle
*/
void Move( const wxPoint& aMoveVector );
/**
* Function Normalize
* ensures that the height ant width are positive.
*/
void Normalize();
/**
* Function Contains
* @param aPoint = the wxPoint to test
* @return true if aPoint is inside the boundary box. A point on a edge is seen as inside
*/
bool Contains( const wxPoint& aPoint ) const;
/**
* Function Contains
* @param x = the x coordinate of the point to test
* @param y = the x coordinate of the point to test
* @return true if point is inside the boundary box. A point on a edge is seen as inside
*/
bool Contains( int x, int y ) const { return Contains( wxPoint( x, y ) ); }
/**
* Function Contains
* @param aRect = the EDA_RECT to test
* @return true if aRect is Contained. A common edge is seen as contained
*/
bool Contains( const EDA_RECT& aRect ) const;
const wxSize& GetSize() const { return m_Size; }
int GetX() const { return m_Pos.x; }
int GetY() const { return m_Pos.y; }
const wxPoint& GetOrigin() const { return m_Pos; }
const wxPoint& GetPosition() const { return m_Pos; }
const wxPoint GetEnd() const { return wxPoint( GetRight(), GetBottom() ); }
int GetWidth() const { return m_Size.x; }
int GetHeight() const { return m_Size.y; }
int GetRight() const { return m_Pos.x + m_Size.x; }
int GetBottom() const { return m_Pos.y + m_Size.y; }
void SetOrigin( const wxPoint& pos ) { m_Pos = pos; }
void SetOrigin( int x, int y ) { m_Pos.x = x; m_Pos.y = y; }
void SetSize( const wxSize& size ) { m_Size = size; }
void SetSize( int w, int h ) { m_Size.x = w; m_Size.y = h; }
void Offset( int dx, int dy ) { m_Pos.x += dx; m_Pos.y += dy; }
void Offset( const wxPoint& offset ) { m_Pos.x += offset.x; m_Pos.y +=
offset.y; }
void SetX( int val ) { m_Pos.x = val; }
void SetY( int val ) { m_Pos.y = val; }
void SetWidth( int val ) { m_Size.x = val; }
void SetHeight( int val ) { m_Size.y = val; }
void SetEnd( int x, int y ) { SetEnd( wxPoint( x, y ) ); }
void SetEnd( const wxPoint& pos )
{
m_Size.x = pos.x - m_Pos.x; m_Size.y = pos.y - m_Pos.y;
}
/**
* Function Intersects
* tests for a common area between rectangles.
*
* @param aRect A rectangle to test intersection with.
* @return bool - true if the argument rectangle intersects this rectangle.
* (i.e. if the 2 rectangles have at least a common point)
*/
bool Intersects( const EDA_RECT& aRect ) const;
/**
* Function Intersects
* tests for a common area between a segment and this rectangle.
*
* @param aPoint1 First point of the segment to test intersection with.
* @param aPoint2 Second point of the segment to test intersection with.
* @return bool - true if the argument segment intersects this rectangle.
* (i.e. if the segment and rectangle have at least a common point)
*/
bool Intersects( const wxPoint& aPoint1, const wxPoint& aPoint2 ) const;
/**
* Function operator(wxRect)
* overloads the cast operator to return a wxRect
* wxRect does not accept negative values for size, so ensure the
* wxRect size is always >= 0
*/
operator wxRect() const
{
EDA_RECT rect( m_Pos, m_Size );
rect.Normalize();
return wxRect( rect.m_Pos, rect.m_Size );
}
/**
* Function Inflate
* inflates the rectangle horizontally by \a dx and vertically by \a dy. If \a dx
* and/or \a dy is negative the rectangle is deflated.
*/
EDA_RECT& Inflate( wxCoord dx, wxCoord dy );
/**
* Function Inflate
* inflates the rectangle horizontally and vertically by \a aDelta. If \a aDelta
* is negative the rectangle is deflated.
*/
EDA_RECT& Inflate( int aDelta );
/**
* Function Merge
* modifies the position and size of the rectangle in order to contain \a aRect. It is
* mainly used to calculate bounding boxes.
* @param aRect The rectangle to merge with this rectangle.
*/
void Merge( const EDA_RECT& aRect );
/**
* Function Merge
* modifies the position and size of the rectangle in order to contain the given point.
* @param aPoint The point to merge with the rectangle.
*/
void Merge( const wxPoint& aPoint );
/**
* Function GetArea
* returns the area of the rectangle.
* @return The area of the rectangle.
*/
double GetArea() const;
/**
* Function GetBoundingBoxRotated
* @return the bounding box of this, after rotation
* @param aAngle = the rotation angle in 0.1 deg.
* @param aRotCenter = the rotation point.
* useful to calculate bounding box of rotated items, when
* rotation if not k*90 degrees
*/
const EDA_RECT GetBoundingBoxRotated( wxPoint aRotCenter, double aAngle );
};
// These define are used for the .m_Flags and .m_UndoRedoStatus member of the // These define are used for the .m_Flags and .m_UndoRedoStatus member of the
// class EDA_ITEM // class EDA_ITEM
#define IS_CHANGED (1 << 0) ///< Item was edited, and modified #define IS_CHANGED (1 << 0) ///< Item was edited, and modified
......
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2014 Jean-Pierre Charras, jp.charras at wanadoo.fr
* Copyright (C) 2004-2014 KiCad Developers, see change_log.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 class_eda_rect.h
*/
#ifndef CLASS_EDA_RECT_H
#define CLASS_EDA_RECT_H
/**
* Class EDA_RECT
* handles the component boundary box.
* This class is similar to wxRect, but some wxRect functions are very curious,
* and are working only if dimensions are >= 0 (not always the case in KiCad)
* and also KiCad needs some specific method.
* so I prefer this more suitable class
*/
class EDA_RECT
{
private:
wxPoint m_Pos; // Rectangle Origin
wxSize m_Size; // Rectangle Size
public:
EDA_RECT() { };
EDA_RECT( const wxPoint& aPos, const wxSize& aSize ) :
m_Pos( aPos ),
m_Size( aSize )
{ }
wxPoint Centre() const
{
return wxPoint( m_Pos.x + ( m_Size.x >> 1 ),
m_Pos.y + ( m_Size.y >> 1 ) );
}
/**
* Function Move
* moves the rectangle by the \a aMoveVector.
* @param aMoveVector A wxPoint that is the value to move this rectangle
*/
void Move( const wxPoint& aMoveVector );
/**
* Function Normalize
* ensures that the height ant width are positive.
*/
void Normalize();
/**
* Function Contains
* @param aPoint = the wxPoint to test
* @return true if aPoint is inside the boundary box. A point on a edge is seen as inside
*/
bool Contains( const wxPoint& aPoint ) const;
/**
* Function Contains
* @param x = the x coordinate of the point to test
* @param y = the x coordinate of the point to test
* @return true if point is inside the boundary box. A point on a edge is seen as inside
*/
bool Contains( int x, int y ) const { return Contains( wxPoint( x, y ) ); }
/**
* Function Contains
* @param aRect = the EDA_RECT to test
* @return true if aRect is Contained. A common edge is seen as contained
*/
bool Contains( const EDA_RECT& aRect ) const;
const wxSize& GetSize() const { return m_Size; }
int GetX() const { return m_Pos.x; }
int GetY() const { return m_Pos.y; }
const wxPoint& GetOrigin() const { return m_Pos; }
const wxPoint& GetPosition() const { return m_Pos; }
const wxPoint GetEnd() const { return wxPoint( m_Pos.x + m_Size.x, m_Pos.y + m_Size.y ); }
int GetWidth() const { return m_Size.x; }
int GetHeight() const { return m_Size.y; }
int GetRight() const { return m_Pos.x + m_Size.x; }
int GetLeft() const { return m_Pos.x; }
int GetBottom() const { return m_Pos.y + m_Size.y; } // Y axis from top to bottom
void SetOrigin( const wxPoint& pos ) { m_Pos = pos; }
void SetOrigin( int x, int y ) { m_Pos.x = x; m_Pos.y = y; }
void SetSize( const wxSize& size ) { m_Size = size; }
void SetSize( int w, int h ) { m_Size.x = w; m_Size.y = h; }
void Offset( int dx, int dy ) { m_Pos.x += dx; m_Pos.y += dy; }
void Offset( const wxPoint& offset ) { m_Pos.x += offset.x; m_Pos.y +=
offset.y; }
void SetX( int val ) { m_Pos.x = val; }
void SetY( int val ) { m_Pos.y = val; }
void SetWidth( int val ) { m_Size.x = val; }
void SetHeight( int val ) { m_Size.y = val; }
void SetEnd( int x, int y ) { SetEnd( wxPoint( x, y ) ); }
void SetEnd( const wxPoint& pos )
{
m_Size.x = pos.x - m_Pos.x; m_Size.y = pos.y - m_Pos.y;
}
/**
* Function Intersects
* tests for a common area between rectangles.
*
* @param aRect A rectangle to test intersection with.
* @return bool - true if the argument rectangle intersects this rectangle.
* (i.e. if the 2 rectangles have at least a common point)
*/
bool Intersects( const EDA_RECT& aRect ) const;
/**
* Function Intersects
* tests for a common area between a segment and this rectangle.
*
* @param aPoint1 First point of the segment to test intersection with.
* @param aPoint2 Second point of the segment to test intersection with.
* @return bool - true if the argument segment intersects this rectangle.
* (i.e. if the segment and rectangle have at least a common point)
*/
bool Intersects( const wxPoint& aPoint1, const wxPoint& aPoint2 ) const;
/**
* Function operator(wxRect)
* overloads the cast operator to return a wxRect
* wxRect does not accept negative values for size, so ensure the
* wxRect size is always >= 0
*/
operator wxRect() const
{
EDA_RECT rect( m_Pos, m_Size );
rect.Normalize();
return wxRect( rect.m_Pos, rect.m_Size );
}
/**
* Function Inflate
* inflates the rectangle horizontally by \a dx and vertically by \a dy. If \a dx
* and/or \a dy is negative the rectangle is deflated.
*/
EDA_RECT& Inflate( wxCoord dx, wxCoord dy );
/**
* Function Inflate
* inflates the rectangle horizontally and vertically by \a aDelta. If \a aDelta
* is negative the rectangle is deflated.
*/
EDA_RECT& Inflate( int aDelta );
/**
* Function Merge
* modifies the position and size of the rectangle in order to contain \a aRect. It is
* mainly used to calculate bounding boxes.
* @param aRect The rectangle to merge with this rectangle.
*/
void Merge( const EDA_RECT& aRect );
/**
* Function Merge
* modifies the position and size of the rectangle in order to contain the given point.
* @param aPoint The point to merge with the rectangle.
*/
void Merge( const wxPoint& aPoint );
/**
* Function GetArea
* returns the area of the rectangle.
* @return The area of the rectangle.
*/
double GetArea() const;
/**
* Function GetBoundingBoxRotated
* @return the bounding box of this, after rotation
* @param aAngle = the rotation angle in 0.1 deg.
* @param aRotCenter = the rotation point.
* useful to calculate bounding box of rotated items, when
* rotation if not k*90 degrees
*/
const EDA_RECT GetBoundingBoxRotated( wxPoint aRotCenter, double aAngle );
};
#endif // CLASS_EDA_RECT_H
...@@ -262,7 +262,7 @@ void ZONE_CONTAINER::DrawFilledArea( EDA_DRAW_PANEL* panel, ...@@ -262,7 +262,7 @@ void ZONE_CONTAINER::DrawFilledArea( EDA_DRAW_PANEL* panel,
const CPolyPt& corner = m_FilledPolysList.GetCorner( ic ); const CPolyPt& corner = m_FilledPolysList.GetCorner( ic );
wxPoint coord( corner.x + offset.x, corner.y + offset.y ); wxPoint coord( corner.x + offset.x, corner.y + offset.y );
CornersBuffer.push_back( coord ); CornersBuffer.push_back( coord );
CornersTypeBuffer.push_back( (char) corner.m_utility ); CornersTypeBuffer.push_back( (char) corner.m_flags );
// the last corner of a filled area is found: draw it // the last corner of a filled area is found: draw it
if( (corner.end_contour) || (ic == imax) ) if( (corner.end_contour) || (ic == imax) )
...@@ -273,9 +273,9 @@ void ZONE_CONTAINER::DrawFilledArea( EDA_DRAW_PANEL* panel, ...@@ -273,9 +273,9 @@ void ZONE_CONTAINER::DrawFilledArea( EDA_DRAW_PANEL* panel,
* just draw filled polygons but with outlines thickness = m_ZoneMinThickness * just draw filled polygons but with outlines thickness = m_ZoneMinThickness
* So DO NOT use draw filled polygons with outlines having a thickness > 0 * So DO NOT use draw filled polygons with outlines having a thickness > 0
* Note: Extra segments ( added to joint holes with external outline) flagged by * Note: Extra segments ( added to joint holes with external outline) flagged by
* m_utility != 0 are not drawn * m_flags != 0 are not drawn
* Note not all polygon libraries provide a flag for these extra-segments, therefore * Note not all polygon libraries provide a flag for these extra-segments, therefore
* the m_utility member can be always 0 * the m_flags member can be always 0
*/ */
{ {
// Draw outlines: // Draw outlines:
...@@ -485,11 +485,8 @@ bool ZONE_CONTAINER::HitTest( const EDA_RECT& aRect, bool aContained, int aAccur ...@@ -485,11 +485,8 @@ bool ZONE_CONTAINER::HitTest( const EDA_RECT& aRect, bool aContained, int aAccur
{ {
EDA_RECT arect = aRect; EDA_RECT arect = aRect;
arect.Inflate( aAccuracy ); arect.Inflate( aAccuracy );
CRect rect = m_Poly->GetBoundingBox(); EDA_RECT bbox = m_Poly->GetBoundingBox();
EDA_RECT bbox; bbox.Normalize();
bbox.SetOrigin( rect.left, rect.bottom );
bbox.SetEnd( rect.right, rect.top );
if( aContained ) if( aContained )
return arect.Contains( bbox ); return arect.Contains( bbox );
......
...@@ -175,7 +175,7 @@ int ZONE_CONTAINER::FillZoneAreasWithSegments() ...@@ -175,7 +175,7 @@ int ZONE_CONTAINER::FillZoneAreasWithSegments()
for( ics = istart, ice = iend; ics <= iend; ice = ics, ics++ ) for( ics = istart, ice = iend; ics <= iend; ice = ics, ics++ )
{ {
if( m_FilledPolysList[ice].m_utility ) if( m_FilledPolysList[ice].m_flags )
continue; continue;
int seg_startX = m_FilledPolysList[ics].x; int seg_startX = m_FilledPolysList[ics].x;
......
...@@ -93,7 +93,7 @@ bool BOARD::CombineAllAreasInNet( PICKED_ITEMS_LIST* aDeletedList, int aNetCode, ...@@ -93,7 +93,7 @@ bool BOARD::CombineAllAreasInNet( PICKED_ITEMS_LIST* aDeletedList, int aNetCode,
bool modified = false; bool modified = false;
//Loop through all combinations // Loop through all combinations
for( unsigned ia1 = 0; ia1 < m_ZoneDescriptorList.size() - 1; ia1++ ) for( unsigned ia1 = 0; ia1 < m_ZoneDescriptorList.size() - 1; ia1++ )
{ {
ZONE_CONTAINER* curr_area = m_ZoneDescriptorList[ia1]; ZONE_CONTAINER* curr_area = m_ZoneDescriptorList[ia1];
...@@ -102,7 +102,7 @@ bool BOARD::CombineAllAreasInNet( PICKED_ITEMS_LIST* aDeletedList, int aNetCode, ...@@ -102,7 +102,7 @@ bool BOARD::CombineAllAreasInNet( PICKED_ITEMS_LIST* aDeletedList, int aNetCode,
continue; continue;
// legal polygon // legal polygon
CRect b1 = curr_area->Outline()->GetBoundingBox(); EDA_RECT b1 = curr_area->Outline()->GetBoundingBox();
bool mod_ia1 = false; bool mod_ia1 = false;
for( unsigned ia2 = m_ZoneDescriptorList.size() - 1; ia2 > ia1; ia2-- ) for( unsigned ia2 = m_ZoneDescriptorList.size() - 1; ia2 > ia1; ia2-- )
...@@ -121,10 +121,9 @@ bool BOARD::CombineAllAreasInNet( PICKED_ITEMS_LIST* aDeletedList, int aNetCode, ...@@ -121,10 +121,9 @@ bool BOARD::CombineAllAreasInNet( PICKED_ITEMS_LIST* aDeletedList, int aNetCode,
if( curr_area->GetLayer() != area2->GetLayer() ) if( curr_area->GetLayer() != area2->GetLayer() )
continue; continue;
CRect b2 = area2->Outline()->GetBoundingBox(); EDA_RECT b2 = area2->Outline()->GetBoundingBox();
if( !( b1.left > b2.right || b1.right < b2.left if( b1.Intersects( b2 ) )
|| b1.bottom > b2.top || b1.top < b2.bottom ) )
{ {
// check area2 against curr_area // check area2 against curr_area
if( curr_area->GetLocalFlags() || area2->GetLocalFlags() if( curr_area->GetLocalFlags() || area2->GetLocalFlags()
...@@ -194,11 +193,10 @@ bool BOARD::TestAreaIntersection( ZONE_CONTAINER* area_ref, ZONE_CONTAINER* area ...@@ -194,11 +193,10 @@ bool BOARD::TestAreaIntersection( ZONE_CONTAINER* area_ref, ZONE_CONTAINER* area
CPolyLine* poly2 = area_to_test->Outline(); CPolyLine* poly2 = area_to_test->Outline();
// test bounding rects // test bounding rects
CRect b1 = poly1->GetBoundingBox(); EDA_RECT b1 = poly1->GetBoundingBox();
CRect b2 = poly2->GetBoundingBox(); EDA_RECT b2 = poly2->GetBoundingBox();
if( b1.bottom > b2.top || b1.top < b2.bottom || if( ! b1.Intersects( b2 ) )
b1.left > b2.right || b1.right < b2.left )
return false; return false;
// now test for intersecting segments // now test for intersecting segments
......
...@@ -53,7 +53,7 @@ CPolyLine::CPolyLine() ...@@ -53,7 +53,7 @@ CPolyLine::CPolyLine()
m_hatchStyle = NO_HATCH; m_hatchStyle = NO_HATCH;
m_hatchPitch = 0; m_hatchPitch = 0;
m_layer = F_Cu; m_layer = F_Cu;
m_utility = 0; m_flags = 0;
} }
CPolyLine::CPolyLine( const CPolyLine& aCPolyLine) CPolyLine::CPolyLine( const CPolyLine& aCPolyLine)
...@@ -599,7 +599,6 @@ void CPolyLine::InsertCorner( int ic, int x, int y ) ...@@ -599,7 +599,6 @@ void CPolyLine::InsertCorner( int ic, int x, int y )
// undraw polyline by removing all graphic elements from display list // undraw polyline by removing all graphic elements from display list
//
void CPolyLine::UnHatch() void CPolyLine::UnHatch()
{ {
m_HatchLines.clear(); m_HatchLines.clear();
...@@ -612,42 +611,50 @@ int CPolyLine::GetEndContour( int ic ) ...@@ -612,42 +611,50 @@ int CPolyLine::GetEndContour( int ic )
} }
CRect CPolyLine::GetBoundingBox() EDA_RECT CPolyLine::GetBoundingBox()
{ {
CRect r; int xmin = INT_MAX;
int ymin = INT_MAX;
r.left = r.bottom = INT_MAX; int xmax = INT_MIN;
r.right = r.top = INT_MIN; int ymax = INT_MIN;
for( unsigned i = 0; i< m_CornersList.GetCornersCount(); i++ ) for( unsigned i = 0; i< m_CornersList.GetCornersCount(); i++ )
{ {
r.left = std::min( r.left, m_CornersList[i].x ); xmin = std::min( xmin, m_CornersList[i].x );
r.right = std::max( r.right, m_CornersList[i].x ); xmax = std::max( xmax, m_CornersList[i].x );
r.bottom = std::min( r.bottom, m_CornersList[i].y ); ymin = std::min( ymin, m_CornersList[i].y );
r.top = std::max( r.top, m_CornersList[i].y ); ymax = std::max( ymax, m_CornersList[i].y );
} }
EDA_RECT r;
r.SetOrigin( wxPoint( xmin, ymin ) );
r.SetEnd( wxPoint( xmax, ymax ) );
return r; return r;
} }
CRect CPolyLine::GetBoundingBox( int icont ) EDA_RECT CPolyLine::GetBoundingBox( int icont )
{ {
CRect r; int xmin = INT_MAX;
int ymin = INT_MAX;
r.left = r.bottom = INT_MAX; int xmax = INT_MIN;
r.right = r.top = INT_MIN; int ymax = INT_MIN;
int istart = GetContourStart( icont ); int istart = GetContourStart( icont );
int iend = GetContourEnd( icont ); int iend = GetContourEnd( icont );
for( int i = istart; i<=iend; i++ ) for( int i = istart; i<=iend; i++ )
{ {
r.left = std::min( r.left, m_CornersList[i].x ); xmin = std::min( xmin, m_CornersList[i].x );
r.right = std::max( r.right, m_CornersList[i].x ); xmax = std::max( xmax, m_CornersList[i].x );
r.bottom = std::min( r.bottom, m_CornersList[i].y ); ymin = std::min( ymin, m_CornersList[i].y );
r.top = std::max( r.top, m_CornersList[i].y ); ymax = std::max( ymax, m_CornersList[i].y );
} }
EDA_RECT r;
r.SetOrigin( wxPoint( xmin, ymin ) );
r.SetEnd( wxPoint( xmax, ymax ) );
return r; return r;
} }
...@@ -1469,7 +1476,7 @@ bool CPolyLine::IsPolygonSelfIntersecting() ...@@ -1469,7 +1476,7 @@ bool CPolyLine::IsPolygonSelfIntersecting()
int n_cont = GetContoursCount(); int n_cont = GetContoursCount();
// make bounding rect for each contour // make bounding rect for each contour
std::vector<CRect> cr; std::vector<EDA_RECT> cr;
cr.reserve( n_cont ); cr.reserve( n_cont );
for( int icont = 0; icont<n_cont; icont++ ) for( int icont = 0; icont<n_cont; icont++ )
...@@ -1498,12 +1505,9 @@ bool CPolyLine::IsPolygonSelfIntersecting() ...@@ -1498,12 +1505,9 @@ bool CPolyLine::IsPolygonSelfIntersecting()
int y1f = GetY( is_next ); int y1f = GetY( is_next );
// check for intersection with any other sides // check for intersection with any other sides
for( int icont2 = icont; icont2<n_cont; icont2++ ) for( int icont2 = icont; icont2 < n_cont; icont2++ )
{ {
if( cr[icont].left > cr[icont2].right if( !cr[icont].Intersects( cr[icont2] ) )
|| cr[icont].bottom > cr[icont2].top
|| cr[icont2].left > cr[icont].right
|| cr[icont2].bottom > cr[icont].top )
{ {
// rectangles don't overlap, do nothing // rectangles don't overlap, do nothing
} }
......
...@@ -5,6 +5,8 @@ ...@@ -5,6 +5,8 @@
* (see http://www.freepcb.com/ ) * (see http://www.freepcb.com/ )
* *
* Copyright (C) 2012-2014 Jean-Pierre Charras, jp.charras at wanadoo.fr * Copyright (C) 2012-2014 Jean-Pierre Charras, jp.charras at wanadoo.fr
* Copyright (C) 2008-2013 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
* Copyright (C) 2008-2013 Wayne Stambaugh <stambaughw@verizon.net>
* Copyright (C) 2012-2014 KiCad Developers, see CHANGELOG.TXT for contributors. * Copyright (C) 2012-2014 KiCad Developers, see CHANGELOG.TXT for contributors.
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
...@@ -48,17 +50,11 @@ ...@@ -48,17 +50,11 @@
#include <vector> #include <vector>
#include <pad_shapes.h> #include <wx/gdicmn.h> // for wxPoint definition
#include <wx/gdicmn.h> // for wxPoint definition #include <layers_id_colors_and_visibility.h> // for LAYER_NUM definition
#include <layers_id_colors_and_visibility.h> #include <class_eda_rect.h> // for EDA_RECT definition
#include <polygons_defs.h> #include <polygons_defs.h>
class CRect
{
public:
int left, right, top, bottom;
};
class CSegment class CSegment
{ {
public: public:
...@@ -83,22 +79,22 @@ class CPolyPt : public wxPoint ...@@ -83,22 +79,22 @@ class CPolyPt : public wxPoint
{ {
public: public:
CPolyPt( int aX = 0, int aY = 0, bool aEnd = false, int aUtility = 0 ) : CPolyPt( int aX = 0, int aY = 0, bool aEnd = false, int aUtility = 0 ) :
wxPoint( aX, aY ), end_contour( aEnd ), m_utility( aUtility ) wxPoint( aX, aY ), end_contour( aEnd ), m_flags( aUtility )
{} {}
// / Pure copy constructor is here to dis-ambiguate from the // / Pure copy constructor is here to dis-ambiguate from the
// / specialized CPolyPt( const wxPoint& ) constructor version below. // / specialized CPolyPt( const wxPoint& ) constructor version below.
CPolyPt( const CPolyPt& aPt ) : CPolyPt( const CPolyPt& aPt ) :
wxPoint( aPt.x, aPt.y ), end_contour( aPt.end_contour ), m_utility( aPt.m_utility ) wxPoint( aPt.x, aPt.y ), end_contour( aPt.end_contour ), m_flags( aPt.m_flags )
{} {}
CPolyPt( const wxPoint& aPoint ) : CPolyPt( const wxPoint& aPoint ) :
wxPoint( aPoint ), end_contour( false ), m_utility( 0 ) wxPoint( aPoint ), end_contour( false ), m_flags( 0 )
{} {}
bool end_contour; bool end_contour;
int m_utility; int m_flags;
bool operator ==( const CPolyPt& cpt2 ) const bool operator ==( const CPolyPt& cpt2 ) const
{ return (x == cpt2.x) && (y == cpt2.y) && (end_contour == cpt2.end_contour); } { return (x == cpt2.x) && (y == cpt2.y) && (end_contour == cpt2.end_contour); }
...@@ -127,10 +123,10 @@ public: ...@@ -127,10 +123,10 @@ public:
void SetX( int ic, int aValue ) { m_cornersList[ic].x = aValue; } void SetX( int ic, int aValue ) { m_cornersList[ic].x = aValue; }
int GetY( int ic ) const { return m_cornersList[ic].y; } int GetY( int ic ) const { return m_cornersList[ic].y; }
void SetY( int ic, int aValue ) { m_cornersList[ic].y = aValue; } void SetY( int ic, int aValue ) { m_cornersList[ic].y = aValue; }
int GetUtility( int ic ) const { return m_cornersList[ic].m_utility; } int GetUtility( int ic ) const { return m_cornersList[ic].m_flags; }
void SetFlag( int ic, int aFlag ) void SetFlag( int ic, int aFlag )
{ {
m_cornersList[ic].m_utility = aFlag; m_cornersList[ic].m_flags = aFlag;
} }
bool IsEndContour( int ic ) const bool IsEndContour( int ic ) const
...@@ -327,8 +323,18 @@ public: ...@@ -327,8 +323,18 @@ public:
void MoveOrigin( int x_off, int y_off ); void MoveOrigin( int x_off, int y_off );
// misc. functions // misc. functions
CRect GetBoundingBox(); /**
CRect GetBoundingBox( int icont ); * @return the full bounding box of polygons
*/
EDA_RECT GetBoundingBox();
/**
* @return the bounding box of a given polygon
* @param icont = the index of the polygon contour
* (0 = main contour, 1 ... n = other contours, usually holes)
*/
EDA_RECT GetBoundingBox( int icont );
void Copy( const CPolyLine* src ); void Copy( const CPolyLine* src );
bool TestPointInside( int x, int y ); bool TestPointInside( int x, int y );
...@@ -464,7 +470,7 @@ private: ...@@ -464,7 +470,7 @@ private:
int m_hatchPitch; // for DIAGONAL_EDGE hatched outlines, basic distance between 2 hatch lines int m_hatchPitch; // for DIAGONAL_EDGE hatched outlines, basic distance between 2 hatch lines
// and the len of eacvh segment // and the len of eacvh segment
// for DIAGONAL_FULL, the pitch is twice this value // for DIAGONAL_FULL, the pitch is twice this value
int m_utility; // a flag used in some calculations int m_flags; // a flag used in some calculations
public: public:
CPOLYGONS_LIST m_CornersList; // array of points for corners CPOLYGONS_LIST m_CornersList; // array of points for corners
std::vector <CSegment> m_HatchLines; // hatch lines showing the polygon area std::vector <CSegment> m_HatchLines; // hatch lines showing the polygon area
......
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