2
// Copyright (C) 2006-2011 Tobias Sargeant (tobias.sargeant@gmail.com).
3
// All rights reserved.
5
// This file is part of the Carve CSG Library (http://carve-csg.com/)
7
// This file may be used under the terms of the GNU General Public
8
// License version 2.0 as published by the Free Software Foundation
9
// and appearing in the file LICENSE.GPL2 included in the packaging of
12
// This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
13
// INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
14
// A PARTICULAR PURPOSE.
21
template<unsigned ndim>
22
inline void swap(carve::poly::Face<ndim> &a, carve::poly::Face<ndim> &b) {
29
template<unsigned ndim>
30
void Face<ndim>::swap(Face<ndim> &other) {
31
std::swap(vertices, other.vertices);
32
std::swap(edges, other.edges);
33
std::swap(owner, other.owner);
34
std::swap(aabb, other.aabb);
35
std::swap(plane_eqn, other.plane_eqn);
36
std::swap(manifold_id, other.manifold_id);
37
std::swap(group_id, other.group_id);
38
std::swap(project, other.project);
39
std::swap(unproject, other.unproject);
42
template<unsigned ndim>
43
template<typename iter_t>
44
Face<ndim> *Face<ndim>::init(const Face<ndim> *base, iter_t vbegin, iter_t vend, bool flipped) {
45
vertices.reserve(std::distance(vbegin, vend));
48
std::reverse_copy(vbegin, vend, std::back_inserter(vertices));
49
plane_eqn = -base->plane_eqn;
51
std::copy(vbegin, vend, std::back_inserter(vertices));
52
plane_eqn = base->plane_eqn;
56
edges.resize(nVertices(), NULL);
58
aabb.fit(vertices.begin(), vertices.end(), vec_adapt_vertex_ptr());
61
int da = carve::geom::largestAxis(plane_eqn.N);
63
project = getProjector(plane_eqn.N.v[da] > 0, da);
64
unproject = getUnprojector(plane_eqn.N.v[da] > 0, da);
69
template<unsigned ndim>
70
template<typename iter_t>
71
Face<ndim> *Face<ndim>::create(iter_t vbegin, iter_t vend, bool flipped) const {
72
return (new Face)->init(this, vbegin, vend, flipped);
75
template<unsigned ndim>
76
Face<ndim> *Face<ndim>::create(const std::vector<const vertex_t *> &_vertices, bool flipped) const {
77
return (new Face)->init(this, _vertices.begin(), _vertices.end(), flipped);
80
template<unsigned ndim>
81
Face<ndim> *Face<ndim>::clone(bool flipped) const {
82
return (new Face)->init(this, vertices, flipped);
85
template<unsigned ndim>
86
void Face<ndim>::getVertexLoop(std::vector<const vertex_t *> &loop) const {
87
loop.resize(nVertices(), NULL);
88
std::copy(vbegin(), vend(), loop.begin());
91
template<unsigned ndim>
92
const typename Face<ndim>::edge_t *&Face<ndim>::edge(size_t idx) {
96
template<unsigned ndim>
97
const typename Face<ndim>::edge_t *Face<ndim>::edge(size_t idx) const {
101
template<unsigned ndim>
102
size_t Face<ndim>::nEdges() const {
106
template<unsigned ndim>
107
const typename Face<ndim>::vertex_t *&Face<ndim>::vertex(size_t idx) {
108
return vertices[idx];
111
template<unsigned ndim>
112
const typename Face<ndim>::vertex_t *Face<ndim>::vertex(size_t idx) const {
113
return vertices[idx];
116
template<unsigned ndim>
117
size_t Face<ndim>::nVertices() const {
118
return vertices.size();
121
template<unsigned ndim>
122
typename Face<ndim>::vector_t Face<ndim>::centroid() const {
124
carve::geom::centroid(vertices.begin(), vertices.end(), vec_adapt_vertex_ptr(), c);
128
template<unsigned ndim>
129
std::vector<carve::geom::vector<2> > Face<ndim>::projectedVertices() const {
130
p2_adapt_project<ndim> proj = projector();
131
std::vector<carve::geom::vector<2> > result;
132
result.reserve(nVertices());
133
for (size_t i = 0; i < nVertices(); ++i) {
134
result.push_back(proj(vertex(i)->v));