lsst.afw  15.0-21-g91b8abf62
Point.cc
Go to the documentation of this file.
1 /*
2  * LSST Data Management System
3  * Copyright 2008, 2009, 2010 LSST Corporation.
4  *
5  * This product includes software developed by the
6  * LSST Project (http://www.lsst.org/).
7  *
8  * This program is free software: you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation, either version 3 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the LSST License Statement and
19  * the GNU General Public License along with this program. If not,
20  * see <http://www.lsstcorp.org/LegalNotices/>.
21  */
22 
23 #include <cmath>
24 
25 #include "lsst/utils/hashCombine.h"
26 #include "lsst/afw/geom/Point.h"
27 
28 namespace lsst {
29 namespace afw {
30 namespace geom {
31 namespace detail {
32 
33 template <typename T>
34 struct PointSpecialized {};
35 
36 template <>
37 struct PointSpecialized<int> {
38  template <typename U>
39  static int convert(U scalar) {
40  return static_cast<int>(std::floor(scalar + 0.5));
41  }
42 };
43 
44 template <>
45 struct PointSpecialized<double> {
46  template <typename U>
47  static double convert(U scalar) {
48  return static_cast<double>(scalar);
49  }
50 };
51 }
52 
53 template <typename T, int N>
54 template <typename U>
56  for (int n = 0; n < N; ++n) {
57  this->_vector[n] = detail::PointSpecialized<T>::template convert<U>(other[n]);
58  }
59 }
60 
61 template <typename T>
62 template <typename U>
64  for (int n = 0; n < 2; ++n) {
65  this->_vector[n] = detail::PointSpecialized<T>::template convert<U>(other[n]);
66  }
67 }
68 
69 template <typename T>
70 template <typename U>
72  for (int n = 0; n < 3; ++n) {
73  this->_vector[n] = detail::PointSpecialized<T>::template convert<U>(other[n]);
74  }
75 }
76 
77 template <typename T, int N>
80  for (int n = 0; n < N; ++n) r[n] = this->_vector[n] == other[n];
81  return r;
82 }
83 
84 template <typename T, int N>
87  for (int n = 0; n < N; ++n) r[n] = this->_vector[n] != other[n];
88  return r;
89 }
90 
91 template <typename T, int N>
94  for (int n = 0; n < N; ++n) r[n] = this->_vector[n] < other[n];
95  return r;
96 }
97 
98 template <typename T, int N>
101  for (int n = 0; n < N; ++n) r[n] = this->_vector[n] <= other[n];
102  return r;
103 }
104 
105 template <typename T, int N>
108  for (int n = 0; n < N; ++n) r[n] = this->_vector[n] > other[n];
109  return r;
110 }
111 
112 template <typename T, int N>
115  for (int n = 0; n < N; ++n) r[n] = this->_vector[n] >= other[n];
116  return r;
117 }
118 
119 template <typename T, int N>
121  std::size_t result = 0;
122  for (int n = 0; n < N; ++n) result = utils::hashCombine(result, point[n]);
123  return result;
124 }
125 
126 
127 #ifndef DOXYGEN
128 #define INSTANTIATE_TYPE_DIM(TYPE, DIM) \
129  template class PointBase<TYPE, DIM>; \
130  template class Point<TYPE, DIM>; \
131  template std::size_t hash_value(Point<TYPE, DIM> const&);
132 #define INSTANTIATE_DIM(DIM) \
133  INSTANTIATE_TYPE_DIM(int, DIM); \
134  INSTANTIATE_TYPE_DIM(double, DIM); \
135  template Point<int, DIM>::Point(Point<double, DIM> const &); \
136  template Point<double, DIM>::Point(Point<int, DIM> const &);
137 
138 INSTANTIATE_DIM(2);
139 INSTANTIATE_DIM(3);
140 #endif
141 }
142 }
143 } // end lsst::afw::geom
A boolean coordinate.
CoordinateExpr< N > gt(Point< T, N > const &other) const
Definition: Point.cc:106
T floor(T... args)
ItemVariant const * other
Definition: Schema.cc:55
CoordinateExpr< N > ne(Point< T, N > const &other) const
Definition: Point.cc:85
CoordinateExpr< N > eq(Point< T, N > const &other) const
Definition: Point.cc:78
A coordinate class intended to represent absolute positions.
CoordinateExpr< N > ge(Point< T, N > const &other) const
Definition: Point.cc:113
Point(T val=static_cast< T >(0))
Construct a Point with all elements set to the same scalar value.
Definition: Point.h:164
A base class for image defects.
std::unique_ptr< SchemaItem< U > > result
Definition: Schema.cc:194
CoordinateExpr< N > le(Point< T, N > const &other) const
Definition: Point.cc:99
std::size_t hashCombine(std::size_t seed)
CoordinateExpr< N > lt(Point< T, N > const &other) const
Definition: Point.cc:92
std::size_t hash_value(Point< T, N > const &point)
Definition: Point.cc:120