Intermediate fix for calc_point_inside
This commit is contained in:
parent
fe7f626265
commit
cd90019bbf
2 changed files with 34 additions and 31 deletions
|
@ -796,6 +796,8 @@ void build_airport( string airport_id, float alt_m,
|
|||
for ( k = 0; k < (int)rwy_polys.size(); ++k ) {
|
||||
TGPolygon poly = rwy_polys[k].get_poly();
|
||||
|
||||
SG_LOG(SG_GENERAL, SG_DEBUG, "total size of section " << k << " before =" << poly.total_size());
|
||||
|
||||
poly = remove_dups( poly );
|
||||
SG_LOG(SG_GENERAL, SG_DEBUG, "total size after remove_dups() = " << poly.total_size());
|
||||
poly = remove_bad_contours( poly );
|
||||
|
@ -822,7 +824,7 @@ void build_airport( string airport_id, float alt_m,
|
|||
// tesselate the polygons and prepair them for final output
|
||||
|
||||
for ( i = 0; i < (int)rwy_polys.size(); ++i ) {
|
||||
SG_LOG(SG_GENERAL, SG_DEBUG, "Tesselating section = " << i);
|
||||
SG_LOG(SG_GENERAL, SG_DEBUG, "Tesselating section = " << i << " flag = " << rwy_polys[i].get_flag());
|
||||
|
||||
TGPolygon poly = rwy_polys[i].get_poly();
|
||||
SG_LOG(SG_GENERAL, SG_DEBUG, "total size before = " << poly.total_size());
|
||||
|
|
|
@ -395,25 +395,11 @@ static void intersect_yline_with_contour( double yline, TGContourNode *node, TGP
|
|||
|
||||
// cout << "intersect_yline_with_contour() p0=(" << p0.x() << ", " << p0.y() << ") p1=(" << p1.x() << ", " << p1.y() << ") ymin=" << ymin << " ymax=" << ymax << " yline=" << yline << endl;
|
||||
|
||||
if ((yline+SG_EPSILON)<ymin || ymax<(yline-SG_EPSILON)) {
|
||||
if (yline<ymin || ymax<yline) {
|
||||
// cout << "intersect_yline_with_contour() does not intersect" << endl;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (ymax-ymin<SG_EPSILON) {
|
||||
// cout << "intersect_yline_with_contour() edge is nearly x-parallel" << endl;
|
||||
|
||||
if (yline-ymin<SG_EPSILON) {
|
||||
throw sg_exception("Edges must not coincide with x-parallel intersection line");
|
||||
}
|
||||
// else the edge does not intersect
|
||||
continue;
|
||||
}
|
||||
|
||||
if (yline-ymin<SG_EPSILON) {
|
||||
throw sg_exception("Points may not lie on x-parallel intersection line");
|
||||
}
|
||||
|
||||
double t=(yline-p0.y())/(p1.y()-p0.y());
|
||||
double x=p0.x()+t*(p1.x()-p0.x());
|
||||
|
||||
|
@ -477,6 +463,8 @@ static void calc_point_inside( TGContourNode *node, TGPolygon &p ) {
|
|||
|
||||
sort(allpoints.begin(), allpoints.end(), Point3DOrdering(PY));
|
||||
|
||||
// TODO: check bounding box size for whether polygon is empty
|
||||
|
||||
point_list::iterator point_it;
|
||||
|
||||
point_it=allpoints.begin();
|
||||
|
@ -494,11 +482,11 @@ static void calc_point_inside( TGContourNode *node, TGPolygon &p ) {
|
|||
lastpt=*point_it;
|
||||
}
|
||||
|
||||
if (maxdiff<SG_EPSILON) {
|
||||
throw sg_exception("Polygon is empty");
|
||||
}
|
||||
cout << "calc_point_inside() " << allpoints.size() << " points ";
|
||||
copy(allpoints.begin(), allpoints.end(), ostream_iterator<Point3D>(cout, " "));
|
||||
cout << endl;
|
||||
|
||||
// cout << "calc_point_inside() contour_num=" << contour_num << " " << pts.size() << " points ymin=" << ymin << " ymax=" << ymax << endl;
|
||||
cout << "calc_point_inside() maxdiff=" << maxdiff << " yline=" << yline << endl;
|
||||
|
||||
vector < double > xcuts;
|
||||
|
||||
|
@ -512,9 +500,9 @@ static void calc_point_inside( TGContourNode *node, TGPolygon &p ) {
|
|||
|
||||
sort( xcuts.begin(), xcuts.end() );
|
||||
|
||||
// cout << "calc_point_inside() " << xcuts.size() << " intersections ";
|
||||
// copy(xcuts.begin(), xcuts.end(), ostream_iterator<double>(cout, " "));
|
||||
// cout << endl;
|
||||
cout << "calc_point_inside() " << xcuts.size() << " intersections ";
|
||||
copy(xcuts.begin(), xcuts.end(), ostream_iterator<double>(cout, " "));
|
||||
cout << endl;
|
||||
|
||||
if ( xcuts.size() < 2 || (xcuts.size() % 2) != 0 ) {
|
||||
throw sg_exception("Geometric inconsistency in calc_point_inside()");
|
||||
|
@ -1026,13 +1014,26 @@ TGPolygon remove_bad_contours( const TGPolygon &poly ) {
|
|||
|
||||
for ( int i = 0; i < poly.contours(); ++i ) {
|
||||
point_list contour = poly.get_contour( i );
|
||||
if ( contour.size() >= 3 ) {
|
||||
// good
|
||||
if ( contour.size() < 3) {
|
||||
//cout << "tossing a bad contour" << endl;
|
||||
continue;
|
||||
}
|
||||
double xmin,xmax,ymin,ymax;
|
||||
xmin=xmax=contour[0].x();
|
||||
ymin=ymax=contour[0].y();
|
||||
for ( int j = 1; j < contour.size(); ++j ) {
|
||||
xmin = SGMisc<double>::min(xmin,contour[j].x());
|
||||
ymin = SGMisc<double>::min(ymin,contour[j].y());
|
||||
xmax = SGMisc<double>::max(xmax,contour[j].x());
|
||||
ymax = SGMisc<double>::max(ymax,contour[j].y());
|
||||
}
|
||||
if ( xmax-xmin < SG_EPSILON || ymax-ymin < SG_EPSILON ) {
|
||||
//cout << "tossing a bad contour (too small)" << endl;
|
||||
continue;
|
||||
}
|
||||
/* keeping the contour */
|
||||
int flag = poly.get_hole_flag( i );
|
||||
result.add_contour( contour, flag );
|
||||
} else {
|
||||
//cout << "tossing a bad contour" << endl;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
|
|
Loading…
Add table
Reference in a new issue