Commit 746dea5a authored by jean-pierre charras's avatar jean-pierre charras

Pcbnew: fix a serious bug in ZONE_CONTAINER::HitTestFilledArea( ) which could...

Pcbnew: fix a serious bug in ZONE_CONTAINER::HitTestFilledArea( ) which could break connectivity calculations relative to copper areas.
Fix also very minor issues relative to copper zones.
Update boost::polygon from Boost svn repository.
parent 3dbae0b8
......@@ -253,8 +253,13 @@ public:
typename polygon_with_holes_traits<polygon_with_holes_type>::hole_type>(*itrhb, HIGH, orient_, !is_hole_);
++itrhb;
} else {
itrhib = itrhie = iterator_geometry_to_set<polygon_90_concept,
typename polygon_with_holes_traits<polygon_with_holes_type>::hole_type>();
//in this case we have no holes so we just need the iterhib == itrhie, which
//is always true if they were default initialized in the initial case or
//both point to end of the previous hole processed
//no need to explicitly reset them, and it causes an stl debug assertion to use
//the default constructed iterator this way
//itrhib = itrhie = iterator_geometry_to_set<polygon_90_concept,
// typename polygon_with_holes_traits<polygon_with_holes_type>::hole_type>();
}
} else {
++itrhib;
......@@ -266,8 +271,9 @@ public:
typename polygon_with_holes_traits<polygon_with_holes_type>::hole_type>(*itrhb, HIGH, orient_, !is_hole_);
++itrhb;
} else {
itrhib = itrhie = iterator_geometry_to_set<polygon_90_concept,
typename polygon_with_holes_traits<polygon_with_holes_type>::hole_type>();
//this is the same case as above
//itrhib = itrhie = iterator_geometry_to_set<polygon_90_concept,
// typename polygon_with_holes_traits<polygon_with_holes_type>::hole_type>();
}
}
}
......
namespace boost { namespace polygon { namespace detail {
template <typename coordinate_type>
struct minkowski_offset {
typedef point_data<coordinate_type> point;
typedef polygon_set_data<coordinate_type> polygon_set;
typedef polygon_with_holes_data<coordinate_type> polygon;
typedef std::pair<point, point> edge;
static void convolve_two_segments(std::vector<point>& figure, const edge& a, const edge& b) {
figure.clear();
figure.push_back(point(a.first));
figure.push_back(point(a.first));
figure.push_back(point(a.second));
figure.push_back(point(a.second));
convolve(figure[0], b.second);
convolve(figure[1], b.first);
convolve(figure[2], b.first);
convolve(figure[3], b.second);
}
template <typename itrT1, typename itrT2>
static void convolve_two_point_sequences(polygon_set& result, itrT1 ab, itrT1 ae, itrT2 bb, itrT2 be) {
if(ab == ae || bb == be)
return;
point first_a = *ab;
point prev_a = *ab;
std::vector<point> vec;
polygon poly;
++ab;
for( ; ab != ae; ++ab) {
point first_b = *bb;
point prev_b = *bb;
itrT2 tmpb = bb;
++tmpb;
for( ; tmpb != be; ++tmpb) {
convolve_two_segments(vec, std::make_pair(prev_b, *tmpb), std::make_pair(prev_a, *ab));
set_points(poly, vec.begin(), vec.end());
result.insert(poly);
prev_b = *tmpb;
}
prev_a = *ab;
}
}
template <typename itrT>
static void convolve_point_sequence_with_polygons(polygon_set& result, itrT b, itrT e, const std::vector<polygon>& polygons) {
for(std::size_t i = 0; i < polygons.size(); ++i) {
convolve_two_point_sequences(result, b, e, begin_points(polygons[i]), end_points(polygons[i]));
for(typename polygon_with_holes_traits<polygon>::iterator_holes_type itrh = begin_holes(polygons[i]);
itrh != end_holes(polygons[i]); ++itrh) {
convolve_two_point_sequences(result, b, e, begin_points(*itrh), end_points(*itrh));
}
}
}
static void convolve_two_polygon_sets(polygon_set& result, const polygon_set& a, const polygon_set& b) {
result.clear();
std::vector<polygon> a_polygons;
std::vector<polygon> b_polygons;
a.get(a_polygons);
b.get(b_polygons);
for(std::size_t ai = 0; ai < a_polygons.size(); ++ai) {
convolve_point_sequence_with_polygons(result, begin_points(a_polygons[ai]),
end_points(a_polygons[ai]), b_polygons);
for(typename polygon_with_holes_traits<polygon>::iterator_holes_type itrh = begin_holes(a_polygons[ai]);
itrh != end_holes(a_polygons[ai]); ++itrh) {
convolve_point_sequence_with_polygons(result, begin_points(*itrh),
end_points(*itrh), b_polygons);
}
for(std::size_t bi = 0; bi < b_polygons.size(); ++bi) {
polygon tmp_poly = a_polygons[ai];
result.insert(convolve(tmp_poly, *(begin_points(b_polygons[bi]))));
tmp_poly = b_polygons[bi];
result.insert(convolve(tmp_poly, *(begin_points(a_polygons[ai]))));
}
}
}
};
}
template<typename T>
inline polygon_set_data<T>&
polygon_set_data<T>::resize(coordinate_type resizing, bool corner_fill_arc, unsigned int num_circle_segments) {
using namespace ::boost::polygon::operators;
if(!corner_fill_arc) {
if(resizing < 0)
return shrink(-resizing);
if(resizing > 0)
return bloat(resizing);
return *this;
}
if(resizing == 0) return *this;
if(empty()) return *this;
if(num_circle_segments < 3) num_circle_segments = 4;
rectangle_data<coordinate_type> rect;
extents(rect);
if(resizing < 0) {
::boost::polygon::bloat(rect, 10);
(*this) = rect - (*this); //invert
}
//make_arc(std::vector<point_data< T> >& return_points,
//point_data< double> start, point_data< double> end,
//point_data< double> center, double r, unsigned int num_circle_segments)
std::vector<point_data<coordinate_type> > circle;
point_data<double> center(0.0, 0.0), start(0.0, (double)resizing);
make_arc(circle, start, start, center, std::abs((double)resizing),
num_circle_segments);
polygon_data<coordinate_type> poly;
set_points(poly, circle.begin(), circle.end());
polygon_set_data<coordinate_type> offset_set;
offset_set += poly;
polygon_set_data<coordinate_type> result;
detail::minkowski_offset<coordinate_type>::convolve_two_polygon_sets
(result, *this, offset_set);
if(resizing < 0) {
result = result & rect;//eliminate overhang
result = result ^ rect;//invert
}
*this = result;
return *this;
}
}}
......@@ -478,7 +478,7 @@ namespace boost { namespace polygon{
ct counts[4];
};
typedef Vertex45CountT<signed char> Vertex45Count;
typedef Vertex45CountT<int> Vertex45Count;
// inline std::ostream& operator<< (std::ostream& o, const Vertex45Count& c) {
// o << c[0] << ", " << c[1] << ", ";
......
......@@ -455,6 +455,10 @@ namespace boost { namespace polygon{
//truncate downward if it went up due to negative number
if(x < x_unit) --x_unit;
if(y < y_unit) --y_unit;
if(is_horizontal(he1))
y_unit = he1.first.y();
if(is_horizontal(he2))
y_unit = he2.first.y();
//if(x != exp_x || y != exp_y)
// std::cout << exp_x << " " << exp_y << " " << x << " " << y << std::endl;
//Unit y1 = evalAtXforY(exp_x, he1.first, he1.second);
......@@ -464,11 +468,11 @@ namespace boost { namespace polygon{
if(!projected && !contains(rect1, result, true)) return false;
if(!projected && !contains(rect2, result, true)) return false;
if(projected) {
rectangle_data<long double> inf_rect((long double)(std::numeric_limits<Unit>::min)(),
(long double) (std::numeric_limits<Unit>::min)(),
rectangle_data<long double> inf_rect(-(long double)(std::numeric_limits<Unit>::max)(),
-(long double) (std::numeric_limits<Unit>::max)(),
(long double)(std::numeric_limits<Unit>::max)(),
(long double) (std::numeric_limits<Unit>::max)() );
if(contains(inf_rect, intersection, true)) {
if(contains(inf_rect, point_data<long double>(x, y), true)) {
intersection = result;
return true;
} else
......@@ -477,6 +481,7 @@ namespace boost { namespace polygon{
intersection = result;
return true;
}
inline bool compute_intersection(Point& intersection, const half_edge& he1, const half_edge& he2,
bool projected = false, bool round_closest = false) {
if(!projected && !intersects(he1, he2))
......@@ -491,6 +496,13 @@ namespace boost { namespace polygon{
} else {
return lazy_success;
}
return compute_exact_intersection(intersection, he1, he2, projected, round_closest);
}
inline bool compute_exact_intersection(Point& intersection, const half_edge& he1, const half_edge& he2,
bool projected = false, bool round_closest = false) {
if(!projected && !intersects(he1, he2))
return false;
typedef rectangle_data<Unit> Rectangle;
Rectangle rect1, rect2;
set_points(rect1, he1.first, he1.second);
......@@ -542,6 +554,7 @@ namespace boost { namespace polygon{
y_den = (dx1 * dy2 - dx2 * dy1);
x = x_num / x_den;
y = y_num / y_den;
//std::cout << x << " " << y << std::endl;
//std::cout << "cross1 " << dy1 << " " << dx2 << " " << dy1 * dx2 << std::endl;
//std::cout << "cross2 " << dy2 << " " << dx1 << " " << dy2 * dx1 << std::endl;
//Unit exp_x = compute_x_intercept<at>(x11, x21, y11, y21, dy1, dy2, dx1, dx2);
......@@ -555,6 +568,10 @@ namespace boost { namespace polygon{
//truncate downward if it went up due to negative number
if(x < (high_precision)x_unit) --x_unit;
if(y < (high_precision)y_unit) --y_unit;
if(is_horizontal(he1))
y_unit = he1.first.y();
if(is_horizontal(he2))
y_unit = he2.first.y();
//if(x != exp_x || y != exp_y)
// std::cout << exp_x << " " << exp_y << " " << x << " " << y << std::endl;
//Unit y1 = evalAtXforY(exp_x, he1.first, he1.second);
......@@ -564,14 +581,9 @@ namespace boost { namespace polygon{
if(!contains(rect1, result, true)) return false;
if(!contains(rect2, result, true)) return false;
if(projected) {
rectangle_data<long double> inf_rect((long double)(std::numeric_limits<Unit>::min)(),
(long double) (std::numeric_limits<Unit>::min)(),
(long double)(std::numeric_limits<Unit>::max)(),
(long double) (std::numeric_limits<Unit>::max)() );
if(contains(inf_rect, intersection, true)) {
intersection = result;
return true;
} else
high_precision b1 = (high_precision) (std::numeric_limits<Unit>::min)();
high_precision b2 = (high_precision) (std::numeric_limits<Unit>::max)();
if(x > b2 || y > b2 || x < b1 || y < b1)
return false;
}
intersection = result;
......@@ -641,6 +653,10 @@ namespace boost { namespace polygon{
//truncate downward if it went up due to negative number
if(x < (high_precision)x_unit) --x_unit;
if(y < (high_precision)y_unit) --y_unit;
if(is_horizontal(he1))
y_unit = he1.first.y();
if(is_horizontal(he2))
y_unit = he2.first.y();
//if(x != exp_x || y != exp_y)
// std::cout << exp_x << " " << exp_y << " " << x << " " << y << std::endl;
//Unit y1 = evalAtXforY(exp_x, he1.first, he1.second);
......
......@@ -125,5 +125,5 @@ namespace boost { namespace polygon {
}
}
//==
#endif
......@@ -198,6 +198,16 @@ namespace boost { namespace polygon{
typedef double coordinate_distance;
};
template <>
struct coordinate_traits<long double> {
typedef long double coordinate_type;
typedef long double area_type;
typedef long double manhattan_area_type;
typedef long double unsigned_area_type;
typedef long double coordinate_difference;
typedef long double coordinate_distance;
};
template <typename T>
struct scaling_policy {
template <typename T2>
......@@ -222,6 +232,8 @@ namespace boost { namespace polygon{
struct geometry_concept<float> { typedef coordinate_concept type; };
template <>
struct geometry_concept<double> { typedef coordinate_concept type; };
template <>
struct geometry_concept<long double> { typedef coordinate_concept type; };
#ifndef BOOST_POLYGON_NO_DEPS
struct gtl_no : mpl::bool_<false> {};
......
......@@ -244,37 +244,47 @@ namespace boost { namespace polygon{
// get the scanline orientation of the polygon set
inline orientation_2d orient() const { return orient_; }
polygon_90_set_data<coordinate_type>& operator-=(const polygon_90_set_data& that) {
sort();
that.sort();
value_type data;
std::swap(data, data_);
applyBooleanBinaryOp(data.begin(), data.end(),
that.begin(), that.end(), boolean_op::BinaryCount<boolean_op::BinaryNot>());
return *this;
}
polygon_90_set_data<coordinate_type>& operator^=(const polygon_90_set_data& that) {
sort();
that.sort();
value_type data;
std::swap(data, data_);
applyBooleanBinaryOp(data.begin(), data.end(),
that.begin(), that.end(), boolean_op::BinaryCount<boolean_op::BinaryXor>());
return *this;
}
polygon_90_set_data<coordinate_type>& operator&=(const polygon_90_set_data& that) {
sort();
that.sort();
value_type data;
std::swap(data, data_);
applyBooleanBinaryOp(data.begin(), data.end(),
that.begin(), that.end(), boolean_op::BinaryCount<boolean_op::BinaryAnd>());
return *this;
}
polygon_90_set_data<coordinate_type>& operator|=(const polygon_90_set_data& that) {
insert(that);
return *this;
}
// Start BM
// The problem: If we have two polygon sets with two different scanline orientations:
// I tried changing the orientation of one to coincide with other (If not, resulting boolean operation
// produces spurious results).
// First I tried copying polygon data from one of the sets into another set with corrected orientation
// using one of the copy constructor that takes in orientation (see somewhere above in this file) --> copy constructor throws error
// Then I tried another approach:(see below). This approach also fails to produce the desired results when test case is run.
// Here is the part that beats me: If I comment out the whole section, I can do all the operations (^=, -=, &= )these commented out
// operations perform. So then why do we need them?. Hence, I commented out this whole section.
// End BM
// polygon_90_set_data<coordinate_type>& operator-=(const polygon_90_set_data& that) {
// sort();
// that.sort();
// value_type data;
// std::swap(data, data_);
// applyBooleanBinaryOp(data.begin(), data.end(),
// that.begin(), that.end(), boolean_op::BinaryCount<boolean_op::BinaryNot>());
// return *this;
// }
// polygon_90_set_data<coordinate_type>& operator^=(const polygon_90_set_data& that) {
// sort();
// that.sort();
// value_type data;
// std::swap(data, data_);
// applyBooleanBinaryOp(data.begin(), data.end(),
// that.begin(), that.end(), boolean_op::BinaryCount<boolean_op::BinaryXor>());
// return *this;
// }
// polygon_90_set_data<coordinate_type>& operator&=(const polygon_90_set_data& that) {
// sort();
// that.sort();
// value_type data;
// std::swap(data, data_);
// applyBooleanBinaryOp(data.begin(), data.end(),
// that.begin(), that.end(), boolean_op::BinaryCount<boolean_op::BinaryAnd>());
// return *this;
// }
// polygon_90_set_data<coordinate_type>& operator|=(const polygon_90_set_data& that) {
// insert(that);
// return *this;
// }
void clean() const {
sort();
......@@ -439,7 +449,7 @@ namespace boost { namespace polygon{
static bool remove_colinear_pts(std::vector<point_data<coordinate_type> >& poly) {
bool found_colinear = true;
while(found_colinear) {
while(found_colinear && poly.size() >= 4) {
found_colinear = false;
typename std::vector<point_data<coordinate_type> >::iterator itr = poly.begin();
itr += poly.size() - 1; //get last element position
......@@ -504,9 +514,9 @@ namespace boost { namespace polygon{
//polygon_45_data<coordinate_type> testpoly(*itrh);
if(resize_poly_down((*itrh).coords_, west_bloating, east_bloating, south_bloating, north_bloating)) {
iterator_geometry_to_set<polygon_90_concept, view_of<polygon_90_concept, polygon_45_data<coordinate_type> > >
begin_input(view_as<polygon_90_concept>(*itrh), LOW, orient_, true, true),
end_input(view_as<polygon_90_concept>(*itrh), HIGH, orient_, true, true);
insert(begin_input, end_input, orient_);
begin_input2(view_as<polygon_90_concept>(*itrh), LOW, orient_, true, true),
end_input2(view_as<polygon_90_concept>(*itrh), HIGH, orient_, true, true);
insert(begin_input2, end_input2, orient_);
//polygon_90_set_data<coordinate_type> pstesthole;
//pstesthole.insert(rect);
//iterator_geometry_to_set<polygon_90_concept, view_of<polygon_90_concept, polygon_45_data<coordinate_type> > >
......@@ -569,9 +579,9 @@ namespace boost { namespace polygon{
//polygon_45_data<coordinate_type> testpoly(*itrh);
resize_poly_up((*itrh).coords_, -west_shrinking, -east_shrinking, -south_shrinking, -north_shrinking);
iterator_geometry_to_set<polygon_90_concept, view_of<polygon_90_concept, polygon_45_data<coordinate_type> > >
begin_input(view_as<polygon_90_concept>(*itrh), LOW, orient_, true, true),
end_input(view_as<polygon_90_concept>(*itrh), HIGH, orient_, true, true);
insert(begin_input, end_input, orient_);
begin_input2(view_as<polygon_90_concept>(*itrh), LOW, orient_, true, true),
end_input2(view_as<polygon_90_concept>(*itrh), HIGH, orient_, true, true);
insert(begin_input2, end_input2, orient_);
//polygon_90_set_data<coordinate_type> pstesthole;
//pstesthole.insert(rect);
//iterator_geometry_to_set<polygon_90_concept, view_of<polygon_90_concept, polygon_45_data<coordinate_type> > >
......@@ -638,8 +648,7 @@ namespace boost { namespace polygon{
return shrink(0, shrinking, 0, 0);
if(dir == SOUTH)
return shrink(0, 0, shrinking, 0);
if(dir == NORTH)
return shrink(0, 0, 0, shrinking);
return shrink(0, 0, 0, shrinking);
}
polygon_90_set_data&
......@@ -650,8 +659,7 @@ namespace boost { namespace polygon{
return bloat(0, shrinking, 0, 0);
if(dir == SOUTH)
return bloat(0, 0, shrinking, 0);
if(dir == NORTH)
return bloat(0, 0, 0, shrinking);
return bloat(0, 0, 0, shrinking);
}
polygon_90_set_data&
......
This diff is collapsed.
......@@ -29,6 +29,7 @@ ZONE_CONTAINER::ZONE_CONTAINER( BOARD* parent ) :
m_NetCode = -1; // Net number for fast comparisons
m_CornerSelection = -1;
m_IsFilled = false; // fill status : true when the zone is filled
m_FillMode = 0; // How to fill areas: 0 = use filled polygons, != 0 fill with segments
utility = 0; // flags used in polygon calculations
utility2 = 0; // flags used in polygon calculations
m_Poly = new CPolyLine(); // Outlines
......@@ -903,6 +904,8 @@ bool ZONE_CONTAINER::HitTestFilledArea( const wxPoint& aRefPos )
inside = true;
break;
}
// Prepare test of next area which starts after the current indexend (if exists)
indexstart = indexend+1;
}
}
return inside;
......
......@@ -41,7 +41,7 @@ public:
int m_CornerSelection; // For corner moving, corner index to drag, or -1 if no selection
int m_ZoneClearance; // clearance value
int m_ZoneMinThickness; // Min thickness value in filled areas
int m_FillMode; // How to fillingareas: 0 = use polygonal areas , != 0 fill with segments
int m_FillMode; // How to fill areas: 0 = use filled polygons, != 0 fill with segments
int m_ArcToSegmentsCount; // number of segments to convert a circle to a polygon
// (uses ARC_APPROX_SEGMENTS_COUNT_LOW_DEF or ARC_APPROX_SEGMENTS_COUNT_HIGHT_DEF)
int m_PadOption; //
......
......@@ -24,7 +24,7 @@
ZONE_SETTING::ZONE_SETTING( void )
{
m_FillMode = 1; // Mode for filling zone : 1 use segments, 0 use polygons
m_FillMode = 0; // Mode for filling zone : 1 use segments, 0 use polygons
m_ZoneClearance = 200; // Clearance value
m_ZoneMinThickness = 100; // Min thickness value in filled areas
m_NetcodeSelection = 0; // Net code selection for the current zone
......
......@@ -19,9 +19,10 @@
#include "dialog_copper_zones.h"
wxString dialog_copper_zone::m_netNameShowFilter( wxT( "*" ) ); /* the filter to show nets (default * "*").
* static to keep this pattern for an entire pcbnew session
*/
/* the filter to show nets (default * "*").
* static to keep this pattern for an entire pcbnew session
*/
wxString dialog_copper_zone::m_netNameShowFilter( wxT( "*" ) );
/************************************************************************************************/
dialog_copper_zone::dialog_copper_zone( WinEDA_PcbFrame* parent, ZONE_SETTING* zone_setting ) :
......@@ -31,8 +32,10 @@ dialog_copper_zone::dialog_copper_zone( WinEDA_PcbFrame* parent, ZONE_SETTING* z
m_Parent = parent;
m_Config = wxGetApp().m_EDA_Config;
m_Zone_Setting = zone_setting;
m_NetSorting = 1; // 0 = alphabetic sort, 1 = pad count sort, and filtering net names
m_OnExitCode = ZONE_ABORT;
m_NetSortingByPadCount = true; /* false = alphabetic sort.
* true = pad count sort.
*/
m_OnExitCode = ZONE_ABORT;
SetReturnCode( ZONE_ABORT ); // Will be changed on buttons click
......@@ -156,7 +159,7 @@ void dialog_copper_zone::initDialog()
else
m_NetDisplayOption->SetSelection( 1 );
m_ShowNetNameFilter->SetValue(m_netNameShowFilter);
m_ShowNetNameFilter->SetValue( m_netNameShowFilter );
initListNetsParams();
// Build list of nets:
......@@ -392,7 +395,7 @@ void dialog_copper_zone::OnPadsInZoneClick( wxCommandEvent& event )
}
/** init m_NetSorting and m_NetFiltering values
/** init m_NetSortingByPadCount and m_NetFiltering values
* according to m_NetDisplayOption selection
*/
void dialog_copper_zone::initListNetsParams()
......@@ -400,22 +403,22 @@ void dialog_copper_zone::initListNetsParams()
switch( m_NetDisplayOption->GetSelection() )
{
case 0:
m_NetSorting = true;
m_NetSortingByPadCount = false;
m_NetFiltering = false;
break;
case 1:
m_NetSorting = false;
m_NetSortingByPadCount = true;
m_NetFiltering = false;
break;
case 2:
m_NetSorting = true;
m_NetSortingByPadCount = false;
m_NetFiltering = true;
break;
case 3:
m_NetSorting = false;
m_NetSortingByPadCount = true;
m_NetFiltering = true;
break;
}
......@@ -429,6 +432,7 @@ void dialog_copper_zone::initListNetsParams()
void dialog_copper_zone::OnRunFiltersButtonClick( wxCommandEvent& event )
{
m_netNameShowFilter = m_ShowNetNameFilter->GetValue();
// Ensure filtered option for nets:
if( m_NetDisplayOption->GetSelection() == 0 )
m_NetDisplayOption->SetSelection( 2 );
......@@ -443,8 +447,7 @@ void dialog_copper_zone::buildAvailableListOfNets()
{
wxArrayString listNetName;
m_Parent->GetBoard()->ReturnSortedNetnamesList(
listNetName, m_NetSorting == 0 ? false : true );
m_Parent->GetBoard()->ReturnSortedNetnamesList( listNetName, m_NetSortingByPadCount );
if( m_NetFiltering )
{
......
......@@ -18,7 +18,9 @@ private:
*/
ZONE_SETTING* m_Zone_Setting;
long m_NetSorting;
bool m_NetSortingByPadCount; /* false = alphabetic sort.
* true = pad count sort.
*/
long m_NetFiltering;
int m_LayerId[LAYER_COUNT]; // Handle the real layer number from layer name position in m_LayerSelectionCtrl
static wxString m_netNameShowFilter; /* the filter to show nets (default * "*").
......
......@@ -486,7 +486,6 @@ void ZONE_CONTAINER::AddClearanceAreasPolygonsToPolysList( BOARD* aPcb )
booleng = new Bool_Engine();
ArmBoolEng( booleng, true );
cornerBufferPolysToSubstract.clear();
// Test thermal stubs connections and add polygons to remove unconnected stubs.
for( MODULE* module = aPcb->m_Modules; module; module = module->Next() )
{
......@@ -535,62 +534,60 @@ void ZONE_CONTAINER::AddClearanceAreasPolygonsToPolysList( BOARD* aPcb )
// translate point
ptTest[i] += pad->ReturnShapePos();
bool inside = HitTestFilledArea( ptTest[i] );
if( HitTestFilledArea( ptTest[i] ) )
continue;
// polygon buffer
std::vector<wxPoint> corners_buffer;
// polygons are rectangles with width of copper bridge value
// contour line width has to be taken into calculation to avoid "thermal stub bleed"
const int iDTRC =
( m_ThermalReliefCopperBridgeValue - m_ZoneMinThickness ) / 2;
switch( i )
{
case 0:
corners_buffer.push_back( wxPoint( -iDTRC, dy ) );
corners_buffer.push_back( wxPoint( +iDTRC, dy ) );
corners_buffer.push_back( wxPoint( +iDTRC, iDTRC ) );
corners_buffer.push_back( wxPoint( -iDTRC, iDTRC ) );
break;
case 1:
corners_buffer.push_back( wxPoint( -iDTRC, -dy ) );
corners_buffer.push_back( wxPoint( +iDTRC, -dy ) );
corners_buffer.push_back( wxPoint( +iDTRC, -iDTRC ) );
corners_buffer.push_back( wxPoint( -iDTRC, -iDTRC ) );
break;
case 2:
corners_buffer.push_back( wxPoint( dx, -iDTRC ) );
corners_buffer.push_back( wxPoint( dx, iDTRC ) );
corners_buffer.push_back( wxPoint( +iDTRC, iDTRC ) );
corners_buffer.push_back( wxPoint( +iDTRC, -iDTRC ) );
break;
case 3:
corners_buffer.push_back( wxPoint( -dx, -iDTRC ) );
corners_buffer.push_back( wxPoint( -dx, iDTRC ) );
corners_buffer.push_back( wxPoint( -iDTRC, iDTRC ) );
corners_buffer.push_back( wxPoint( -iDTRC, -iDTRC ) );
break;
}
if( inside == false )
// add computed polygon to list
for( unsigned ic = 0; ic < corners_buffer.size(); ic++ )
{
// polygon buffer
std::vector<wxPoint> corners_buffer;
// polygons are rectangles with width of copper bridge value
// contour line width has to be taken into calculation to avoid "thermal stub bleed"
const int iDTRC =
( m_ThermalReliefCopperBridgeValue - m_ZoneMinThickness ) / 2;
switch( i )
{
case 0:
corners_buffer.push_back( wxPoint( -iDTRC, dy ) );
corners_buffer.push_back( wxPoint( +iDTRC, dy ) );
corners_buffer.push_back( wxPoint( +iDTRC, iDTRC ) );
corners_buffer.push_back( wxPoint( -iDTRC, iDTRC ) );
break;
case 1:
corners_buffer.push_back( wxPoint( -iDTRC, -dy ) );
corners_buffer.push_back( wxPoint( +iDTRC, -dy ) );
corners_buffer.push_back( wxPoint( +iDTRC, -iDTRC ) );
corners_buffer.push_back( wxPoint( -iDTRC, -iDTRC ) );
break;
case 2:
corners_buffer.push_back( wxPoint( dx, -iDTRC ) );
corners_buffer.push_back( wxPoint( dx, iDTRC ) );
corners_buffer.push_back( wxPoint( +iDTRC, iDTRC ) );
corners_buffer.push_back( wxPoint( +iDTRC, -iDTRC ) );
break;
case 3:
corners_buffer.push_back( wxPoint( -dx, -iDTRC ) );
corners_buffer.push_back( wxPoint( -dx, iDTRC ) );
corners_buffer.push_back( wxPoint( -iDTRC, iDTRC ) );
corners_buffer.push_back( wxPoint( -iDTRC, -iDTRC ) );
break;
}
// add computed polygon to list
for( unsigned ic = 0; ic < corners_buffer.size(); ic++ )
{
wxPoint cpos = corners_buffer[ic];
RotatePoint( &cpos, fAngle ); // Rotate according to module orientation
cpos += pad->ReturnShapePos(); // Shift origin to position
CPolyPt corner;
corner.x = cpos.x;
corner.y = cpos.y;
corner.end_contour = ( ic < (corners_buffer.size() - 1) ) ? 0 : 1;
cornerBufferPolysToSubstract.push_back( corner );
}
wxPoint cpos = corners_buffer[ic];
RotatePoint( &cpos, fAngle ); // Rotate according to module orientation
cpos += pad->ReturnShapePos(); // Shift origin to position
CPolyPt corner;
corner.x = cpos.x;
corner.y = cpos.y;
corner.end_contour = ( ic < (corners_buffer.size() - 1) ) ? 0 : 1;
cornerBufferPolysToSubstract.push_back( corner );
}
}
}
......
......@@ -83,8 +83,8 @@ bool TestPointInsidePolygon( std::vector <CPolyPt> aPolysList,
// with the horizontal line at the new refy position
// the line slope = seg_endY/seg_endX;
// and the x pos relative to the new origin is intersec_x = refy/slope
// Note: because horizontal segments are skipped, 1/slope exists (seg_end_y never == O)
double intersec_x = newrefy * seg_endX / seg_endY;
// Note: because horizontal segments are skipped, 1/slope exists (seg_endY never == O)
double intersec_x = (newrefy * seg_endX) / seg_endY;
if( newrefx < intersec_x ) // Intersection found with the semi-infinite line from refx to infinite
count++;
}
......@@ -101,7 +101,6 @@ bool TestPointInsidePolygon( wxPoint *aPolysList, int aCount,wxPoint aRefPoint )
// count intersection points to right of (refx,refy). If odd number, point (refx,refy) is inside polyline
int ics, ice;
int count = 0;
// find all intersection points of line with polyline sides
for( ics = 0, ice = aCount-1; ics < aCount; ice = ics++ )
{
......@@ -138,8 +137,8 @@ bool TestPointInsidePolygon( wxPoint *aPolysList, int aCount,wxPoint aRefPoint )
// with the horizontal line at the new refy position
// the line slope = seg_endY/seg_endX;
// and the x pos relative to the new origin is intersec_x = refy/slope
// Note: because horizontal segments are skipped, 1/slope exists (seg_end_y never == O)
double intersec_x = newrefy * seg_endX / seg_endY;
// Note: because horizontal segments are skipped, 1/slope exists (seg_endY never == O)
double intersec_x = (newrefy * seg_endX) / seg_endY;
if( newrefx < intersec_x ) // Intersection found with the semi-infinite line from refx to infinite
count++;
}
......
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