CMS 3D CMS Logo

FKDPoint.h
Go to the documentation of this file.
1 #ifndef COMMONTOOLS_RECOALGOS_FKDPOINT_H
2 #define COMMONTOOLS_RECOALGOS_FKDPOINT_H
3 #include <array>
4 #include <utility>
5 
6 //a K-dimensional point to interface with the FKDTree class
7 template <class TYPE, int numberOfDimensions>
8 class FKDPoint {
9 public:
10  FKDPoint() : theElements(), theId(0) {}
11 
12  FKDPoint(TYPE x, TYPE y, unsigned int id = 0) {
13  static_assert(numberOfDimensions == 2, "FKDPoint number of arguments does not match the number of dimensions");
14 
15  theId = id;
16  theElements[0] = x;
17  theElements[1] = y;
18  }
19 
20  FKDPoint(TYPE x, TYPE y, TYPE z, unsigned int id = 0) {
21  static_assert(numberOfDimensions == 3, "FKDPoint number of arguments does not match the number of dimensions");
22 
23  theId = id;
24  theElements[0] = x;
25  theElements[1] = y;
26  theElements[2] = z;
27  }
28 
29  FKDPoint(TYPE x, TYPE y, TYPE z, TYPE w, unsigned int id = 0) {
30  static_assert(numberOfDimensions == 4, "FKDPoint number of arguments does not match the number of dimensions");
31  theId = id;
32  theElements[0] = x;
33  theElements[1] = y;
34  theElements[2] = z;
35  theElements[3] = w;
36  }
37 
38  // the user should check that i < numberOfDimensions
39  TYPE& operator[](unsigned int const i) { return theElements[i]; }
40 
41  TYPE const& operator[](unsigned int const i) const { return theElements[i]; }
42 
43  void setDimension(unsigned int i, const TYPE& value) { theElements[i] = value; }
44 
45  void setId(const unsigned int id) { theId = id; }
46 
47  unsigned int getId() const { return theId; }
48 
49 private:
50  std::array<TYPE, numberOfDimensions> theElements;
51  unsigned int theId;
52 };
53 
54 #endif
FKDPoint(TYPE x, TYPE y, unsigned int id=0)
Definition: FKDPoint.h:12
T w() const
FKDPoint(TYPE x, TYPE y, TYPE z, TYPE w, unsigned int id=0)
Definition: FKDPoint.h:29
TYPE const & operator[](unsigned int const i) const
Definition: FKDPoint.h:41
unsigned int theId
Definition: FKDPoint.h:51
FKDPoint(TYPE x, TYPE y, TYPE z, unsigned int id=0)
Definition: FKDPoint.h:20
void setDimension(unsigned int i, const TYPE &value)
Definition: FKDPoint.h:43
Definition: value.py:1
unsigned int getId() const
Definition: FKDPoint.h:47
FKDPoint()
Definition: FKDPoint.h:10
TYPE & operator[](unsigned int const i)
Definition: FKDPoint.h:39
void setId(const unsigned int id)
Definition: FKDPoint.h:45
std::array< TYPE, numberOfDimensions > theElements
Definition: FKDPoint.h:50