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 @@
#ifndef DRW_BASE_H
#define DRW_BASE_H
#define DRW_VERSION "0.5.10"
#define DRW_VERSION "0.5.11"
#include <string>
#include <cmath>
......
......@@ -27,7 +27,7 @@ class dxfRW
public:
dxfRW( const char* name );
~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
* components being added.
......@@ -71,7 +71,7 @@ public:
void setEllipseParts( int parts ) { elParts = parts; } /*!< set parts munber when convert ellipse to polyline */
private:
// / used by read() to parse the content of the file
/// used by read() to parse the content of the file
bool processDxf();
bool processHeader();
bool processTables();
......
......@@ -88,8 +88,8 @@ CPolyLine::~CPolyLine()
#include "clipper.hpp"
int CPolyLine::NormalizeAreaOutlines( std::vector<CPolyLine*>* aNewPolygonList )
{
ClipperLib::Polygon raw_polygon;
ClipperLib::Polygons normalized_polygons;
ClipperLib::Path raw_polygon;
ClipperLib::Paths normalized_polygons;
unsigned corners_count = m_CornersList.GetCornersCount();
......@@ -115,7 +115,7 @@ int CPolyLine::NormalizeAreaOutlines( std::vector<CPolyLine*>* aNewPolygonList )
// enter main outline
for( unsigned ii = 0; ii < normalized_polygons.size(); ii++ )
{
ClipperLib::Polygon& polygon = normalized_polygons[ii];
ClipperLib::Path& polygon = normalized_polygons[ii];
cornerslist.clear();
for( unsigned jj = 0; jj < polygon.size(); jj++ )
cornerslist.push_back( KI_POLY_POINT( KiROUND( polygon[jj].X ),
......@@ -142,7 +142,7 @@ int CPolyLine::NormalizeAreaOutlines( std::vector<CPolyLine*>* aNewPolygonList )
ClipperLib::SimplifyPolygon( raw_polygon, normalized_polygons );
for( unsigned ii = 0; ii < normalized_polygons.size(); ii++ )
{
ClipperLib::Polygon& polygon = normalized_polygons[ii];
ClipperLib::Path& polygon = normalized_polygons[ii];
cornerslist.clear();
for( unsigned jj = 0; jj < polygon.size(); jj++ )
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 @@
#include <cmath>
namespace p2t {
struct Edge;
struct Point {
struct Point
{
double x, y;
/// Default constructor does nothing (for performance).
......@@ -57,7 +56,7 @@ struct Point {
std::vector<Edge*> edge_list;
/// 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.
void set_zero()
......@@ -67,7 +66,7 @@ struct Point {
}
/// Set this point to some specified coordinates.
void set(double x_, double y_)
void set( double x_, double y_ )
{
x = x_;
y = y_;
......@@ -77,26 +76,27 @@ struct Point {
Point operator -() const
{
Point v;
v.set(-x, -y);
v.set( -x, -y );
return v;
}
/// Add a point to this point.
void operator +=(const Point& v)
void operator +=( const Point& v )
{
x += v.x;
y += v.y;
}
/// Subtract a point from this point.
void operator -=(const Point& v)
void operator -=( const Point& v )
{
x -= v.x;
y -= v.y;
}
/// Multiply this point by a scalar.
void operator *=(double a)
void operator *=( double a )
{
x *= a;
y *= a;
......@@ -105,221 +105,247 @@ struct Point {
/// Get the length of this point (the norm).
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.
double Normalize()
{
double len = Length();
x /= len;
y /= len;
return len;
}
};
// Represents a simple polygon's edge
struct Edge {
Point* p, *q;
struct Edge
{
Point* p, * q;
/// 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;
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;
p = &p2;
} else if (p1.x == p2.x) {
}
else if( p1.x == p2.x )
{
// 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
// See: J. Shewchuk, "Triangle: Engineering a 2D Quality Mesh Generator and Delaunay Triangulator"
// "Triangulations in CGAL"
class Triangle {
class Triangle
{
public:
/// 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
bool constrained_edge[3];
bool constrained_edge[3];
/// Flags to determine if an edge is a Delauney edge
bool delaunay_edge[3];
Point* GetPoint(const int& index);
Point* PointCW(Point& point);
Point* PointCCW(Point& point);
Point* OppositePoint(Triangle& t, Point& p);
Triangle* GetNeighbor(const int& index);
void MarkNeighbor(Point* p1, Point* p2, Triangle* t);
void MarkNeighbor(Triangle& t);
void MarkConstrainedEdge(const int index);
void MarkConstrainedEdge(Edge& edge);
void MarkConstrainedEdge(Point* p, Point* q);
int Index(const Point* p);
int EdgeIndex(const Point* p1, const Point* p2);
Triangle* NeighborCW(Point& point);
Triangle* NeighborCCW(Point& point);
bool GetConstrainedEdgeCCW(Point& p);
bool GetConstrainedEdgeCW(Point& p);
void SetConstrainedEdgeCCW(Point& p, bool ce);
void SetConstrainedEdgeCW(Point& p, bool ce);
bool GetDelunayEdgeCCW(Point& p);
bool GetDelunayEdgeCW(Point& p);
void SetDelunayEdgeCCW(Point& p, bool e);
void SetDelunayEdgeCW(Point& p, bool e);
bool Contains(Point* p);
bool Contains(const Edge& e);
bool Contains(Point* p, Point* q);
void Legalize(Point& point);
void Legalize(Point& opoint, Point& npoint);
bool delaunay_edge[3];
Point* GetPoint( const int& index );
Point* PointCW( Point& point );
Point* PointCCW( Point& point );
Point* OppositePoint( Triangle& t, Point& p );
Triangle* GetNeighbor( const int& index );
void MarkNeighbor( Point* p1, Point* p2, Triangle* t );
void MarkNeighbor( Triangle& t );
void MarkConstrainedEdge( const int index );
void MarkConstrainedEdge( Edge& edge );
void MarkConstrainedEdge( Point* p, Point* q );
int Index( const Point* p );
int EdgeIndex( const Point* p1, const Point* p2 );
Triangle* NeighborCW( Point& point );
Triangle* NeighborCCW( Point& point );
bool GetConstrainedEdgeCCW( Point& p );
bool GetConstrainedEdgeCW( Point& p );
void SetConstrainedEdgeCCW( Point& p, bool ce );
void SetConstrainedEdgeCW( Point& p, bool ce );
bool GetDelunayEdgeCCW( Point& p );
bool GetDelunayEdgeCW( Point& p );
void SetDelunayEdgeCCW( Point& p, bool e );
void SetDelunayEdgeCW( Point& p, bool e );
bool Contains( Point* p );
bool Contains( const Edge& e );
bool Contains( Point* p, Point* q );
void Legalize( Point& point );
void Legalize( Point& opoint, Point& npoint );
/**
* Clears all references to all other triangles and points
*/
void Clear();
void ClearNeighbor(Triangle *triangle );
void ClearNeighbors();
void ClearDelunayEdges();
void Clear();
void ClearNeighbor( Triangle* triangle );
void ClearNeighbors();
void ClearDelunayEdges();
inline bool IsInterior();
inline void IsInterior(bool b);
inline bool IsInterior();
inline void IsInterior( bool b );
Triangle& NeighborAcross(Point& opoint);
Triangle& NeighborAcross( Point& opoint );
void DebugPrint();
void DebugPrint();
private:
/// Triangle points
Point* points_[3];
Point* points_[3];
/// Neighbor list
Triangle* neighbors_[3];
Triangle* neighbors_[3];
/// 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;
} else if (a->y == b->y) {
}
else if( a->y == b->y )
{
// Make sure q is point with greater x value
if (a->x < b->x) {
if( a->x < b->x )
{
return true;
}
}
return false;
}
/// 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.
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
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;
}
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);
}
/// 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;
}
/// 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;
}
/// Perform the cross product on a point and a scalar. In 2D this produces
/// 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
/// 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];
}
inline Triangle* Triangle::GetNeighbor(const int& index)
inline Triangle* Triangle::GetNeighbor( const int& 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];
}
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()
{
return interior_;
}
inline void Triangle::IsInterior(bool b)
inline void Triangle::IsInterior( bool b )
{
interior_ = b;
}
}
#endif
......@@ -39,12 +39,13 @@
#include <math.h>
namespace p2t {
const double PI_3div4 = 3 * M_PI / 4;
const double PI_div2 = 1.57079632679489661923;
const double EPSILON = 1e-12;
enum Orientation { CW, CCW, COLLINEAR };
enum Orientation {
CW, CCW, COLLINEAR
};
/**
* Forumla to calculate signed area<br>
......@@ -56,68 +57,77 @@ enum Orientation { CW, CCW, COLLINEAR };
* = (x1-x3)*(y2-y3) - (y1-y3)*(x2-x3)
* </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 detright = (pa.y - pc.y) * (pb.x - pc.x);
double val = detleft - detright;
if (val > -EPSILON && val < EPSILON) {
if( val > -EPSILON && val < EPSILON )
{
return COLLINEAR;
} else if (val > 0) {
}
else if( val > 0 )
{
return CCW;
}
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;
double adxcdy = adx * cdy;
double ocad = cdxady - adxcdy;
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 (ocad <= EPSILON) {
if( oadb >= -EPSILON )
{
return false;
}
return true;
}
double oadc = (pa.x - pc.x) * (pd.y - pc.y) - (pd.x - pc.x) * (pa.y - pc.y);
*/
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) {
if( oadc <= EPSILON )
{
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;
}
}
#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