code cleanup

This commit is contained in:
zzzzrrr 2010-01-22 15:22:08 -05:00
parent 2df225041f
commit ac40ef4631
7 changed files with 17 additions and 139 deletions

View File

@ -29,6 +29,7 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
#include "shapes.h" #include "shapes.h"
#include <iostream>
Triangle::Triangle(Point& a, Point& b, Point& c) Triangle::Triangle(Point& a, Point& b, Point& c)
{ {

View File

@ -37,8 +37,6 @@
#include <cstddef> #include <cstddef>
#include <assert.h> #include <assert.h>
#include <cmath> #include <cmath>
#include <stdio.h>
#include <iostream>
struct Node; struct Node;
struct Edge; struct Edge;
@ -50,51 +48,57 @@ struct Point {
/// Default constructor does nothing (for performance). /// Default constructor does nothing (for performance).
Point() Point()
{ {
x = 0.0; y = 0.0; x = 0.0;
y = 0.0;
} }
/// The edges this point constitutes an upper ending point /// The edges this point constitutes an upper ending point
std::vector<Edge*> edge_list; std::vector<Edge*> edge_list;
/// Construct using coordinates. /// Construct using coordinates.
Point(double x, double y) : x(x), y(y) Point(double x, double y) : x(x), y(y) {}
{
}
/// Set this point to all zeros. /// Set this point to all zeros.
void set_zero() void set_zero()
{ {
x = 0.0f; y = 0.0f; x = 0.0f;
y = 0.0f;
} }
/// Set this point to some specified coordinates. /// Set this point to some specified coordinates.
void set(double x_, double y_) void set(double x_, double y_)
{ {
x = x_; y = y_; x = x_;
y = y_;
} }
/// Negate this point. /// Negate this point.
Point operator -() const Point operator -() const
{ {
Point v; v.set(-x, -y); return v; Point v;
v.set(-x, -y);
return v;
} }
/// Add a point to this point. /// Add a point to this point.
void operator +=(const Point& v) void operator +=(const Point& v)
{ {
x += v.x; y += v.y; x += v.x;
y += v.y;
} }
/// Subtract a point from this point. /// Subtract a point from this point.
void operator -=(const Point& v) void operator -=(const Point& v)
{ {
x -= v.x; y -= v.y; x -= v.x;
y -= v.y;
} }
/// Multiply this point by a scalar. /// Multiply this point by a scalar.
void operator *=(double a) void operator *=(double a)
{ {
x *= a; y *= a; x *= a;
y *= a;
} }
/// Get the length of this point (the norm). /// Get the length of this point (the norm).
@ -112,10 +116,6 @@ struct Point {
return len; return len;
} }
void DebugPrint()
{
printf("%f,%f ", x, y);
}
}; };
// Represents a simple polygon's edge // Represents a simple polygon's edge

View File

@ -29,7 +29,6 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
#include "advancing_front.h" #include "advancing_front.h"
#include "mesh.h"
#include "sweep_context.h" #include "sweep_context.h"
#include "sweep.h" #include "sweep.h"

View File

@ -1,49 +0,0 @@
/*
* Poly2Tri Copyright (c) 2009-2010, Poly2Tri Contributors
* http://code.google.com/p/poly2tri/
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* * Neither the name of Poly2Tri nor the names of its contributors may be
* used to endorse or promote products derived from this software without specific
* prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "mesh.h"
// Recursively collect interior triangles and clean the mesh
// Excludes exterior triangles outside constrained edges
// Depth first search
void Mesh::clean(Triangle& triangle)
{
/*
if(triangle != NULL && !triangle.interior)
{
triangle.interior = true;
triangles += triangle;
for(i <- 0 until 3)
if(!triangle.edges(i))
clean(triangle.neighbors(i));
}
*/
}

View File

@ -1,48 +0,0 @@
/*
* Poly2Tri Copyright (c) 2009-2010, Poly2Tri Contributors
* http://code.google.com/p/poly2tri/
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* * Neither the name of Poly2Tri nor the names of its contributors may be
* used to endorse or promote products derived from this software without specific
* prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <vector>
using namespace std;
class Triangle;
class Mesh
{
public:
/// Triangles that constitute the mesh
vector<Triangle> map;
// Debug triangles
//val debug = new ArrayBuffer[Triangle]
//val triangles = new ArrayBuffer[Triangle]
void clean(Triangle& triangle);
};

View File

@ -79,25 +79,8 @@ void SweepContext::InitTriangulation()
tail_ = new Point(xmin - dx, ymin - dy); tail_ = new Point(xmin - dx, ymin - dy);
// Sort points along y-axis // Sort points along y-axis
double init_time = glfwGetTime();
std::sort(points_, points_ + point_count_, cmp); std::sort(points_, points_ + point_count_, cmp);
double dt = glfwGetTime() - init_time;
printf("Sort time (secs) = %f\n", dt);
/*
printf("*************************\n");
for (int i = 0; i < point_count_; i++) {
printf("%f,%f ", points_[i]->x, points_[i]->y);
printf("%p\n", points_[i]);
}
/*
printf("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n");
for(int i = 0; i < edge_list.size(); i++) {
edge_list[i]->p->DebugPrint(); edge_list[i]->q->DebugPrint();
printf("%p, %p\n", edge_list[i]->p, edge_list[i]->q);
}
*/
} }
void SweepContext::InitEdges(Point** polyline, const int& point_count) void SweepContext::InitEdges(Point** polyline, const int& point_count)
@ -106,13 +89,6 @@ void SweepContext::InitEdges(Point** polyline, const int& point_count)
int j = i < point_count - 1 ? i + 1 : 0; int j = i < point_count - 1 ? i + 1 : 0;
edge_list.push_back(new Edge(*polyline[i], *polyline[j])); edge_list.push_back(new Edge(*polyline[i], *polyline[j]));
} }
/*
for(int i = 0; i < edge_list.size(); i++) {
edge_list[i]->p->DebugPrint(); edge_list[i]->q->DebugPrint();
printf("%p, %p\n", edge_list[i]->p, edge_list[i]->q);
}
*/
} }
Point* SweepContext::GetPoint(const int& index) Point* SweepContext::GetPoint(const int& index)

View File

@ -7,7 +7,6 @@ blddir = 'build'
p2t_source_files = ['poly2tri/common/shapes.cc', p2t_source_files = ['poly2tri/common/shapes.cc',
'poly2tri/sweep/cdt.cc', 'poly2tri/sweep/cdt.cc',
'poly2tri/sweep/advancing_front.cc', 'poly2tri/sweep/advancing_front.cc',
'poly2tri/sweep/mesh.cc',
'poly2tri/sweep/sweep_context.cc', 'poly2tri/sweep/sweep_context.cc',
'poly2tri/sweep/sweep.cc'] 'poly2tri/sweep/sweep.cc']