Skip to content

Commit 22f6bb6

Browse files
committed
Point can be cast to different Scalar type.
1 parent 8b36cc5 commit 22f6bb6

File tree

1 file changed

+11
-0
lines changed
  • examples/pico_toolshed/pico_toolshed

1 file changed

+11
-0
lines changed

examples/pico_toolshed/pico_toolshed/point.hpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
//! \tparam Dim_ The dimension of the space in which the point resides.
1111
template <typename Scalar_, int Dim_>
1212
class Point {
13+
static_assert(Dim_ > 0, "INVALID_SPATIAL_DIMENSION_POINT");
14+
1315
public:
1416
using ScalarType = Scalar_;
1517
static constexpr int Dim = Dim_;
@@ -23,6 +25,15 @@ class Point {
2325
}
2426
}
2527

28+
template <typename OtherScalarType>
29+
inline Point<OtherScalarType, Dim> Cast() const {
30+
Point<OtherScalarType, Dim> other;
31+
for (int i = 0; i < Dim; ++i) {
32+
other.data[i] = static_cast<OtherScalarType>(data[i]);
33+
}
34+
return other;
35+
}
36+
2637
ScalarType data[Dim];
2738
};
2839

0 commit comments

Comments
 (0)