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.
18
#if defined(HAVE_CONFIG_H)
19
# include <carve_config.h>
22
#include <carve/geom.hpp>
23
#include <carve/pointset.hpp>
28
PointSet::PointSet(const std::vector<carve::geom3d::Vector> &points) {
29
vertices.resize(points.size());
30
for (size_t i = 0; i < points.size(); ++i) {
31
vertices[i].v = points[i];
33
aabb.fit(points.begin(), points.end());
36
void PointSet::sortVertices(const carve::geom3d::Vector &axis) {
37
std::vector<std::pair<double, size_t> > temp;
38
temp.reserve(vertices.size());
39
for (size_t i = 0; i < vertices.size(); ++i) {
40
temp.push_back(std::make_pair(dot(axis, vertices[i].v), i));
42
std::sort(temp.begin(), temp.end());
44
std::vector<Vertex> vnew;
45
vnew.reserve(vertices.size());
47
// std::vector<int> revmap;
48
// revmap.resize(vertices.size());
50
for (size_t i = 0; i < vertices.size(); ++i) {
51
vnew.push_back(vertices[temp[i].second]);
52
// revmap[temp[i].second] = i;