- // find bucket based on average center point of hull list.
- // Eventually we'll need to handle cases where the area crosses
- // bucket boundaries.
- fgBucketFind( average.lon, average.lat, &b);
- printf( "Bucket = lon,lat = %d,%d x,y index = %d,%d\n",
- b.lon, b.lat, b.x, b.y);
-
- index = fgBucketGenIndex(&b);
- fgBucketGenBasePath(&b, base);
- path = root + "/Scenery/" + base;
- command = "mkdir -p " + path;
- system( command.c_str() );
-
- sprintf(tmp, "%ld", index);
- exfile = path + "/" + tmp + ".node.ex";
- file = path + "/" + tmp + ".poly";
- aptfile = path + "/" + tmp + ".apt";
- printf( "extra node file = %s\n", exfile.c_str() );
- printf( "poly file = %s\n", file.c_str() );
- printf( "apt file = %s\n", aptfile.c_str() );
-
- // output exclude nodes
- printf("Output exclude nodes\n");
- if ( (fd = fopen(exfile.c_str(), "w")) == NULL ) {
- printf("Cannot open file: %s\n", exfile.c_str());
- exit(-1);
- }
-
- fprintf( fd, "%d 2 0 0\n", count );
-
- current = hull_list.begin();
- last = hull_list.end();
- i = 1;
- for ( ; current != last ; ++current ) {
- // printf( "(%.4f, %.4f)\n",
- fprintf( fd, "%d %.2f %.2f %.2f\n", i,
- (*current).lon * 3600.0, (*current).lat * 3600.0,
- (double)elev * FEET_TO_METER );
- ++i;
- }
- fclose(fd);
-
- // output poly
- printf("Output poly\n");
- if ( (fd = fopen(file.c_str(), "w")) == NULL ) {
- printf("Cannot open file: %s\n", file.c_str());
- exit(-1);
- }
-
- // output empty node list
- fprintf(fd, "0 2 0 0\n");
-
- // output segments
- fprintf( fd, "%d 0\n", count );
- for ( i = 1; i < count; i++ ) {
- fprintf( fd, "%d %d %d\n", i, i, i + 1 );
- }
- fprintf( fd, "%d %d %d\n", count, count, 1 );
-
- // output hole center
- fprintf( fd, "1\n");
- fprintf( fd, "1 %.2f %.2f\n", average.x * 3600.0, average.y * 3600);
-
- fclose(fd);
-
- // output "apt" file
- printf("Output airport\n");
- if ( (fd = fopen(aptfile.c_str(), "w")) == NULL ) {
- printf("Cannot open file: %s\n", aptfile.c_str());
- exit(-1);
- }
-
- // write main airport identifier
- fprintf(fd, "a %s", last_airport.c_str() );
-
- // write perimeter polygon
- current = hull_list.begin();
- last = hull_list.end();
- for ( ; current != last ; ++current ) {
- fprintf( fd, "p %.7f %.7f %.2f\n", (*current).lon, (*current).lat,
- (double)elev * FEET_TO_METER );
- }
+ // find buckets for center, min, and max points of convex hull.
+ // note to self: self, you should think about checking for runways
+ // that span the data line
+ FGBucket b(average.lon, average.lat);
+ FGBucket b_min(min.x, min.y);
+ FGBucket b_max(max.x, max.y);
+ cout << "Bucket center = " << b << endl;
+ cout << "Bucket min = " << b_min << endl;
+ cout << "Bucket max = " << b_max << endl;
+
+ if ( b_min == b_max ) {
+ write_airport( hull_list, b, root, true );
+ } else {
+ FGBucket b_cur;
+ int dx, dy, i, j;
+
+ fgBucketDiff(b_min, b_max, &dx, &dy);
+ cout << "airport spans tile boundaries" << endl;
+ cout << " dx = " << dx << " dy = " << dy << endl;
+
+ if ( (dx > 1) || (dy > 1) ) {
+ cout << "somethings really wrong!!!!" << endl;
+ exit(-1);
+ }