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

Pcbnew: very minor fixes and update: update clipper version. uncrustify...

Pcbnew: very minor fixes and update:  update clipper version. uncrustify polytri/* and fix some warning compil.
parent 6e56aa2f
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
#ifndef DRW_BASE_H #ifndef DRW_BASE_H
#define DRW_BASE_H #define DRW_BASE_H
#define DRW_VERSION "0.5.10" #define DRW_VERSION "0.5.11"
#include <string> #include <string>
#include <cmath> #include <cmath>
......
...@@ -27,7 +27,7 @@ class dxfRW ...@@ -27,7 +27,7 @@ class dxfRW
public: public:
dxfRW( const char* name ); dxfRW( const char* name );
~dxfRW(); ~dxfRW();
// / reads the file specified in constructor /// reads the file specified in constructor
/*! /*!
* An interface must be provided. It is used by the class to signal various * An interface must be provided. It is used by the class to signal various
* components being added. * components being added.
...@@ -71,7 +71,7 @@ public: ...@@ -71,7 +71,7 @@ public:
void setEllipseParts( int parts ) { elParts = parts; } /*!< set parts munber when convert ellipse to polyline */ void setEllipseParts( int parts ) { elParts = parts; } /*!< set parts munber when convert ellipse to polyline */
private: private:
// / used by read() to parse the content of the file /// used by read() to parse the content of the file
bool processDxf(); bool processDxf();
bool processHeader(); bool processHeader();
bool processTables(); bool processTables();
......
...@@ -88,8 +88,8 @@ CPolyLine::~CPolyLine() ...@@ -88,8 +88,8 @@ CPolyLine::~CPolyLine()
#include "clipper.hpp" #include "clipper.hpp"
int CPolyLine::NormalizeAreaOutlines( std::vector<CPolyLine*>* aNewPolygonList ) int CPolyLine::NormalizeAreaOutlines( std::vector<CPolyLine*>* aNewPolygonList )
{ {
ClipperLib::Polygon raw_polygon; ClipperLib::Path raw_polygon;
ClipperLib::Polygons normalized_polygons; ClipperLib::Paths normalized_polygons;
unsigned corners_count = m_CornersList.GetCornersCount(); unsigned corners_count = m_CornersList.GetCornersCount();
...@@ -115,7 +115,7 @@ int CPolyLine::NormalizeAreaOutlines( std::vector<CPolyLine*>* aNewPolygonList ) ...@@ -115,7 +115,7 @@ int CPolyLine::NormalizeAreaOutlines( std::vector<CPolyLine*>* aNewPolygonList )
// enter main outline // enter main outline
for( unsigned ii = 0; ii < normalized_polygons.size(); ii++ ) for( unsigned ii = 0; ii < normalized_polygons.size(); ii++ )
{ {
ClipperLib::Polygon& polygon = normalized_polygons[ii]; ClipperLib::Path& polygon = normalized_polygons[ii];
cornerslist.clear(); cornerslist.clear();
for( unsigned jj = 0; jj < polygon.size(); jj++ ) for( unsigned jj = 0; jj < polygon.size(); jj++ )
cornerslist.push_back( KI_POLY_POINT( KiROUND( polygon[jj].X ), cornerslist.push_back( KI_POLY_POINT( KiROUND( polygon[jj].X ),
...@@ -142,7 +142,7 @@ int CPolyLine::NormalizeAreaOutlines( std::vector<CPolyLine*>* aNewPolygonList ) ...@@ -142,7 +142,7 @@ int CPolyLine::NormalizeAreaOutlines( std::vector<CPolyLine*>* aNewPolygonList )
ClipperLib::SimplifyPolygon( raw_polygon, normalized_polygons ); ClipperLib::SimplifyPolygon( raw_polygon, normalized_polygons );
for( unsigned ii = 0; ii < normalized_polygons.size(); ii++ ) for( unsigned ii = 0; ii < normalized_polygons.size(); ii++ )
{ {
ClipperLib::Polygon& polygon = normalized_polygons[ii]; ClipperLib::Path& polygon = normalized_polygons[ii];
cornerslist.clear(); cornerslist.clear();
for( unsigned jj = 0; jj < polygon.size(); jj++ ) for( unsigned jj = 0; jj < polygon.size(); jj++ )
cornerslist.push_back( KI_POLY_POINT( KiROUND( polygon[jj].X ), cornerslist.push_back( KI_POLY_POINT( KiROUND( polygon[jj].X ),
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
...@@ -39,11 +39,10 @@ ...@@ -39,11 +39,10 @@
#include <cmath> #include <cmath>
namespace p2t { namespace p2t {
struct Edge; struct Edge;
struct Point { struct Point
{
double x, y; double x, y;
/// Default constructor does nothing (for performance). /// Default constructor does nothing (for performance).
...@@ -57,7 +56,7 @@ struct Point { ...@@ -57,7 +56,7 @@ struct Point {
std::vector<Edge*> edge_list; std::vector<Edge*> edge_list;
/// Construct using coordinates. /// Construct using coordinates.
Point(double x, double y) : x(x), y(y) {} Point( double x, double y ) : x( x ), y( y ) {}
/// Set this point to all zeros. /// Set this point to all zeros.
void set_zero() void set_zero()
...@@ -67,7 +66,7 @@ struct Point { ...@@ -67,7 +66,7 @@ struct Point {
} }
/// Set this point to some specified coordinates. /// Set this point to some specified coordinates.
void set(double x_, double y_) void set( double x_, double y_ )
{ {
x = x_; x = x_;
y = y_; y = y_;
...@@ -77,26 +76,27 @@ struct Point { ...@@ -77,26 +76,27 @@ struct Point {
Point operator -() const Point operator -() const
{ {
Point v; Point v;
v.set(-x, -y);
v.set( -x, -y );
return v; return v;
} }
/// Add a point to this point. /// Add a point to this point.
void operator +=(const Point& v) void operator +=( const Point& v )
{ {
x += v.x; x += v.x;
y += v.y; y += v.y;
} }
/// Subtract a point from this point. /// Subtract a point from this point.
void operator -=(const Point& v) void operator -=( const Point& v )
{ {
x -= v.x; x -= v.x;
y -= v.y; y -= v.y;
} }
/// Multiply this point by a scalar. /// Multiply this point by a scalar.
void operator *=(double a) void operator *=( double a )
{ {
x *= a; x *= a;
y *= a; y *= a;
...@@ -105,221 +105,247 @@ struct Point { ...@@ -105,221 +105,247 @@ struct Point {
/// Get the length of this point (the norm). /// Get the length of this point (the norm).
double Length() const double Length() const
{ {
return sqrt(x * x + y * y); return sqrt( x * x + y * y );
} }
/// Convert this point into a unit point. Returns the Length. /// Convert this point into a unit point. Returns the Length.
double Normalize() double Normalize()
{ {
double len = Length(); double len = Length();
x /= len; x /= len;
y /= len; y /= len;
return len; return len;
} }
}; };
// Represents a simple polygon's edge // Represents a simple polygon's edge
struct Edge { struct Edge
{
Point* p, *q; Point* p, * q;
/// Constructor /// Constructor
Edge(Point& p1, Point& p2) : p(&p1), q(&p2) Edge( Point& p1, Point& p2 ) : p( &p1 ), q( &p2 )
{
if( p1.y > p2.y )
{ {
if (p1.y > p2.y) {
q = &p1; q = &p1;
p = &p2; p = &p2;
} else if (p1.y == p2.y) { }
if (p1.x > p2.x) { else if( p1.y == p2.y )
{
if( p1.x > p2.x )
{
q = &p1; q = &p1;
p = &p2; p = &p2;
} else if (p1.x == p2.x) { }
else if( p1.x == p2.x )
{
// Repeat points // Repeat points
assert(false); assert( false );
} }
} }
q->edge_list.push_back(this); q->edge_list.push_back( this );
} }
}; };
// Triangle-based data structures are know to have better performance than quad-edge structures // Triangle-based data structures are know to have better performance than quad-edge structures
// See: J. Shewchuk, "Triangle: Engineering a 2D Quality Mesh Generator and Delaunay Triangulator" // See: J. Shewchuk, "Triangle: Engineering a 2D Quality Mesh Generator and Delaunay Triangulator"
// "Triangulations in CGAL" // "Triangulations in CGAL"
class Triangle { class Triangle
{
public: public:
/// Constructor /// Constructor
Triangle(Point& a, Point& b, Point& c); Triangle( Point& a, Point& b, Point& c );
/// Flags to determine if an edge is a Constrained edge /// Flags to determine if an edge is a Constrained edge
bool constrained_edge[3]; bool constrained_edge[3];
/// Flags to determine if an edge is a Delauney edge /// Flags to determine if an edge is a Delauney edge
bool delaunay_edge[3]; bool delaunay_edge[3];
Point* GetPoint(const int& index); Point* GetPoint( const int& index );
Point* PointCW(Point& point); Point* PointCW( Point& point );
Point* PointCCW(Point& point); Point* PointCCW( Point& point );
Point* OppositePoint(Triangle& t, Point& p); Point* OppositePoint( Triangle& t, Point& p );
Triangle* GetNeighbor(const int& index); Triangle* GetNeighbor( const int& index );
void MarkNeighbor(Point* p1, Point* p2, Triangle* t); void MarkNeighbor( Point* p1, Point* p2, Triangle* t );
void MarkNeighbor(Triangle& t); void MarkNeighbor( Triangle& t );
void MarkConstrainedEdge(const int index); void MarkConstrainedEdge( const int index );
void MarkConstrainedEdge(Edge& edge); void MarkConstrainedEdge( Edge& edge );
void MarkConstrainedEdge(Point* p, Point* q); void MarkConstrainedEdge( Point* p, Point* q );
int Index(const Point* p); int Index( const Point* p );
int EdgeIndex(const Point* p1, const Point* p2); int EdgeIndex( const Point* p1, const Point* p2 );
Triangle* NeighborCW(Point& point); Triangle* NeighborCW( Point& point );
Triangle* NeighborCCW(Point& point); Triangle* NeighborCCW( Point& point );
bool GetConstrainedEdgeCCW(Point& p); bool GetConstrainedEdgeCCW( Point& p );
bool GetConstrainedEdgeCW(Point& p); bool GetConstrainedEdgeCW( Point& p );
void SetConstrainedEdgeCCW(Point& p, bool ce); void SetConstrainedEdgeCCW( Point& p, bool ce );
void SetConstrainedEdgeCW(Point& p, bool ce); void SetConstrainedEdgeCW( Point& p, bool ce );
bool GetDelunayEdgeCCW(Point& p); bool GetDelunayEdgeCCW( Point& p );
bool GetDelunayEdgeCW(Point& p); bool GetDelunayEdgeCW( Point& p );
void SetDelunayEdgeCCW(Point& p, bool e); void SetDelunayEdgeCCW( Point& p, bool e );
void SetDelunayEdgeCW(Point& p, bool e); void SetDelunayEdgeCW( Point& p, bool e );
bool Contains(Point* p); bool Contains( Point* p );
bool Contains(const Edge& e); bool Contains( const Edge& e );
bool Contains(Point* p, Point* q); bool Contains( Point* p, Point* q );
void Legalize(Point& point); void Legalize( Point& point );
void Legalize(Point& opoint, Point& npoint); void Legalize( Point& opoint, Point& npoint );
/** /**
* Clears all references to all other triangles and points * Clears all references to all other triangles and points
*/ */
void Clear(); void Clear();
void ClearNeighbor(Triangle *triangle ); void ClearNeighbor( Triangle* triangle );
void ClearNeighbors(); void ClearNeighbors();
void ClearDelunayEdges(); void ClearDelunayEdges();
inline bool IsInterior(); inline bool IsInterior();
inline void IsInterior(bool b); inline void IsInterior( bool b );
Triangle& NeighborAcross(Point& opoint); Triangle& NeighborAcross( Point& opoint );
void DebugPrint(); void DebugPrint();
private: private:
/// Triangle points /// Triangle points
Point* points_[3]; Point* points_[3];
/// Neighbor list /// Neighbor list
Triangle* neighbors_[3]; Triangle* neighbors_[3];
/// Has this triangle been marked as an interior triangle? /// Has this triangle been marked as an interior triangle?
bool interior_; bool interior_;
}; };
inline bool cmp(const Point* a, const Point* b) inline bool cmp( const Point* a, const Point* b )
{ {
if (a->y < b->y) { if( a->y < b->y )
{
return true; return true;
} else if (a->y == b->y) { }
else if( a->y == b->y )
{
// Make sure q is point with greater x value // Make sure q is point with greater x value
if (a->x < b->x) { if( a->x < b->x )
{
return true; return true;
} }
} }
return false; return false;
} }
/// Add two points_ component-wise. /// Add two points_ component-wise.
inline Point operator +(const Point& a, const Point& b) inline Point operator +( const Point& a, const Point& b )
{ {
return Point(a.x + b.x, a.y + b.y); return Point( a.x + b.x, a.y + b.y );
} }
/// Subtract two points_ component-wise. /// Subtract two points_ component-wise.
inline Point operator -(const Point& a, const Point& b) inline Point operator -( const Point& a, const Point& b )
{ {
return Point(a.x - b.x, a.y - b.y); return Point( a.x - b.x, a.y - b.y );
} }
/// Multiply point by scalar /// Multiply point by scalar
inline Point operator *(double s, const Point& a) inline Point operator *( double s, const Point& a )
{ {
return Point(s * a.x, s * a.y); return Point( s * a.x, s * a.y );
} }
inline bool operator ==(const Point& a, const Point& b)
inline bool operator ==( const Point& a, const Point& b )
{ {
return a.x == b.x && a.y == b.y; return a.x == b.x && a.y == b.y;
} }
inline bool operator !=(const Point& a, const Point& b)
inline bool operator !=( const Point& a, const Point& b )
{ {
return !(a.x == b.x) && !(a.y == b.y); return !(a.x == b.x) && !(a.y == b.y);
} }
/// Peform the dot product on two vectors. /// Peform the dot product on two vectors.
inline double Dot(const Point& a, const Point& b) inline double Dot( const Point& a, const Point& b )
{ {
return a.x * b.x + a.y * b.y; return a.x * b.x + a.y * b.y;
} }
/// Perform the cross product on two vectors. In 2D this produces a scalar. /// Perform the cross product on two vectors. In 2D this produces a scalar.
inline double Cross(const Point& a, const Point& b) inline double Cross( const Point& a, const Point& b )
{ {
return a.x * b.y - a.y * b.x; return a.x * b.y - a.y * b.x;
} }
/// Perform the cross product on a point and a scalar. In 2D this produces /// Perform the cross product on a point and a scalar. In 2D this produces
/// a point. /// a point.
inline Point Cross(const Point& a, double s) inline Point Cross( const Point& a, double s )
{ {
return Point(s * a.y, -s * a.x); return Point( s * a.y, -s * a.x );
} }
/// Perform the cross product on a scalar and a point. In 2D this produces /// Perform the cross product on a scalar and a point. In 2D this produces
/// a point. /// a point.
inline Point Cross(const double s, const Point& a) inline Point Cross( const double s, const Point& a )
{ {
return Point(-s * a.y, s * a.x); return Point( -s * a.y, s * a.x );
} }
inline Point* Triangle::GetPoint(const int& index)
inline Point* Triangle::GetPoint( const int& index )
{ {
return points_[index]; return points_[index];
} }
inline Triangle* Triangle::GetNeighbor(const int& index)
inline Triangle* Triangle::GetNeighbor( const int& index )
{ {
return neighbors_[index]; return neighbors_[index];
} }
inline bool Triangle::Contains(Point* p)
inline bool Triangle::Contains( Point* p )
{ {
return p == points_[0] || p == points_[1] || p == points_[2]; return p == points_[0] || p == points_[1] || p == points_[2];
} }
inline bool Triangle::Contains(const Edge& e)
inline bool Triangle::Contains( const Edge& e )
{ {
return Contains(e.p) && Contains(e.q); return Contains( e.p ) && Contains( e.q );
} }
inline bool Triangle::Contains(Point* p, Point* q)
inline bool Triangle::Contains( Point* p, Point* q )
{ {
return Contains(p) && Contains(q); return Contains( p ) && Contains( q );
} }
inline bool Triangle::IsInterior() inline bool Triangle::IsInterior()
{ {
return interior_; return interior_;
} }
inline void Triangle::IsInterior(bool b)
inline void Triangle::IsInterior( bool b )
{ {
interior_ = b; interior_ = b;
} }
} }
#endif #endif
...@@ -39,12 +39,13 @@ ...@@ -39,12 +39,13 @@
#include <math.h> #include <math.h>
namespace p2t { namespace p2t {
const double PI_3div4 = 3 * M_PI / 4; const double PI_3div4 = 3 * M_PI / 4;
const double PI_div2 = 1.57079632679489661923; const double PI_div2 = 1.57079632679489661923;
const double EPSILON = 1e-12; const double EPSILON = 1e-12;
enum Orientation { CW, CCW, COLLINEAR }; enum Orientation {
CW, CCW, COLLINEAR
};
/** /**
* Forumla to calculate signed area<br> * Forumla to calculate signed area<br>
...@@ -56,68 +57,77 @@ enum Orientation { CW, CCW, COLLINEAR }; ...@@ -56,68 +57,77 @@ enum Orientation { CW, CCW, COLLINEAR };
* = (x1-x3)*(y2-y3) - (y1-y3)*(x2-x3) * = (x1-x3)*(y2-y3) - (y1-y3)*(x2-x3)
* </pre> * </pre>
*/ */
Orientation Orient2d(Point& pa, Point& pb, Point& pc) Orientation Orient2d( Point& pa, Point& pb, Point& pc )
{ {
double detleft = (pa.x - pc.x) * (pb.y - pc.y); double detleft = (pa.x - pc.x) * (pb.y - pc.y);
double detright = (pa.y - pc.y) * (pb.x - pc.x); double detright = (pa.y - pc.y) * (pb.x - pc.x);
double val = detleft - detright; double val = detleft - detright;
if (val > -EPSILON && val < EPSILON) {
if( val > -EPSILON && val < EPSILON )
{
return COLLINEAR; return COLLINEAR;
} else if (val > 0) { }
else if( val > 0 )
{
return CCW; return CCW;
} }
return CW; return CW;
} }
/*
bool InScanArea(Point& pa, Point& pb, Point& pc, Point& pd)
{
double pdx = pd.x;
double pdy = pd.y;
double adx = pa.x - pdx;
double ady = pa.y - pdy;
double bdx = pb.x - pdx;
double bdy = pb.y - pdy;
double adxbdy = adx * bdy;
double bdxady = bdx * ady;
double oabd = adxbdy - bdxady;
if (oabd <= EPSILON) {
return false;
}
double cdx = pc.x - pdx; /*
double cdy = pc.y - pdy; * bool InScanArea(Point& pa, Point& pb, Point& pc, Point& pd)
* {
* double pdx = pd.x;
* double pdy = pd.y;
* double adx = pa.x - pdx;
* double ady = pa.y - pdy;
* double bdx = pb.x - pdx;
* double bdy = pb.y - pdy;
*
* double adxbdy = adx * bdy;
* double bdxady = bdx * ady;
* double oabd = adxbdy - bdxady;
*
* if (oabd <= EPSILON) {
* return false;
* }
*
* double cdx = pc.x - pdx;
* double cdy = pc.y - pdy;
*
* double cdxady = cdx * ady;
* double adxcdy = adx * cdy;
* double ocad = cdxady - adxcdy;
*
* if (ocad <= EPSILON) {
* return false;
* }
*
* return true;
* }
*
*/
double cdxady = cdx * ady; bool InScanArea( Point& pa, Point& pb, Point& pc, Point& pd )
double adxcdy = adx * cdy; {
double ocad = cdxady - adxcdy; double oadb = (pa.x - pb.x) * (pd.y - pb.y) - (pd.x - pb.x) * (pa.y - pb.y);
if (ocad <= EPSILON) { if( oadb >= -EPSILON )
{
return false; return false;
} }
return true; double oadc = (pa.x - pc.x) * (pd.y - pc.y) - (pd.x - pc.x) * (pa.y - pc.y);
}
*/ if( oadc <= EPSILON )
{
bool InScanArea(Point& pa, Point& pb, Point& pc, Point& pd)
{
double oadb = (pa.x - pb.x)*(pd.y - pb.y) - (pd.x - pb.x)*(pa.y - pb.y);
if (oadb >= -EPSILON) {
return false; return false;
} }
double oadc = (pa.x - pc.x)*(pd.y - pc.y) - (pd.x - pc.x)*(pa.y - pc.y);
if (oadc <= EPSILON) {
return false;
}
return true; return true;
} }
} }
#endif #endif
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