mirror of
https://github.com/jhasse/poly2tri.git
synced 2024-11-16 02:32:25 +01:00
code cleanup
This commit is contained in:
parent
2df225041f
commit
ac40ef4631
@ -29,6 +29,7 @@
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
#include "shapes.h"
|
||||
#include <iostream>
|
||||
|
||||
Triangle::Triangle(Point& a, Point& b, Point& c)
|
||||
{
|
||||
|
@ -37,8 +37,6 @@
|
||||
#include <cstddef>
|
||||
#include <assert.h>
|
||||
#include <cmath>
|
||||
#include <stdio.h>
|
||||
#include <iostream>
|
||||
|
||||
struct Node;
|
||||
struct Edge;
|
||||
@ -50,51 +48,57 @@ struct Point {
|
||||
/// Default constructor does nothing (for performance).
|
||||
Point()
|
||||
{
|
||||
x = 0.0; y = 0.0;
|
||||
x = 0.0;
|
||||
y = 0.0;
|
||||
}
|
||||
|
||||
/// The edges this point constitutes an upper ending point
|
||||
std::vector<Edge*> edge_list;
|
||||
|
||||
/// 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.
|
||||
void set_zero()
|
||||
{
|
||||
x = 0.0f; y = 0.0f;
|
||||
x = 0.0f;
|
||||
y = 0.0f;
|
||||
}
|
||||
|
||||
/// Set this point to some specified coordinates.
|
||||
void set(double x_, double y_)
|
||||
{
|
||||
x = x_; y = y_;
|
||||
x = x_;
|
||||
y = y_;
|
||||
}
|
||||
|
||||
/// Negate this point.
|
||||
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.
|
||||
void operator +=(const Point& v)
|
||||
{
|
||||
x += v.x; y += v.y;
|
||||
x += v.x;
|
||||
y += v.y;
|
||||
}
|
||||
|
||||
/// Subtract a point from this point.
|
||||
void operator -=(const Point& v)
|
||||
{
|
||||
x -= v.x; y -= v.y;
|
||||
x -= v.x;
|
||||
y -= v.y;
|
||||
}
|
||||
|
||||
/// Multiply this point by a scalar.
|
||||
void operator *=(double a)
|
||||
{
|
||||
x *= a; y *= a;
|
||||
x *= a;
|
||||
y *= a;
|
||||
}
|
||||
|
||||
/// Get the length of this point (the norm).
|
||||
@ -112,10 +116,6 @@ struct Point {
|
||||
return len;
|
||||
}
|
||||
|
||||
void DebugPrint()
|
||||
{
|
||||
printf("%f,%f ", x, y);
|
||||
}
|
||||
};
|
||||
|
||||
// Represents a simple polygon's edge
|
||||
|
@ -29,7 +29,6 @@
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
#include "advancing_front.h"
|
||||
#include "mesh.h"
|
||||
#include "sweep_context.h"
|
||||
#include "sweep.h"
|
||||
|
||||
|
@ -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));
|
||||
}
|
||||
*/
|
||||
}
|
@ -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);
|
||||
};
|
@ -79,25 +79,8 @@ void SweepContext::InitTriangulation()
|
||||
tail_ = new Point(xmin - dx, ymin - dy);
|
||||
|
||||
// Sort points along y-axis
|
||||
double init_time = glfwGetTime();
|
||||
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)
|
||||
@ -106,13 +89,6 @@ void SweepContext::InitEdges(Point** polyline, const int& point_count)
|
||||
int j = i < point_count - 1 ? i + 1 : 0;
|
||||
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)
|
||||
|
Loading…
Reference in New Issue
Block a user