Commit 6032a9ab authored by JasonPries's avatar JasonPries
Browse files

Changed Edge members from type Edge* to type size_t

This is initial work on changing Mesh::Edges from type std::vector<Edge*> to std::vector<Edge>
parent 4e734e84
#include "Mesh.hpp"
Edge::Edge(Curve *c, bool direction, size_t v) {
Edge::Edge(Curve *c, bool d, size_t n, size_t s) {
ConstraintCurve = c;
Node = v;
Twin = this;
Next = nullptr;
Prev = nullptr;
Orientation = direction;
Node = n;
Self = s;
Twin = SIZE_MAX;
Next = SIZE_MAX;
Prev = SIZE_MAX;
Orientation = d;
}
bool Edge::is_valid() const {
size_t Edge::tip(Mesh const &mesh) const {
return (Next == Self ? mesh.Edges[Twin]->Node : mesh.Edges[Next]->Node);
};
bool Edge::is_valid(Mesh const &mesh) const {
bool value = true;
value = value && (this == Next->Prev);
value = value && (this == Prev->Next);
value = value && (this == Twin->Twin);
value = value && (Self == mesh.Edges[Next]->Prev);
value = value && (Self == mesh.Edges[Prev]->Next);
value = value && (Self == mesh.Edges[Twin]->Twin);
return value;
}
bool Edge::swap() {
bool Edge::swap(Mesh const &mesh) {
if (ConstraintCurve == nullptr) {
Edge * e1 = Next;
Edge * e2 = Prev;
Edge * e3 = Twin->Next;
Edge * e4 = Twin->Prev;
Edge *e1 = mesh.Edges[Next];
Edge *e2 = mesh.Edges[Prev];
Edge *e3 = mesh.Edges[mesh.Edges[Twin]->Next];
Edge *e4 = mesh.Edges[mesh.Edges[Twin]->Prev];
Edge *twin = mesh.Edges[Twin];
Node = e2->Node;
Next = e4;
Prev = e1;
Next = e4->Self;
Prev = e1->Self;
Mark = false;
Twin->Node = e4->Node;
Twin->Next = e2;
Twin->Prev = e3;
Twin->Mark = false;
twin->Node = e4->Node;
twin->Next = e2->Self;
twin->Prev = e3->Self;
twin->Mark = false;
e1->Next = this;
e1->Prev = e4;
e1->Next = Self;
e1->Prev = e4->Self;
e1->Mark = false;
e2->Next = e3;
e2->Next = e3->Self;
e2->Prev = Twin;
e2->Mark = false;
e3->Next = Twin;
e3->Prev = e2;
e3->Prev = e2->Self;
e3->Mark = false;
e4->Next = e1;
e4->Prev = this;
e4->Next = e1->Self;
e4->Prev = Self;
e4->Mark = false;
return true;
......@@ -59,9 +65,9 @@ bool Edge::swap() {
}
}
void Edge::recursive_mark() {
if (Mark && Next->Mark && Prev->Mark) {
Next->Mark = false;
Prev->Mark = false;
void Edge::recursive_mark(Mesh const &mesh) {
if (Mark && mesh.Edges[Next]->Mark && mesh.Edges[Prev]->Mark) {
mesh.Edges[Next]->Mark = false;
mesh.Edges[Prev]->Mark = false;
}
}
\ No newline at end of file
......@@ -12,24 +12,26 @@ public:
friend bool are_intersecting(Edge const *e0, Edge const *e1, Mesh const &m);
// Constructors
Edge() : Node(SIZE_MAX), Next(nullptr), Prev(nullptr), Twin(this), ConstraintCurve(nullptr), Orientation(true), Mark(false) {};
Edge() : Node(SIZE_MAX), Self(SIZE_MAX), Next(SIZE_MAX), Prev(SIZE_MAX), Twin(SIZE_MAX), ConstraintCurve(nullptr), Orientation(true), Mark(false) {};
Edge(size_t v, Edge &n, Edge &p, Edge &t) : Node(v), Next(&n), Prev(&p), Twin(&t), ConstraintCurve(nullptr), Orientation(true), Mark(false) {};
Edge(size_t v, size_t s, Edge &n, Edge &p, Edge &tw) : Node(v), Self(s), Next(n.Self), Prev(p.Self), Twin(tw.Self), ConstraintCurve(nullptr), Orientation(true), Mark(false) {};
Edge(Curve *c, bool Orientation, size_t v);
Edge(Curve *c, bool Orientation, size_t v, size_t s);
// Accessors
size_t node() const { return Node; };
size_t base() const { return Node; };
size_t tip() const { return (next() == nullptr ? twin()->base() : next()->base()); };
size_t tip(Mesh const &mesh) const;
Edge const *next() const { return Next; };
size_t self() const { return Self; };
Edge const *twin() const { return Twin; };
size_t next() const { return Next; };
Edge const *prev() const { return Prev; };
size_t twin() const { return Twin; };
size_t prev() const { return Prev; };
Curve const *constraint_curve() const { return ConstraintCurve; };
......@@ -38,22 +40,29 @@ public:
bool mark() const { return Mark; };
bool operator==(Edge const &e) const {
return (node() == e.node()) && (constraint_curve() == e.constraint_curve()) && (twin()->node() == e.twin()->node());
return (Node == e.Node &&
Self == e.Self &&
Next == e.Next &&
Twin == e.Twin &&
Prev == e.Twin &&
ConstraintCurve == e.ConstraintCurve &&
Orientation == e.Orientation);
};
bool is_constrained() const { return (ConstraintCurve != nullptr); };
bool is_valid() const;
bool is_valid(Mesh const &mesh) const;
bool swap();
bool swap(Mesh const &mesh);
void recursive_mark();
void recursive_mark(Mesh const &mesh);
protected:
size_t Node; //Start of edge
Edge *Next; //In triangle
Edge *Twin; //Adjacent triangle
Edge *Prev; //In triangle
size_t Self; //This triangle
size_t Next; //In triangle
size_t Twin; //Adjacent triangle
size_t Prev; //In triangle
Curve *ConstraintCurve; //==nullptr if unconstrained
bool Orientation; //undefined if unconstrained
......
This diff is collapsed.
......@@ -5,8 +5,8 @@
#include "Point.h"
#include "Edge.h"
#include <fstream>
#include <algorithm>
#include <fstream>
#include <numeric>
enum class LocateTriangleResult {
......@@ -96,6 +96,11 @@ public:
bool is_attached(Edge *&edge_out, Point const &p) const;
void add_edge(Edge *&e) {
e->Self = Edges.size();
Edges.push_back(e);
};
protected:
Contour const *Boundary;
std::vector<Curve const *> Curves;
......
......@@ -8,9 +8,9 @@ bool are_intersecting(Edge const *e0, Edge const *e1, Mesh const &m) {
}
Point const v00 = m.point(e0->base());
Point const v01 = m.point(e0->tip());
Point const v01 = m.point(e0->tip(m));
Point const v10 = m.point(e1->base());
Point const v11 = m.point(e1->tip());
Point const v11 = m.point(e1->tip(m));
double xs0 = (v00.X + v01.X) / 2.0;
double ys0 = (v00.Y + v01.Y) / 2.0;
......@@ -73,8 +73,8 @@ bool in_triangle(Point const &p, Edge const *&e, Mesh const &m) {
double yp = p.Y;
Point const p0 = m.point(e->node());
Point const p1 = m.point(e->next()->node());
Point const p2 = m.point(e->prev()->node());
Point const p1 = m.point(m.edge(e->next())->node());
Point const p2 = m.point(m.edge(e->prev())->node());
double dx0p = p0.X - xp;
double dy0p = p0.Y - yp;
......
......@@ -3,17 +3,18 @@
#define SIGN(x) (double)((x > 0.0) - (x < 0.0))
#include <algorithm>
#include <cfloat>
#include <cmath>
#include <vector>
#include <list>
#include <fstream>
#include <algorithm>
#include <list>
#include <numeric>
#include <cfloat>
#include "Eigen"
#include <vector>
#include <boost/filesystem.hpp>
#include "Eigen"
class Sketch;
// Sketch Parameter
......
......@@ -53,18 +53,18 @@ TEST(Mesh, create__triangle_domain) {
EXPECT_TRUE(v0.x() == m.point(e0->node()).X);
EXPECT_TRUE(v0.y() == m.point(e0->node()).Y);
EXPECT_TRUE(e1 == e0->next());
EXPECT_TRUE(e2 == e0->prev());
EXPECT_TRUE(e1->self() == e0->next());
EXPECT_TRUE(e2->self() == e0->prev());
EXPECT_TRUE(v1.x() == m.point(e1->node()).X);
EXPECT_TRUE(v1.y() == m.point(e1->node()).Y);
EXPECT_TRUE(e2 == e1->next());
EXPECT_TRUE(e0 == e1->prev());
EXPECT_TRUE(e2->self() == e1->next());
EXPECT_TRUE(e0->self() == e1->prev());
EXPECT_TRUE(v2.x() == m.point(e2->node()).X);
EXPECT_TRUE(v2.y() == m.point(e2->node()).Y);
EXPECT_TRUE(e0 == e2->next());
EXPECT_TRUE(e1 == e2->prev());
EXPECT_TRUE(e0->self() == e2->next());
EXPECT_TRUE(e1->self() == e2->prev());
}
{ // Test triangles
......@@ -147,8 +147,8 @@ TEST(Mesh, create__square_domain) {
for (size_t i = 0; i < 5; i++) {
const Edge *e = m.edge(i);
EXPECT_TRUE(e == e->next()->prev());
EXPECT_TRUE(e == e->prev()->next());
EXPECT_TRUE(e->self() == m.edge(e->next())->prev());
EXPECT_TRUE(e->self() == m.edge(e->prev())->next());
}
}
......@@ -215,11 +215,11 @@ TEST(Mesh, create__narrow_diamond_domain) {
const Edge *e = m.edge(5);
if (m.point(e->node()) == m.point(vmap[0])) {
EXPECT_TRUE(m.point(vmap[2]) == m.point(e->next()->node()));
EXPECT_TRUE(m.point(vmap[2]) == m.point(e->twin()->node()));
EXPECT_TRUE(m.point(vmap[2]) == m.point(m.edge(e->next())->node()));
EXPECT_TRUE(m.point(vmap[2]) == m.point(m.edge(e->twin())->node()));
} else if (m.point(e->node()) == m.point(vmap[2])) {
EXPECT_TRUE(m.point(vmap[0]) == m.point(e->next()->node()));
EXPECT_TRUE(m.point(vmap[0]) == m.point(e->twin()->node()));
EXPECT_TRUE(m.point(vmap[0]) == m.point(m.edge(e->next())->node()));
EXPECT_TRUE(m.point(vmap[0]) == m.point(m.edge(e->twin())->node()));
}
}
}
......@@ -298,8 +298,8 @@ TEST(Mesh, create__narrow_rectangle_domain) {
Edge const *e = m.edge(i);
if (m.point(e->node()) == m.point(vmap[2])) {
if (e->twin() != e) {
EXPECT_TRUE(m.point(e->twin()->node()) == v5);
if (e->twin() != e->self()) {
EXPECT_TRUE(m.point(m.edge(e->twin())->node()) == v5);
}
}
}
......@@ -380,16 +380,16 @@ TEST(Mesh, create__horseshoe_domain) {
{ // Test triangles, possibly redundant
for (size_t i = 0; i < m.size_edges(); ++i) {
EXPECT_TRUE(m.edge(i)->next()->prev() == m.edge(i));
EXPECT_TRUE(m.edge(i)->next()->next()->prev()->prev() == m.edge(i));
EXPECT_TRUE(m.edge(i)->next()->next()->next() == m.edge(i));
EXPECT_TRUE(m.edge(m.edge(i)->next())->prev() == m.edge(i)->self());
EXPECT_TRUE(m.edge(m.edge(m.edge(m.edge(i)->next())->next())->prev())->prev() == m.edge(i)->self());
EXPECT_TRUE(m.edge(m.edge(m.edge(i)->next())->next())->next() == m.edge(i)->self());
EXPECT_TRUE(m.edge(i)->prev()->next() == m.edge(i));
EXPECT_TRUE(m.edge(i)->prev()->prev()->next()->next() == m.edge(i));
EXPECT_TRUE(m.edge(i)->prev()->prev()->prev() == m.edge(i));
EXPECT_TRUE(m.edge(m.edge(i)->prev())->next() == m.edge(i)->self());
EXPECT_TRUE(m.edge(m.edge(m.edge(m.edge(i)->prev())->prev())->next())->next() == m.edge(i)->self());
EXPECT_TRUE(m.edge(m.edge(m.edge(i)->prev())->prev())->prev() == m.edge(i)->self());
if (!(m.edge(i)->twin() == m.edge(i))) {
EXPECT_TRUE(m.edge(i)->twin()->node() == m.edge(i)->next()->node());
if ((m.edge(i)->twin() != m.edge(i)->self())) {
EXPECT_TRUE(m.edge(m.edge(i)->twin())->node() == m.edge(m.edge(i)->next())->node());
}
}
}
......@@ -751,15 +751,15 @@ TEST(Mesh, locate_triangle__triangular_domain) {
vp = ve0;
EXPECT_TRUE(mesh.locate_triangle(vp, e) == LocateTriangleResult::Exterior);
EXPECT_TRUE((mesh.point(e->node()) == mesh.point(vmap[0])) && (mesh.point(e->next()->node()) == mesh.point(vmap[1])));
EXPECT_TRUE((mesh.point(e->node()) == mesh.point(vmap[0])) && (mesh.point(mesh.edge(e->next())->node()) == mesh.point(vmap[1])));
vp = ve1;
EXPECT_TRUE(mesh.locate_triangle(vp, e) == LocateTriangleResult::Exterior);
EXPECT_TRUE((mesh.point(e->node()) == mesh.point(vmap[1])) && (mesh.point(e->next()->node()) == mesh.point(vmap[2])));
EXPECT_TRUE((mesh.point(e->node()) == mesh.point(vmap[1])) && (mesh.point(mesh.edge(e->next())->node()) == mesh.point(vmap[2])));
vp = ve2;
EXPECT_TRUE(mesh.locate_triangle(vp, e) == LocateTriangleResult::Exterior);
EXPECT_TRUE((mesh.point(e->node()) == mesh.point(vmap[2])) && (mesh.point(e->next()->node()) == mesh.point(vmap[0])));
EXPECT_TRUE((mesh.point(e->node()) == mesh.point(vmap[2])) && (mesh.point(mesh.edge(e->next())->node()) == mesh.point(vmap[0])));
}
// Corner Cases
......@@ -773,15 +773,15 @@ TEST(Mesh, locate_triangle__triangular_domain) {
vp = ve0;
EXPECT_TRUE(mesh.locate_triangle(vp, e) == LocateTriangleResult::Interior);
EXPECT_TRUE((mesh.point(e->node()) == mesh.point(vmap[0])) && (mesh.point(e->next()->node()) == mesh.point(vmap[1])));
EXPECT_TRUE((mesh.point(e->node()) == mesh.point(vmap[0])) && (mesh.point(mesh.edge(e->next())->node()) == mesh.point(vmap[1])));
vp = ve1;
EXPECT_TRUE(mesh.locate_triangle(vp, e) == LocateTriangleResult::Interior);
EXPECT_TRUE((mesh.point(e->node()) == mesh.point(vmap[1])) && (mesh.point(e->next()->node()) == mesh.point(vmap[2])));
EXPECT_TRUE((mesh.point(e->node()) == mesh.point(vmap[1])) && (mesh.point(mesh.edge(e->next())->node()) == mesh.point(vmap[2])));
vp = ve2;
EXPECT_TRUE(mesh.locate_triangle(vp, e) == LocateTriangleResult::Interior);
EXPECT_TRUE((mesh.point(e->node()) == mesh.point(vmap[2])) && (mesh.point(e->next()->node()) == mesh.point(vmap[0])));
EXPECT_TRUE((mesh.point(e->node()) == mesh.point(vmap[2])) && (mesh.point(mesh.edge(e->next())->node()) == mesh.point(vmap[0])));
}
}
......@@ -839,19 +839,19 @@ TEST(Mesh, locate_triange__square_domain) {
vp = ve0;
EXPECT_TRUE(mesh.locate_triangle(vp, e) == LocateTriangleResult::Exterior);
EXPECT_TRUE((mesh.point(e->node()) == mesh.point(vmap[0])) && (mesh.point(e->next()->node()) == mesh.point(vmap[1])));
EXPECT_TRUE((mesh.point(e->node()) == mesh.point(vmap[0])) && (mesh.point(mesh.edge(e->next())->node()) == mesh.point(vmap[1])));
vp = ve1;
EXPECT_TRUE(mesh.locate_triangle(vp, e) == LocateTriangleResult::Exterior);
EXPECT_TRUE((mesh.point(e->node()) == mesh.point(vmap[1])) && (mesh.point(e->next()->node()) == mesh.point(vmap[2])));
EXPECT_TRUE((mesh.point(e->node()) == mesh.point(vmap[1])) && (mesh.point(mesh.edge(e->next())->node()) == mesh.point(vmap[2])));
vp = ve2;
EXPECT_TRUE(mesh.locate_triangle(vp, e) == LocateTriangleResult::Exterior);
EXPECT_TRUE((mesh.point(e->node()) == mesh.point(vmap[2])) && (mesh.point(e->next()->node()) == mesh.point(vmap[3])));
EXPECT_TRUE((mesh.point(e->node()) == mesh.point(vmap[2])) && (mesh.point(mesh.edge(e->next())->node()) == mesh.point(vmap[3])));
vp = ve3;
EXPECT_TRUE(mesh.locate_triangle(vp, e) == LocateTriangleResult::Exterior);
EXPECT_TRUE((mesh.point(e->node()) == mesh.point(vmap[3])) && (mesh.point(e->next()->node()) == mesh.point(vmap[0])));
EXPECT_TRUE((mesh.point(e->node()) == mesh.point(vmap[3])) && (mesh.point(mesh.edge(e->next())->node()) == mesh.point(vmap[0])));
}
// Exterior Edge Points
......@@ -867,22 +867,22 @@ TEST(Mesh, locate_triange__square_domain) {
vp = ve0;
result = mesh.locate_triangle(vp, e);
EXPECT_TRUE(result == LocateTriangleResult::Interior);
EXPECT_TRUE((mesh.point(e->node()) == mesh.point(vmap[0])) && (mesh.point(e->next()->node()) == mesh.point(vmap[1])));
EXPECT_TRUE((mesh.point(e->node()) == mesh.point(vmap[0])) && (mesh.point(mesh.edge(e->next())->node()) == mesh.point(vmap[1])));
vp = ve1;
result = mesh.locate_triangle(vp, e);
EXPECT_TRUE(result == LocateTriangleResult::Interior);
EXPECT_TRUE((mesh.point(e->node()) == mesh.point(vmap[1])) && (mesh.point(e->next()->node()) == mesh.point(vmap[2])));
EXPECT_TRUE((mesh.point(e->node()) == mesh.point(vmap[1])) && (mesh.point(mesh.edge(e->next())->node()) == mesh.point(vmap[2])));
vp = ve2;
result = mesh.locate_triangle(vp, e);
EXPECT_TRUE(result == LocateTriangleResult::Interior);
EXPECT_TRUE((mesh.point(e->node()) == mesh.point(vmap[2])) && (mesh.point(e->next()->node()) == mesh.point(vmap[3])));
EXPECT_TRUE((mesh.point(e->node()) == mesh.point(vmap[2])) && (mesh.point(mesh.edge(e->next())->node()) == mesh.point(vmap[3])));
vp = ve3;
result = mesh.locate_triangle(vp, e);
EXPECT_TRUE(result == LocateTriangleResult::Interior);
EXPECT_TRUE((mesh.point(e->node()) == mesh.point(vmap[3])) && (mesh.point(e->next()->node()) == mesh.point(vmap[0])));
EXPECT_TRUE((mesh.point(e->node()) == mesh.point(vmap[3])) && (mesh.point(mesh.edge(e->next())->node()) == mesh.point(vmap[0])));
}
Point vie{0.5, 0.5};
......
......@@ -12,29 +12,29 @@ bool edges_are_valid(Mesh &m) {
for (size_t i = 0;i < m.size_edges();++i) {
const Edge *e = m.edge(i);
EXPECT_TRUE(e == e->next()->prev());
EXPECT_TRUE(e == e->prev()->next());
EXPECT_TRUE(e == e->twin()->twin());
EXPECT_TRUE(e->self() == m.edge(e->next())->prev());
EXPECT_TRUE(e->self() == m.edge(e->prev())->next());
EXPECT_TRUE(e->self() == m.edge(e->twin())->twin());
//e->ConstraintCurve == e->Twin->ConstraintCurve and e->Orientation != e->Orientation
if (!(e->twin() == e)) {
EXPECT_TRUE(e->node() == e->twin()->next()->node());
EXPECT_TRUE(e->constraint_curve() == e->twin()->constraint_curve());
if ((e->twin() != e->self())) {
EXPECT_TRUE(e->node() == m.edge(m.edge(e->twin())->next())->node());
EXPECT_TRUE(e->constraint_curve() == m.edge(e->twin())->constraint_curve());
if (e->constraint_curve() != nullptr) {
EXPECT_TRUE(e->orientation() != e->twin()->orientation());
EXPECT_TRUE(e->orientation() != m.edge(e->twin())->orientation());
}
EXPECT_FALSE(e->node() == e->twin()->node());
EXPECT_FALSE(e->node() == m.edge(e->twin())->node());
}
if (e->constraint_curve() != nullptr) {
if (e->orientation()) {
EXPECT_TRUE(m.point(e->base()) == *e->constraint_curve()->start());
EXPECT_TRUE(m.point(e->tip()) == *e->constraint_curve()->end());
EXPECT_TRUE(m.point(e->tip(m)) == *e->constraint_curve()->end());
}
else {
EXPECT_TRUE(m.point(e->base()) == *e->constraint_curve()->end());
EXPECT_TRUE(m.point(e->tip()) == *e->constraint_curve()->start());
EXPECT_TRUE(m.point(e->tip(m)) == *e->constraint_curve()->start());
}
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment