lsst.geom  16.0-11-g017a494
Extent.cc
Go to the documentation of this file.
1 /*
2  * Developed for the LSST Data Management System.
3  * This product includes software developed by the LSST Project
4  * (https://www.lsst.org).
5  * See the COPYRIGHT file at the top-level directory of this distribution
6  * for details of code ownership.
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 GNU General Public License
19  * along with this program. If not, see <https://www.gnu.org/licenses/>.
20  */
21 
23 #include "lsst/geom/Point.h"
24 #include "lsst/geom/Extent.h"
25 
26 namespace lsst {
27 namespace geom {
28 
29 template <typename T, int N>
30 Extent<T, N>::Extent(Point<T, N> const &other) noexcept(Super::IS_ELEMENT_NOTHROW_COPYABLE)
31  : Super(other.asEigen()) {}
32 
33 // The following two template specializations raise Doxygen warnings and produce no documenation.
34 // This is a known Doxygen bug: <https://bugzilla.gnome.org/show_bug.cgi?id=406027>
36 template <typename T>
37 Extent<T, 2>::Extent(Point<T, 2> const &other) noexcept(Super::IS_ELEMENT_NOTHROW_COPYABLE)
38  : Super(other.asEigen()) {}
39 
40 template <typename T>
41 Extent<T, 3>::Extent(Point<T, 3> const &other) noexcept(Super::IS_ELEMENT_NOTHROW_COPYABLE)
42  : Super(other.asEigen()) {}
44 
45 template <typename T, int N>
46 CoordinateExpr<N> ExtentBase<T, N>::eq(Extent<T, N> const &other) const noexcept {
48  for (int n = 0; n < N; ++n) r[n] = this->_vector[n] == other[n];
49  return r;
50 }
51 
52 template <typename T, int N>
53 CoordinateExpr<N> ExtentBase<T, N>::ne(Extent<T, N> const &other) const noexcept {
55  for (int n = 0; n < N; ++n) r[n] = this->_vector[n] != other[n];
56  return r;
57 }
58 
59 template <typename T, int N>
60 CoordinateExpr<N> ExtentBase<T, N>::lt(Extent<T, N> const &other) const noexcept {
62  for (int n = 0; n < N; ++n) r[n] = this->_vector[n] < other[n];
63  return r;
64 }
65 
66 template <typename T, int N>
67 CoordinateExpr<N> ExtentBase<T, N>::le(Extent<T, N> const &other) const noexcept {
69  for (int n = 0; n < N; ++n) r[n] = this->_vector[n] <= other[n];
70  return r;
71 }
72 
73 template <typename T, int N>
74 CoordinateExpr<N> ExtentBase<T, N>::gt(Extent<T, N> const &other) const noexcept {
76  for (int n = 0; n < N; ++n) r[n] = this->_vector[n] > other[n];
77  return r;
78 }
79 
80 template <typename T, int N>
81 CoordinateExpr<N> ExtentBase<T, N>::ge(Extent<T, N> const &other) const noexcept {
83  for (int n = 0; n < N; ++n) r[n] = this->_vector[n] >= other[n];
84  return r;
85 }
86 
87 template <typename T, int N>
88 Point<T, N> ExtentBase<T, N>::asPoint() const noexcept(Super::IS_ELEMENT_NOTHROW_COPYABLE) {
89  return Point<T, N>(static_cast<Extent<T, N> const &>(*this));
90 }
91 
92 template <typename T, int N>
94  noexcept(Super::IS_ELEMENT_NOTHROW_COPYABLE) {
95  return Point<T, N>(this->_vector + other.asEigen());
96 }
97 
98 template <int N>
99 Extent<int, N> truncate(Extent<double, N> const &input) noexcept {
100  Extent<int, N> result;
101  for (int i = 0; i < N; ++i) {
102  result[i] = static_cast<int>(input[i]);
103  }
104  return result;
105 }
106 
107 template <int N>
108 Extent<int, N> floor(Extent<double, N> const &input) noexcept {
109  Extent<int, N> result;
110  for (int i = 0; i < N; ++i) {
111  result[i] = std::floor(input[i]);
112  }
113  return result;
114 }
115 
116 template <int N>
117 Extent<int, N> ceil(Extent<double, N> const &input) noexcept {
118  Extent<int, N> result;
119  for (int i = 0; i < N; ++i) {
120  result[i] = std::ceil(input[i]);
121  }
122  return result;
123 }
124 
125 #ifndef DOXYGEN
126 
127 template class ExtentBase<int, 2>;
128 template class ExtentBase<int, 3>;
129 template class ExtentBase<double, 2>;
130 template class ExtentBase<double, 3>;
131 template class Extent<int, 2>;
132 template class Extent<int, 3>;
133 template class Extent<double, 2>;
134 template class Extent<double, 3>;
135 template Extent<double, 2>::Extent(Extent<int, 2> const &);
136 template Extent<double, 3>::Extent(Extent<int, 3> const &);
137 template Extent<double, 2>::Extent(Point<int, 2> const &);
138 template Extent<double, 3>::Extent(Point<int, 3> const &);
139 
140 template Extent<int, 2> truncate(Extent<double, 2> const &);
141 template Extent<int, 3> truncate(Extent<double, 3> const &);
142 template Extent<int, 2> floor(Extent<double, 2> const &);
143 template Extent<int, 3> floor(Extent<double, 3> const &);
144 template Extent<int, 2> ceil(Extent<double, 2> const &);
145 template Extent<int, 3> ceil(Extent<double, 3> const &);
146 
147 #endif // !DOXYGEN
148 
149 } // namespace geom
150 } // namespace lsst
Extent< int, N > ceil(Extent< double, N > const &input) noexcept
Return the component-wise ceil (round towards more positive).
Definition: Extent.cc:117
CoordinateExpr< N > ne(Extent< T, N > const &other) const noexcept
Definition: Extent.cc:53
A coordinate class intended to represent absolute positions (2-d specialization). ...
Definition: Point.h:211
T ceil(T... args)
A coordinate class intended to represent absolute positions (3-d specialization). ...
Definition: Point.h:268
A coordinate class intended to represent absolute positions.
CoordinateExpr< N > le(Extent< T, N > const &other) const noexcept
Definition: Extent.cc:67
Point< T, N > asPoint() const noexcept(Super::IS_ELEMENT_NOTHROW_COPYABLE)
Cast this object to an Extent of the same numeric type and dimensionality.
Definition: Extent.cc:88
T floor(T... args)
Extent(T val=static_cast< T >(0)) noexcept(Super::IS_ELEMENT_NOTHROW_COPYABLE)
Construct an Extent with all elements set to the same scalar value.
Definition: Extent.h:217
Extent< T, N > operator+() const noexcept(Super::IS_ELEMENT_NOTHROW_COPYABLE)
Definition: Extent.h:146
Extent< int, N > truncate(Extent< double, N > const &input) noexcept
Return the component-wise truncation (round towards zero).
Definition: Extent.cc:99
CoordinateExpr< N > lt(Extent< T, N > const &other) const noexcept
Definition: Extent.cc:60
A boolean coordinate.
CoordinateExpr< N > gt(Extent< T, N > const &other) const noexcept
Definition: Extent.cc:74
A coordinate class intended to represent offsets and dimensions.
Eigen::Vector3d asEigen(sphgeom::Vector3d const &vector) noexcept
Definition: sphgeomUtils.h:36
CoordinateExpr< N > eq(Extent< T, N > const &other) const noexcept
Definition: Extent.cc:46
CoordinateExpr< N > ge(Extent< T, N > const &other) const noexcept
Definition: Extent.cc:81
EigenVector const & asEigen() const noexcept(IS_ELEMENT_NOTHROW_COPYABLE)
Return a fixed-size Eigen representation of the coordinate object.
Extent< int, N > floor(Extent< double, N > const &input) noexcept
Return the component-wise floor (round towards more negative).
Definition: Extent.cc:108