Improvement: Remove strong types from t8_3D_vec and t8_3D_point#2139
Improvement: Remove strong types from t8_3D_vec and t8_3D_point#2139lenaploetzke wants to merge 9 commits intomainfrom
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #2139 +/- ##
==========================================
- Coverage 77.95% 77.89% -0.06%
==========================================
Files 113 112 -1
Lines 19089 19021 -68
==========================================
- Hits 14881 14817 -64
+ Misses 4208 4204 -4 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
src/t8_types/t8_vec.hxx
Outdated
| /** Type alias for a 2D point. | ||
| */ | ||
| using t8_2D_vec = t8_vec<2>; | ||
| typedef std::array<double, 2> t8_2D_point; |
There was a problem hiding this comment.
What you you think, do we still need the differentiation between vectors and points or is a general dimensional type sufficient?
There was a problem hiding this comment.
We could keep the vector name, since a vector is not only a vector in a geometric sense, but also a one-dimensional tensor.
There was a problem hiding this comment.
No i also think that one dimensional object is enough. And yes i agree that we can just name it t8_vec and not t8_dimensional. I just defined both because we have so many usages of t8_3D_point in t8code...
src/t8_types/t8_vec.hxx
Outdated
| template <typename T> | ||
| concept T8ContainerdoubleType = requires (T t) { |
There was a problem hiding this comment.
| template <typename T> | |
| concept T8ContainerdoubleType = requires (T t) { | |
| template <typename TType> | |
| concept T8ContainerDoubleType = requires (TType type) { |
There was a problem hiding this comment.
Renamed to T8ContainerType and deleted the other one
| */ | ||
| template <typename T, std::size_t Expected = static_cast<std::size_t> (-1)> | ||
| concept T8VecType = requires { typename std::remove_cvref_t<T>::tag; } && requires { | ||
| concept T8ContainerType = requires (TType t) { |
There was a problem hiding this comment.
Since we use cpp20 now, we can also use ranges for this :)
This is more open and checks everything automatically
template <typename TType>
concept T8Range =
std::ranges::input_range<TType> &&
std::convertible_to<std::ranges::range_value_t<TType>, double>;
| static inline void | ||
| t8_cross_3D (const TVecX &vec_x, const TVecY &vec_y, TVecCross &cross) | ||
| { | ||
| T8_ASSERT ((vec_x.size () == 3) && (vec_y.size () == 3)); |
There was a problem hiding this comment.
Not all containers have a function named size (). Ranges is the container agnostic way.
cross needs to be big enough for the output values.
| T8_ASSERT ((vec_x.size () == 3) && (vec_y.size () == 3)); | |
| T8_ASSERT ((std::ranges::distance(vec_x) >= 3) && (std::ranges::distance(vec_y) >= 3) && (std::ranges::distance(cross) >= 3)); |
| template <T8ContainerType TVecX, T8ContainerType TVecY, T8ContainerType TVecDiff> | ||
| constexpr void | ||
| t8_diff (const TVecX &vec_x, const TVecY &vec_y, TVecDiff &diff) | ||
| { |
| static inline void | ||
| t8_normal_of_tri (const TVecP1 &p1, const TVecP2 &p2, const TVecP3 &p3, TVecNormal &normal) | ||
| { | ||
| T8_ASSERT ((p1.size () == 3) && (p2.size () == 3) && (p3.size () == 3)); |
There was a problem hiding this comment.
| T8_ASSERT ((p1.size () == 3) && (p2.size () == 3) && (p3.size () == 3)); | |
| T8_ASSERT ((std::ranges::distance(p1) >= 3) && (std::ranges::distance(p2) >= 3) && (std::ranges::distance(p3) >= 3)); |
| static inline void | ||
| t8_orthogonal_tripod (const TVecV1 &v1, TVecV2 &v2, TVecV3 &v3) | ||
| { | ||
| T8_ASSERT (v1.size () == 3); |
There was a problem hiding this comment.
v2 and v3 still need to be big enough to hold the output values.
| T8_ASSERT (v1.size () == 3); | |
| T8_ASSERT ((std::ranges::distance(v1) >= 3) && (std::ranges::distance(v2) >= 3) && (std::ranges::distance(v3) >= 3)); |
| static inline double | ||
| t8_cross_2D (const TVecX &vec_x, const TVecY &vec_y) | ||
| { | ||
| T8_ASSERT ((vec_x.size () == 2) && (vec_y.size () == 2)); |
There was a problem hiding this comment.
Not all containers have a function named size (). Ranges is the container agnostic way.
Also it would be nice to check if the containers have at least the right size. In t8code we also sometimes use 3D containers to store 2D values and if this assertion is too limited, we cannot use this function.
| T8_ASSERT ((vec_x.size () == 2) && (vec_y.size () == 2)); | |
| T8_ASSERT ((std::ranges::distance(vec_x) >= 2) && (std::ranges::distance(vec_y) >= 2)); |
Describe your changes here:
Closes #2130
Very open for suggestions
All these boxes must be checked by the AUTHOR before requesting review:
Documentation:,Bugfix:,Feature:,Improvement:orOther:.All these boxes must be checked by the REVIEWERS before merging the pull request:
As a reviewer please read through all the code lines and make sure that the code is fully understood, bug free, well-documented and well-structured.
General
Tests
If the Pull request introduces code that is not covered by the github action (for example coupling with a new library):
Scripts and Wiki
script/find_all_source_files.scpto check the indentation of these files.License
doc/(or already has one).