From 5dbe785975263c5fcc71d24a27c1912dfac0fe8e Mon Sep 17 00:00:00 2001 From: zzzzrrr Date: Fri, 22 Jan 2010 19:50:35 -0500 Subject: [PATCH] added p2t namespace --- poly2tri/common/shapes.cc | 4 +++- poly2tri/common/shapes.h | 7 ++++++- poly2tri/common/utils.h | 11 ++--------- poly2tri/poly2tri.h | 1 + poly2tri/sweep/advancing_front.cc | 5 +++++ poly2tri/sweep/advancing_front.h | 4 ++++ poly2tri/sweep/cdt.cc | 8 ++++++-- poly2tri/sweep/cdt.h | 4 ++++ poly2tri/sweep/sweep.cc | 3 +++ poly2tri/sweep/sweep.h | 5 ++++- poly2tri/sweep/sweep_context.cc | 4 ++++ poly2tri/sweep/sweep_context.h | 5 ++++- testbed/main.cc | 5 +++-- 13 files changed, 49 insertions(+), 17 deletions(-) diff --git a/poly2tri/common/shapes.cc b/poly2tri/common/shapes.cc index c2f0250..4289925 100644 --- a/poly2tri/common/shapes.cc +++ b/poly2tri/common/shapes.cc @@ -31,6 +31,8 @@ #include "shapes.h" #include +namespace p2t { + Triangle::Triangle(Point& a, Point& b, Point& c) { points_[0] = &a; points_[1] = &b; points_[2] = &c; @@ -328,5 +330,5 @@ void Triangle::DebugPrint() cout << points_[2]->x << "," << points_[2]->y << endl; } - +} diff --git a/poly2tri/common/shapes.h b/poly2tri/common/shapes.h index 3d4c993..47d2037 100644 --- a/poly2tri/common/shapes.h +++ b/poly2tri/common/shapes.h @@ -28,7 +28,7 @@ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ - + // Include guard #ifndef SHAPES_H #define SHAPES_H @@ -38,6 +38,8 @@ #include #include +namespace p2t { + struct Node; struct Edge; @@ -312,5 +314,8 @@ inline void Triangle::IsInterior(bool b) interior_ = b; } +} + #endif + diff --git a/poly2tri/common/utils.h b/poly2tri/common/utils.h index c01f574..2fc3b5b 100644 --- a/poly2tri/common/utils.h +++ b/poly2tri/common/utils.h @@ -28,18 +28,11 @@ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ - -#ifndef UTILS_H -#define UTILS_H #include #include -template -int array_length(T(&)[size]) -{ - return size; -} +namespace p2t { const double PI_3div4 = 3 * M_PI / 4; const double EPSILON = 1e-12; @@ -100,5 +93,5 @@ bool InScanArea(Point& pa, Point& pb, Point& pc, Point& pd) return true; } -#endif +} diff --git a/poly2tri/poly2tri.h b/poly2tri/poly2tri.h index cc4936c..eab8910 100644 --- a/poly2tri/poly2tri.h +++ b/poly2tri/poly2tri.h @@ -30,3 +30,4 @@ */ #include "common/shapes.h" #include "sweep/cdt.h" + diff --git a/poly2tri/sweep/advancing_front.cc b/poly2tri/sweep/advancing_front.cc index 4a1e2b5..446caf7 100644 --- a/poly2tri/sweep/advancing_front.cc +++ b/poly2tri/sweep/advancing_front.cc @@ -30,6 +30,8 @@ */ #include "advancing_front.h" +namespace p2t { + AdvancingFront::AdvancingFront(Node& head, Node& tail) { head_ = &head; @@ -104,3 +106,6 @@ AdvancingFront::~AdvancingFront() delete search_node_; delete tail_; } + +} + diff --git a/poly2tri/sweep/advancing_front.h b/poly2tri/sweep/advancing_front.h index 33117b9..5b9b299 100644 --- a/poly2tri/sweep/advancing_front.h +++ b/poly2tri/sweep/advancing_front.h @@ -30,6 +30,8 @@ */ #include "../common/shapes.h" +namespace p2t { + struct Node; // Advancing front node @@ -108,3 +110,5 @@ inline void AdvancingFront::set_search(Node* node) search_node_ = node; } +} + diff --git a/poly2tri/sweep/cdt.cc b/poly2tri/sweep/cdt.cc index be027cf..5aec1ea 100644 --- a/poly2tri/sweep/cdt.cc +++ b/poly2tri/sweep/cdt.cc @@ -30,6 +30,8 @@ */ #include "cdt.h" +namespace p2t { + CDT::CDT(Point** polyline, const int& point_count) { sweep_context_ = new SweepContext(polyline, point_count); @@ -45,12 +47,12 @@ void CDT::Triangulate() sweep_->Triangulate(*sweep_context_); } -std::vector CDT::GetTriangles() +std::vector CDT::GetTriangles() { return sweep_context_->GetTriangles(); } -std::list CDT::GetMap() +std::list CDT::GetMap() { return sweep_context_->GetMap(); } @@ -61,3 +63,5 @@ CDT::~CDT() delete sweep_; } +} + diff --git a/poly2tri/sweep/cdt.h b/poly2tri/sweep/cdt.h index 94da14b..db4fdbb 100644 --- a/poly2tri/sweep/cdt.h +++ b/poly2tri/sweep/cdt.h @@ -32,6 +32,8 @@ #include "sweep_context.h" #include "sweep.h" +namespace p2t { + class CDT { public: @@ -55,3 +57,5 @@ Sweep* sweep_; /// Destructor ~CDT(); }; + +} diff --git a/poly2tri/sweep/sweep.cc b/poly2tri/sweep/sweep.cc index 66d5a72..280cec2 100644 --- a/poly2tri/sweep/sweep.cc +++ b/poly2tri/sweep/sweep.cc @@ -33,6 +33,8 @@ #include "advancing_front.h" #include "../common/utils.h" +namespace p2t { + // Triangulate simple polygon with holes void Sweep::Triangulate(SweepContext& tcx) { @@ -801,4 +803,5 @@ void Sweep::FlipScanEdgeEvent(SweepContext& tcx, Point& ep, Point& eq, Triangle& } } +} diff --git a/poly2tri/sweep/sweep.h b/poly2tri/sweep/sweep.h index 66bb06a..bf94d61 100644 --- a/poly2tri/sweep/sweep.h +++ b/poly2tri/sweep/sweep.h @@ -28,7 +28,6 @@ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ - /** * Sweep-line, Constrained Delauney Triangulation (CDT) See: Domiter, V. and * Zalik, B.(2008)'Sweep-line algorithm for constrained Delaunay triangulation', @@ -37,6 +36,8 @@ * "FlipScan" Constrained Edge Algorithm invented by Thomas Åhlén, thahlen@gmail.com */ +namespace p2t { + class SweepContext; struct Node; struct Point; @@ -110,3 +111,5 @@ void FlipScanEdgeEvent(SweepContext& tcx, Point& ep, Point& eq, Triangle& flip_t void FinalizationPolygon(SweepContext& tcx); }; + +} diff --git a/poly2tri/sweep/sweep_context.cc b/poly2tri/sweep/sweep_context.cc index db42e6c..66e574c 100644 --- a/poly2tri/sweep/sweep_context.cc +++ b/poly2tri/sweep/sweep_context.cc @@ -33,6 +33,8 @@ #include #include "advancing_front.h" +namespace p2t { + SweepContext::SweepContext(Point** polyline, const int& point_count) { basin = Basin(); @@ -168,3 +170,5 @@ SweepContext::~SweepContext() delete tail_; delete front_; } + +} diff --git a/poly2tri/sweep/sweep_context.h b/poly2tri/sweep/sweep_context.h index 9308639..37a070a 100644 --- a/poly2tri/sweep/sweep_context.h +++ b/poly2tri/sweep/sweep_context.h @@ -31,6 +31,8 @@ #include #include +namespace p2t { + // Inital triangle factor, seed triangle will extend 30% of // PointSet width to both left and right. const double kAlpha = 0.3; @@ -41,7 +43,6 @@ struct Node; struct Edge; class AdvancingFront; - class SweepContext { public: @@ -166,3 +167,5 @@ inline Point* SweepContext::tail() { return tail_; } + +} diff --git a/testbed/main.cc b/testbed/main.cc index 091913d..276349a 100644 --- a/testbed/main.cc +++ b/testbed/main.cc @@ -40,7 +40,7 @@ using namespace std; #include "../poly2tri/poly2tri.h" - +using namespace p2t; void Init(); void ShutDown(int return_code); @@ -76,6 +76,7 @@ bool draw_map = false; int main(int argc, char* argv[]) { + if (argc != 5) { cout << "Usage: p2t filename centerX centerY zoom" << endl; return 1; @@ -101,7 +102,7 @@ int main(int argc, char* argv[]) string line; ifstream myfile(argv[1]); - vector points; + vector points; if (myfile.is_open()) { while (!myfile.eof()) { getline(myfile, line);