File size: 1,779 Bytes
fe775b6 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 | // This file is part of libigl, a simple c++ geometry processing library.
//
// Copyright (C) 2013 Alec Jacobson <alecjacobson@gmail.com>
//
// This Source Code Form is subject to the terms of the Mozilla Public License
// v. 2.0. If a copy of the MPL was not distributed with this file, You can
// obtain one at http://mozilla.org/MPL/2.0/.
#ifndef IGL_SORTABLE_ROW_H
#define IGL_SORTABLE_ROW_H
// Simple class to contain a rowvector which allows rowwise sorting and
// reordering
#include <Eigen/Core>
namespace igl
{
// Templates:
// T should be a matrix that implements .size(), and operator(int i)
template <typename T>
class SortableRow
{
public:
T data;
public:
SortableRow():data(){};
SortableRow(const T & data):data(data){};
bool operator<(const SortableRow & that) const
{
// Lexicographical
int minc = (this->data.size() < that.data.size()?
this->data.size() : that.data.size());
// loop over columns
for(int i = 0;i<minc;i++)
{
if(this->data(i) == that.data(i))
{
continue;
}
return this->data(i) < that.data(i);
}
// All characters the same, comes done to length
return this->data.size()<that.data.size();
};
bool operator==(const SortableRow & that) const
{
if(this->data.size() != that.data.size())
{
return false;
}
for(int i = 0;i<this->data.size();i++)
{
if(this->data(i) != that.data(i))
{
return false;
}
}
return true;
};
bool operator!=(const SortableRow & that) const
{
return !(*this == that);
};
};
}
#endif
|