]> git.mxchange.org Git - flightgear.git/commitdiff
Renamed main.cxx to testclipper.cxx
authorcurt <curt>
Sat, 13 Mar 1999 23:51:32 +0000 (23:51 +0000)
committercurt <curt>
Sat, 13 Mar 1999 23:51:32 +0000 (23:51 +0000)
Converted clipper routines to a class FGClipper.

Clipper/Makefile.am
Clipper/clipper.cxx
Clipper/clipper.hxx
Clipper/main.cxx [deleted file]
Clipper/testclipper.cxx [new file with mode: 0644]

index 07ddbce968903aaa5e1f380bdfbd3ab52f378ac8..87a59e28bf05add9999447c75bc32656bc0ab346 100644 (file)
@@ -4,7 +4,7 @@ libClipper_a_SOURCES = clipper.cxx clipper.hxx
 
 bin_PROGRAMS = testclipper
 
-testclipper_SOURCES = main.cxx
+testclipper_SOURCES = testclipper.cxx
 
 testclipper_LDADD = $(top_builddir)/Tools/Construct/Clipper/libClipper.a \
        $(top_builddir)/Tools/Lib/Polygon/libPolygon.a \
index e4aaa76f0b424404fe0fd7f2385bf434bc559124..3ea78c200fd2f5888116632d97f73209873c0e12 100644 (file)
  
 
 
-#include "clipper.hxx"
-
 #include <Debug/logstream.hxx>
 #include <Include/fg_constants.h>
 #include <Misc/fgstream.hxx>
 #include <Polygon/names.hxx>
 
+#include "clipper.hxx"
 
-#define EXTRA_SAFETY_CLIP
 
-#define FG_MAX_VERTICES 100000
+// Constructor
+FGClipper::FGClipper( void ) {
+}
 
-static gpc_vertex_list v_list;
-// static gpc_polygon poly;
-static FGPolyList polys_in, polys_out;
+
+// Destructor
+FGClipper::~FGClipper( void ) {
+}
 
 
 // Initialize Clipper (allocate and/or connect structures)
-bool fgClipperInit() {
+bool FGClipper::init() {
     v_list.num_vertices = 0;
     v_list.vertex = new gpc_vertex[FG_MAX_VERTICES];;
 
@@ -52,7 +53,7 @@ bool fgClipperInit() {
 
 
 // Load a polygon definition file
-bool fgClipperLoadPolygons(const string& path) {
+bool FGClipper::load_polys(const string& path) {
     string poly_name;
     AreaType poly_type;
     int contours, count, i, j;
@@ -141,7 +142,7 @@ bool fgClipperLoadPolygons(const string& path) {
 
 
 // Do actually clipping work
-bool fgClipperMaster(const point2d& min, const point2d& max) {
+bool FGClipper::clip_all(const point2d& min, const point2d& max) {
     gpc_polygon accum, result_diff, result_union, tmp;
     polylist_iterator current, last;
 
@@ -221,6 +222,10 @@ bool fgClipperMaster(const point2d& min, const point2d& max) {
 
 
 // $Log$
+// Revision 1.2  1999/03/13 23:51:33  curt
+// Renamed main.cxx to testclipper.cxx
+// Converted clipper routines to a class FGClipper.
+//
 // Revision 1.1  1999/03/01 15:39:39  curt
 // Initial revision.
 //
index 79b7e16daa1a954f4430ea44a813fe811b750164..b9f0d1bed86bcf64061a72b7e3c15e17a558e2af 100644 (file)
@@ -52,6 +52,8 @@ typedef vector < gpc_polygon * > polylist;
 typedef polylist::iterator polylist_iterator;
 
 #define FG_MAX_AREAS 20
+#define EXTRA_SAFETY_CLIP
+#define FG_MAX_VERTICES 100000
 
 class point2d {
 public:
@@ -66,22 +68,41 @@ public:
 };
 
 
-// Initialize Clipper (allocate and/or connect structures)
-bool fgClipperInit();
+class FGClipper {
 
+private:
 
-// Load a polygon definition file
-bool fgClipperLoadPolygons(const string& path);
+    gpc_vertex_list v_list;
+    // static gpc_polygon poly;
+    FGPolyList polys_in, polys_out;
 
+public:
+
+    // Constructor
+    FGClipper( void );
 
-// Do actually clipping work
-bool fgClipperMaster(const point2d& min, const point2d& max);
+    // Destructor
+    ~FGClipper( void );
+
+    // Initialize Clipper (allocate and/or connect structures)
+    bool init();
+
+    // Load a polygon definition file
+    bool load_polys(const string& path);
+
+    // Do actually clipping work
+    bool clip_all(const point2d& min, const point2d& max);
+};
 
 
 #endif // _CLIPPER_HXX
 
 
 // $Log$
+// Revision 1.2  1999/03/13 23:51:34  curt
+// Renamed main.cxx to testclipper.cxx
+// Converted clipper routines to a class FGClipper.
+//
 // Revision 1.1  1999/03/01 15:39:39  curt
 // Initial revision.
 //
diff --git a/Clipper/main.cxx b/Clipper/main.cxx
deleted file mode 100644 (file)
index 4aa613a..0000000
+++ /dev/null
@@ -1,114 +0,0 @@
-// main.cxx -- sample use of the clipper lib
-//
-// Written by Curtis Olson, started February 1999.
-//
-// Copyright (C) 1999  Curtis L. Olson  - curt@flightgear.org
-//
-// This program is free software; you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation; either version 2 of the License, or
-// (at your option) any later version.
-//
-// This program is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with this program; if not, write to the Free Software
-// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-//
-// $Id$
-// (Log is kept at end of this file)
-
-
-#include "clipper.hxx"
-
-#include <Debug/logstream.hxx>
-#include <Bucket/newbucket.hxx>
-
-
-int main( int argc, char **argv ) {
-    point2d global_min, global_max;
-
-    fglog().setLogLevels( FG_ALL, FG_DEBUG );
-
-    global_min.x = global_min.y = 200;
-    global_max.y = global_max.x = -200;
-
-    fgClipperInit();
-
-    if ( argc < 2 ) {
-       FG_LOG( FG_CLIPPER, FG_ALERT, "Usage: " << argv[0] 
-               << " file1 file2 ..." );
-       exit(-1);
-    }
-
-    // process all specified polygon files
-    for ( int i = 1; i < argc; i++ ) {
-       string full_path = argv[i];
-
-       // determine bucket for this polygon
-       int pos = full_path.rfind("/");
-       string file_name = full_path.substr(pos + 1);
-       cout << "file name = " << file_name << endl;
-
-       pos = file_name.find(".");
-       string base_name = file_name.substr(0, pos);
-       cout << "base_name = " << base_name << endl;
-
-       long int index;
-       sscanf( base_name.c_str(), "%ld", &index);
-       FGBucket b(index);
-       cout << "bucket = " << b << endl;
-
-       // calculate bucket dimensions
-       point2d c, min, max;
-
-       c.x = b.get_center_lon();
-       c.y = b.get_center_lat();
-       double span = bucket_span(c.y);
-
-       if ( (c.y >= -89.0) && (c.y < 89.0) ) {
-           min.x = c.x - span / 2.0;
-           max.x = c.x + span / 2.0;
-           min.y = c.y - FG_HALF_BUCKET_SPAN;
-           max.y = c.y + FG_HALF_BUCKET_SPAN;
-       } else if ( c.y < -89.0) {
-           min.x = -90.0;
-           max.x = -89.0;
-           min.y = -180.0;
-           max.y = 180.0;
-       } else if ( c.y >= 89.0) {
-           min.x = 89.0;
-           max.x = 90.0;
-           min.y = -180.0;
-           max.y = 180.0;
-       } else {
-           FG_LOG ( FG_GENERAL, FG_ALERT, 
-                    "Out of range latitude in clip_and_write_poly() = " 
-                    << c.y );
-       }
-
-       if ( min.x < global_min.x ) global_min.x = min.x;
-       if ( min.y < global_min.y ) global_min.y = min.y;
-       if ( max.x > global_max.x ) global_max.x = max.x;
-       if ( max.y > global_max.y ) global_max.y = max.y;
-
-       // finally, load the polygon(s) from this file
-       fgClipperLoadPolygons( full_path );
-    }
-
-    // do the clipping
-    fgClipperMaster(global_min, global_max);
-
-    FG_LOG( FG_CLIPPER, FG_INFO, "finished main" );
-
-    return 0;
-}
-
-// $Log$
-// Revision 1.1  1999/03/01 15:39:39  curt
-// Initial revision.
-//
diff --git a/Clipper/testclipper.cxx b/Clipper/testclipper.cxx
new file mode 100644 (file)
index 0000000..2a0477b
--- /dev/null
@@ -0,0 +1,119 @@
+// main.cxx -- sample use of the clipper lib
+//
+// Written by Curtis Olson, started February 1999.
+//
+// Copyright (C) 1999  Curtis L. Olson  - curt@flightgear.org
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+//
+// $Id$
+// (Log is kept at end of this file)
+
+
+#include <Debug/logstream.hxx>
+#include <Bucket/newbucket.hxx>
+
+#include "clipper.hxx"
+
+
+int main( int argc, char **argv ) {
+    point2d global_min, global_max;
+
+    fglog().setLogLevels( FG_ALL, FG_DEBUG );
+
+    global_min.x = global_min.y = 200;
+    global_max.y = global_max.x = -200;
+
+    FGClipper clipper;
+    clipper.init();
+
+    if ( argc < 2 ) {
+       FG_LOG( FG_CLIPPER, FG_ALERT, "Usage: " << argv[0] 
+               << " file1 file2 ..." );
+       exit(-1);
+    }
+
+    // process all specified polygon files
+    for ( int i = 1; i < argc; i++ ) {
+       string full_path = argv[i];
+
+       // determine bucket for this polygon
+       int pos = full_path.rfind("/");
+       string file_name = full_path.substr(pos + 1);
+       cout << "file name = " << file_name << endl;
+
+       pos = file_name.find(".");
+       string base_name = file_name.substr(0, pos);
+       cout << "base_name = " << base_name << endl;
+
+       long int index;
+       sscanf( base_name.c_str(), "%ld", &index);
+       FGBucket b(index);
+       cout << "bucket = " << b << endl;
+
+       // calculate bucket dimensions
+       point2d c, min, max;
+
+       c.x = b.get_center_lon();
+       c.y = b.get_center_lat();
+       double span = bucket_span(c.y);
+
+       if ( (c.y >= -89.0) && (c.y < 89.0) ) {
+           min.x = c.x - span / 2.0;
+           max.x = c.x + span / 2.0;
+           min.y = c.y - FG_HALF_BUCKET_SPAN;
+           max.y = c.y + FG_HALF_BUCKET_SPAN;
+       } else if ( c.y < -89.0) {
+           min.x = -90.0;
+           max.x = -89.0;
+           min.y = -180.0;
+           max.y = 180.0;
+       } else if ( c.y >= 89.0) {
+           min.x = 89.0;
+           max.x = 90.0;
+           min.y = -180.0;
+           max.y = 180.0;
+       } else {
+           FG_LOG ( FG_GENERAL, FG_ALERT, 
+                    "Out of range latitude in clip_and_write_poly() = " 
+                    << c.y );
+       }
+
+       if ( min.x < global_min.x ) global_min.x = min.x;
+       if ( min.y < global_min.y ) global_min.y = min.y;
+       if ( max.x > global_max.x ) global_max.x = max.x;
+       if ( max.y > global_max.y ) global_max.y = max.y;
+
+       // finally, load the polygon(s) from this file
+       clipper.load_polys( full_path );
+    }
+
+    // do the clipping
+    clipper.clip_all(global_min, global_max);
+
+    FG_LOG( FG_CLIPPER, FG_INFO, "finished main" );
+
+    return 0;
+}
+
+// $Log$
+// Revision 1.1  1999/03/13 23:51:36  curt
+// Renamed main.cxx to testclipper.cxx
+// Converted clipper routines to a class FGClipper.
+//
+// Revision 1.1  1999/03/01 15:39:39  curt
+// Initial revision.
+//