qpolytri.h
来自「算断裂的」· C头文件 代码 · 共 143 行
H
143 行
// ------------------------------------------------------------------// qpolytri.h//// This file contains useful classes for polytri.cpp, the routine// for triangulating a polygon.// ------------------------------------------------------------------// Author: Stephen A. Vavasis// Copyright (c) 1999 by Cornell University. All rights reserved.// // See the accompanying file 'Copyright' for authorship information,// the terms of the license governing this software, and disclaimers// concerning this software.// ------------------------------------------------------------------// This file is part of the QMG software. // Version 2.0 of QMG, release date September 3, 1999.// ------------------------------------------------------------------#ifndef QPOLYTRI_H#define QPOLYTRI_H#include "qnamesp.h"namespace QMG { namespace PolyTri { using namespace QMG; typedef int VertexIndex; // An edge is a pair of vertex indices. class Edge { private: VertexIndex ep1_, ep2_; public: Edge() { } Edge(VertexIndex ep1, VertexIndex ep2) : ep1_(ep1), ep2_(ep2) { } Edge(const Edge& other) : ep1_(other.ep1_), ep2_(other.ep2_) { } ~Edge() { } const Edge& operator=(const Edge& other) { ep1_ = other.ep1_; ep2_ = other.ep2_; return *this; } Edge sort() const { return (ep1_ < ep2_)? Edge(ep1_,ep2_) : Edge(ep2_,ep1_); } Edge reverse() const { return Edge(ep2_, ep1_); } VertexIndex endpoint(int j) const { return (j == 0)? ep1_ : ep2_; } bool operator==(const Edge& other) const { return ep1_ == other.ep1_ && ep2_ == other.ep2_; } bool operator<(const Edge& other) const { return ep1_ < other.ep1_ || (ep1_ == other.ep1_ && ep2_ < other.ep2_); } }; // A vertex list is a matrix of vertex coordinates. class VertexList { private: vector<Real> coords_; void operator=(const VertexList&) { } VertexList(const VertexList&) { } public: Real coord(VertexIndex i, int d) const { return coords_[i * 2 + d]; } VertexIndex add_vertex(Real a, Real b) { coords_.push_back(a); coords_.push_back(b); return (coords_.size() - 2) / 2; } int size() const { return coords_.size() / 2; } void resize(int newsz) { coords_.resize(newsz * 2); } VertexList() { } ~VertexList() { } }; // A triangulation is a list of triples of // vertex indices. class Triangulation { private: vector<VertexIndex>* data_; void operator=(const Triangulation&) { } public: int numtri() const { return (data_)? ((data_ -> size()) / 3) : 0; } VertexIndex tri_vertex(int k, int d) const { return (*data_)[k * 3 + d]; } Triangulation() : data_(0) { } ~Triangulation() { if (data_) delete data_; } // Destructive copy semantics private: class Triangulation_Returnval { private: friend class Triangulation; Triangulation& t_; Triangulation_Returnval(Triangulation& t, int) : t_(t) { } }; public: Triangulation(Triangulation& other) : data_(other.data_) { other.data_ = 0; } Triangulation(const Triangulation_Returnval& tv) : data_(tv.t_.data_) { tv.t_.data_ = 0; } operator Triangulation_Returnval() { return Triangulation_Returnval(*this,0); } void add_triangle(VertexIndex a, VertexIndex b, VertexIndex c) { if (!data_) { data_ = new vector<VertexIndex>; } data_ -> push_back(a); data_ -> push_back(b); data_ -> push_back(c); } }; }}#endif
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?