libigl v2.5.0
Loading...
Searching...
No Matches
IndexComparison.h
Go to the documentation of this file.
1// This file is part of libigl, a simple c++ geometry processing library.
2//
3// Copyright (C) 2013 Alec Jacobson <alecjacobson@gmail.com>
4//
5// This Source Code Form is subject to the terms of the Mozilla Public License
6// v. 2.0. If a copy of the MPL was not distributed with this file, You can
7// obtain one at http://mozilla.org/MPL/2.0/.
8#ifndef IGL_INDEXCOMPARISON_H
9#define IGL_INDEXCOMPARISON_H
10namespace igl{
13 template<class T> struct IndexLessThan
14 {
15 IndexLessThan(const T arr) : arr(arr) {}
16 bool operator()(const size_t a, const size_t b) const
17 {
18 return arr[a] < arr[b];
19 }
20 const T arr;
21 };
22
24 template<class T> struct IndexEquals
25 {
26 IndexEquals(const T arr) : arr(arr) {}
27 bool operator()(const size_t a, const size_t b) const
28 {
29 return arr[a] == arr[b];
30 }
31 const T arr;
32 };
33
35 template<class T> struct IndexVectorLessThan
36 {
37 IndexVectorLessThan(const T & vec) : vec ( vec) {}
38 bool operator()(const size_t a, const size_t b) const
39 {
40 return vec(a) < vec(b);
41 }
42 const T & vec;
43 };
44
46 template<class T> struct IndexDimLessThan
47 {
48 IndexDimLessThan(const T & mat,const int & dim, const int & j) :
49 mat(mat),
50 dim(dim),
51 j(j)
52 {}
53 bool operator()(const size_t a, const size_t b) const
54 {
55 if(dim == 1)
56 {
57 return mat(a,j) < mat(b,j);
58 }else
59 {
60 return mat(j,a) < mat(j,b);
61 }
62 }
63 const T & mat;
64 const int & dim;
65 const int & j;
66 };
67
69 template<class T> struct IndexRowLessThan
70 {
71 IndexRowLessThan(const T & mat) : mat ( mat) {}
72 bool operator()(const size_t a, const size_t b) const
73 {
74 const int cols = mat.cols();
75 // Lexicographical order
76 for(int j = 0;j<cols;j++)
77 {
78 if(mat(a,j) > mat(b,j))
79 {
80 return false;
81 } else if(mat(a,j) < mat(b,j))
82 {
83 return true;
84 }
85 }
86 // equality is false
87 return false;
88 }
89 const T & mat;
90 };
91
93 template<class T> struct IndexRowEquals
94 {
95 IndexRowEquals(const T & mat) : mat ( mat) {}
96 bool operator()(const size_t a, const size_t b) const
97 {
98 const int cols = mat.cols();
99 // Lexicographical order
100 for(int j = 0;j<cols;j++)
101 {
102 if(mat(a,j) != mat(b,j))
103 {
104 return false;
105 }
106 }
107 return true;
108 }
109 const T & mat;
110 };
111
112}
113
114#endif
Definition AABB.h:17
Comparison struct for use with functions like std::sort.
Definition IndexComparison.h:47
const int & j
Definition IndexComparison.h:65
bool operator()(const size_t a, const size_t b) const
Definition IndexComparison.h:53
const T & mat
Definition IndexComparison.h:63
IndexDimLessThan(const T &mat, const int &dim, const int &j)
Definition IndexComparison.h:48
const int & dim
Definition IndexComparison.h:64
Comparison struct used by unique.
Definition IndexComparison.h:25
IndexEquals(const T arr)
Definition IndexComparison.h:26
bool operator()(const size_t a, const size_t b) const
Definition IndexComparison.h:27
const T arr
Definition IndexComparison.h:31
Comparison struct used by sort http://bytes.com/topic/c/answers/132045-sort-get-index.
Definition IndexComparison.h:14
bool operator()(const size_t a, const size_t b) const
Definition IndexComparison.h:16
const T arr
Definition IndexComparison.h:20
IndexLessThan(const T arr)
Definition IndexComparison.h:15
Comparison struct for use with functions like std::sort.
Definition IndexComparison.h:94
const T & mat
Definition IndexComparison.h:109
bool operator()(const size_t a, const size_t b) const
Definition IndexComparison.h:96
IndexRowEquals(const T &mat)
Definition IndexComparison.h:95
Comparison struct For use with functions like std::sort.
Definition IndexComparison.h:70
bool operator()(const size_t a, const size_t b) const
Definition IndexComparison.h:72
const T & mat
Definition IndexComparison.h:89
IndexRowLessThan(const T &mat)
Definition IndexComparison.h:71
Comparison struct for vectors for use with functions like std::sort.
Definition IndexComparison.h:36
bool operator()(const size_t a, const size_t b) const
Definition IndexComparison.h:38
const T & vec
Definition IndexComparison.h:42
IndexVectorLessThan(const T &vec)
Definition IndexComparison.h:37