Commit 51a5df42 authored by Philip Trettner's avatar Philip Trettner
Browse files

working on correctness

parent 0ab6420c
......@@ -180,6 +180,10 @@ void Mesh::assert_consistency() const
assert(h.vertex_from().is_valid());
// face can be invalid
// DEBUG
if (h.next().prev() != h)
print_debug(*this);
assert(h.next().prev() == h);
assert(h.prev().next() == h);
assert(h.opposite().opposite() == h);
......
......@@ -305,12 +305,12 @@ private:
struct halfedge_info &halfedge(edge_index i, int h)
{
assert(i.is_valid());
return mHalfedges[(i.value >> 1) + h];
return mHalfedges[(i.value << 1) + h];
}
struct halfedge_info const &halfedge(edge_index i, int h) const
{
assert(i.is_valid());
return mHalfedges[(i.value >> 1) + h];
return mHalfedges[(i.value << 1) + h];
}
// internal state
......@@ -416,7 +416,6 @@ inline face_index Mesh::add_face(const halfedge_handle *half_loop, size_t vcnt)
inline face_index Mesh::add_face(const halfedge_index *half_loop, size_t vcnt)
{
assert(vcnt >= 3 && "no support for less-than-triangular faces");
/// TODO: attributes
auto fidx = face_index((int)mFaces.size());
......@@ -576,9 +575,9 @@ inline void Mesh::make_adjacent(halfedge_index he_in, halfedge_index he_out)
auto &g = halfedge(he_g);
auto he_h = g.next_halfedge;
auto &h = halfedge(he_d);
auto &h = halfedge(he_h);
// attrerly rewire
// properly rewire
in.next_halfedge = he_out;
out.prev_halfedge = he_in;
......
#pragma once
#include <iostream>
namespace polymesh
{
class Mesh;
......@@ -115,9 +117,10 @@ struct halfedge_index
struct face_handle
{
Mesh const* mesh;
Mesh const* mesh = nullptr;
face_index idx;
face_handle() = default;
face_handle(Mesh const* mesh, face_index idx) : mesh(mesh), idx(idx) {}
bool operator==(face_index const& rhs) const { return idx == rhs; }
......@@ -147,9 +150,10 @@ struct face_handle
struct vertex_handle
{
Mesh const* mesh;
Mesh const* mesh = nullptr;
vertex_index idx;
vertex_handle() = default;
vertex_handle(Mesh const* mesh, vertex_index idx) : mesh(mesh), idx(idx) {}
bool operator==(vertex_index const& rhs) const { return idx == rhs; }
......@@ -184,9 +188,10 @@ struct vertex_handle
struct edge_handle
{
Mesh const* mesh;
Mesh const* mesh = nullptr;
edge_index idx;
edge_handle() = default;
edge_handle(Mesh const* mesh, edge_index idx) : mesh(mesh), idx(idx) {}
bool operator==(edge_index const& rhs) const { return idx == rhs; }
......@@ -216,9 +221,10 @@ struct edge_handle
struct halfedge_handle
{
Mesh const* mesh;
Mesh const* mesh = nullptr;
halfedge_index idx;
halfedge_handle() = default;
halfedge_handle(Mesh const* mesh, halfedge_index idx) : mesh(mesh), idx(idx) {}
bool operator==(halfedge_index const& rhs) const { return idx == rhs; }
......@@ -246,4 +252,56 @@ struct halfedge_handle
halfedge_handle opposite() const;
face_handle opposite_face() const; ///< invalid if opposite boundary
};
/// ======== IMPLEMENTATION ========
inline std::ostream& operator<<(std::ostream& out, vertex_index v)
{
out << "vertex " << v.value;
if (v.is_invalid())
out << " (invalid)";
return out;
}
inline std::ostream& operator<<(std::ostream& out, face_index f)
{
out << "face " << f.value;
if (f.is_invalid())
out << " (invalid)";
return out;
}
inline std::ostream& operator<<(std::ostream& out, edge_index e)
{
out << "edge " << e.value;
if (e.is_invalid())
out << " (invalid)";
return out;
}
inline std::ostream& operator<<(std::ostream& out, halfedge_index h)
{
out << "half-edge " << h.value;
if (h.is_invalid())
out << " (invalid)";
return out;
}
inline std::ostream& operator<<(std::ostream& out, vertex_handle v)
{
out << v.idx;
return out;
}
inline std::ostream& operator<<(std::ostream& out, face_handle f)
{
out << f.idx;
return out;
}
inline std::ostream& operator<<(std::ostream& out, edge_handle e)
{
out << e.idx;
return out;
}
inline std::ostream& operator<<(std::ostream& out, halfedge_handle h)
{
out << h.idx;
return out;
}
}
......@@ -7,7 +7,7 @@
namespace polymesh
{
void print_debug(Mesh const& m)
inline void print_debug(Mesh const& m)
{
using namespace std;
......@@ -38,7 +38,7 @@ void print_debug(Mesh const& m)
cout << endl;
}
void write_dot_graph(Mesh const& m, std::ostream& out)
inline void write_dot_graph(Mesh const& m, std::ostream& out)
{
out << "strict digraph {\n";
for (auto v : m.vertices())
......@@ -51,7 +51,8 @@ void write_dot_graph(Mesh const& m, std::ostream& out)
}
out << "}\n";
}
void write_dot_graph(Mesh const& m, std::string const& filename)
inline void write_dot_graph(Mesh const& m, std::string const& filename)
{
std::ofstream file(filename);
write_dot_graph(m, file);
......
Supports Markdown
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