]> git.mxchange.org Git - flightgear.git/commitdiff
Fixing slight bugs with calculating point inside multi-contoured polygons.
authorcurt <curt>
Thu, 29 Apr 1999 21:39:27 +0000 (21:39 +0000)
committercurt <curt>
Thu, 29 Apr 1999 21:39:27 +0000 (21:39 +0000)
Tools/Construct/Makefile.am
Tools/Construct/Triangulate/polygon.cxx
Tools/Construct/Triangulate/polygon.hxx
Tools/Construct/Triangulate/triangle.cxx

index 79fc6b321979b0f01fab35f0b59843ca308b40a0..2f07b7be0b4478c7ddd4d4976e4c0f21c6cd9506 100644 (file)
@@ -3,6 +3,7 @@ SUBDIRS = \
        Clipper \
        Combine \
        GenOutput \
-       Match \
        Triangulate \
        Main
+
+#       Match
index 6020d9595bbe644546808932d11a6bf95cfe83a9..e305aa84698fb4fb05062132f3f940d14fe41de6 100644 (file)
@@ -82,13 +82,13 @@ static bool intersects( const Point3D& p0, const Point3D& p1, double x,
 }
 
 
-// calculate an "arbitrary" point inside the specified contour for
+// calculate some "arbitrary" point inside the specified contour for
 // assigning attribute areas
 void FGPolygon::calc_point_inside( const int contour, 
                                   const FGTriNodes& trinodes ) {
     Point3D tmp, min, ln, p1, p2, p3, m, result;
 
-    // 1. find point, min, with smallest y
+    // 1. find a point on the specified contour, min, with smallest y
 
     // min.y() starts greater than the biggest possible lat (degrees)
     min.sety( 100.0 );
@@ -161,7 +161,7 @@ void FGPolygon::calc_point_inside( const int contour,
            if ( intersects(p1, p2, m.x(), &result) ) {
                // cout << "intersection = " << result << endl;
                if ( ( result.y() < p3.y() ) &&
-                    ( fabs(result.y() - m.y()) > FG_EPSILON ) ) {
+                    ( result.y() > m.y() + FG_EPSILON ) ) {
                    p3 = result;
                }
            }
@@ -173,7 +173,7 @@ void FGPolygon::calc_point_inside( const int contour,
        if ( intersects(p1, p2, m.x(), &result) ) {
            // cout << "intersection = " << result << endl;
            if ( ( result.y() < p3.y() ) &&
-            ( fabs(result.y() - m.y()) > FG_EPSILON ) ) {
+                ( result.y() > m.y() + FG_EPSILON ) ) {
                p3 = result;
            }
        }
index ac21e09674da18aefe0b4d61e6d7bf52978106ba..1959bb3c13ec34535ea5a8cf40f58ffd67225db0 100644 (file)
@@ -86,7 +86,7 @@ public:
        return poly[contour][i];
     }
 
-    // calculate an "arbitrary" point inside the specified contour for
+    // calculate some "arbitrary" point inside the specified contour for
     // assigning attribute areas
     void calc_point_inside( const int contour, const FGTriNodes& trinodes );
     inline Point3D get_point_inside( const int contour ) const { 
index 80a8d5d38e5c3b73d186ef131abb3efba9270611..969899a5dc8fc612fce88e3c31682eca5ce57608 100644 (file)
@@ -40,6 +40,7 @@ FGTriangle::build( const point_list& corner_list,
                   const point_list& fit_list, 
                   const FGgpcPolyList& gpc_polys )
 {
+    int debug_counter = 0;
     FGPolygon poly;
     int index;
 
@@ -75,6 +76,7 @@ FGTriangle::build( const point_list& corner_list,
        polylist[i].clear();
 
        // cout << "area type = " << i << endl;
+       debug_counter = 0;
        current = gpc_polys.polys[i].begin();
        last = gpc_polys.polys[i].end();
        for ( ; current != last; ++current ) {
@@ -87,12 +89,6 @@ FGTriangle::build( const point_list& corner_list,
                exit(-1);
            }
 
-           if (gpc_poly->num_contours > 1 ) {
-               cout << "FATAL ERROR! no multi-contour support" << endl;
-               sleep(2);
-               // exit(-1);
-           }
-
            poly.erase();
 
            int j;
@@ -123,11 +119,38 @@ FGTriangle::build( const point_list& corner_list,
                poly.set_hole_flag( j, gpc_poly->hole[j] );
            }
 
-           for ( j = 0; j < gpc_poly->num_contours; j++ ) {
+           for ( j = 0; j < gpc_poly->num_contours; ++j ) {
                poly.calc_point_inside( j, in_nodes );
            }
 
+           // temporary ... write out/hole polygon info for debugging
+           for ( j = 0; j < (int)poly.contours(); ++j ) {
+               char pname[256];
+               sprintf(pname, "poly%02d-%02d-%02d", i, debug_counter, j);
+               FILE *fp = fopen( pname, "w" );
+               int index;
+               Point3D point;
+               for ( int k = 0; k < poly.contour_size( j ); ++k ) {
+                   index = poly.get_pt_index( j, k );
+                   point = in_nodes.get_node( index );
+                   fprintf( fp, "%.6f %.6f\n", point.x(), point.y() );
+               }
+               index = poly.get_pt_index( j, 0 );
+               point = in_nodes.get_node( index );
+               fprintf( fp, "%.6f %.6f\n", point.x(), point.y() );
+               fclose(fp);
+
+               char hname[256];
+               sprintf(hname, "hole%02d-%02d-%02d", i, debug_counter, j);
+               FILE *fh = fopen( hname, "w" );
+               point = poly.get_point_inside( j );
+               fprintf( fh, "%.6f %.6f\n", point.x(), point.y() );
+               fclose(fh);
+           }
+
            polylist[i].push_back( poly );
+
+           ++debug_counter;
        }
     }