// Begin License: // Copyright (C) 2006-2008 Tobias Sargeant (tobias.sargeant@gmail.com). // All rights reserved. // // This file is part of the Carve CSG Library (http://carve-csg.com/) // // This file may be used under the terms of the GNU General Public // License version 2.0 as published by the Free Software Foundation // and appearing in the file LICENSE.GPL2 included in the packaging of // this file. // // This file is provided "AS IS" with NO WARRANTY OF ANY KIND, // INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR // A PARTICULAR PURPOSE. // End: #pragma once namespace std { template inline void swap(carve::poly::Face &a, carve::poly::Face &b) { a.swap(b); } } namespace carve { namespace poly { template void Face::swap(Face &other) { std::swap(vertices, other.vertices); std::swap(edges, other.edges); std::swap(owner, other.owner); std::swap(aabb, other.aabb); std::swap(plane_eqn, other.plane_eqn); std::swap(manifold_id, other.manifold_id); std::swap(group_id, other.group_id); std::swap(project, other.project); std::swap(unproject, other.unproject); } template template Face *Face::init(const Face *base, iter_t vbegin, iter_t vend, bool flipped) { vertices.reserve(std::distance(vbegin, vend)); if (flipped) { std::reverse_copy(vbegin, vend, std::back_inserter(vertices)); plane_eqn = -base->plane_eqn; } else { std::copy(vbegin, vend, std::back_inserter(vertices)); plane_eqn = base->plane_eqn; } edges.clear(); edges.resize(nVertices(), NULL); aabb.fit(vertices.begin(), vertices.end(), vec_adapt_vertex_ptr()); untag(); int da = carve::geom::largestAxis(plane_eqn.N); project = getProjector(plane_eqn.N.v[da] > 0, da); unproject = getUnprojector(plane_eqn.N.v[da] > 0, da); return this; } template template Face *Face::create(iter_t vbegin, iter_t vend, bool flipped) const { return (new Face)->init(this, vbegin, vend, flipped); } template Face *Face::create(const std::vector &_vertices, bool flipped) const { return (new Face)->init(this, _vertices.begin(), _vertices.end(), flipped); } template Face *Face::clone(bool flipped) const { return (new Face)->init(this, vertices, flipped); } template void Face::getVertexLoop(std::vector &loop) const { loop.resize(nVertices(), NULL); std::copy(vbegin(), vend(), loop.begin()); } template const typename Face::edge_t *&Face::edge(size_t idx) { return edges[idx]; } template const typename Face::edge_t *Face::edge(size_t idx) const { return edges[idx]; } template size_t Face::nEdges() const { return edges.size(); } template const typename Face::vertex_t *&Face::vertex(size_t idx) { return vertices[idx]; } template const typename Face::vertex_t *Face::vertex(size_t idx) const { return vertices[idx]; } template size_t Face::nVertices() const { return vertices.size(); } template typename Face::vector_t Face::centroid() const { vector_t c; carve::geom::centroid(vertices.begin(), vertices.end(), vec_adapt_vertex_ptr(), c); return c; } template std::vector > Face::projectedVertices() const { p2_adapt_project proj = projector(); std::vector > result; result.reserve(nVertices()); for (size_t i = 0; i < nVertices(); ++i) { result.push_back(proj(vertex(i)->v)); } return result; } } }