Skip to content

Commit a6cabaf

Browse files
committed
Document Morton.h file and its functions, adding detailed descriptions and parameters
1 parent 38d60c7 commit a6cabaf

File tree

1 file changed

+45
-13
lines changed

1 file changed

+45
-13
lines changed

source/pbat/geometry/Morton.h

Lines changed: 45 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
/**
2+
* @file Morton.h
3+
* @author Quoc-Minh Ton-That ([email protected])
4+
* @brief This file contains functions to compute Morton codes.
5+
* @date 2025-02-12
6+
*
7+
* @copyright Copyright (c) 2025
8+
*
9+
*/
10+
111
#ifndef PBAT_GEOMETRY_MORTON_H
212
#define PBAT_GEOMETRY_MORTON_H
313

@@ -11,14 +21,17 @@
1121
namespace pbat {
1222
namespace geometry {
1323

14-
using MortonCodeType = std::uint32_t;
15-
16-
// NOTE:
17-
// We make these (otherwise non-templated) functions inline so that they
18-
// are compiled by nvcc whenever this header is included in cuda sources.
24+
using MortonCodeType = std::uint32_t; ///< Type used to represent Morton codes
1925

20-
// Expands a 10-bit integer into 30 bits
21-
// by inserting 2 zeros after each bit.
26+
/**
27+
* @brief Expands a 10-bit integer into 30 bits by inserting 2 zeros after each bit.
28+
*
29+
* @note We make this (otherwise non-templated) function inline so that it gets compiled by nvcc
30+
* whenever this header is included in cuda sources.
31+
*
32+
* @param v 10-bit integer
33+
* @return Expanded 30-bit integer
34+
*/
2235
PBAT_HOST_DEVICE inline MortonCodeType ExpandBits(MortonCodeType v)
2336
{
2437
v = (v * 0x00010001u) & 0xFF0000FFu;
@@ -28,13 +41,32 @@ PBAT_HOST_DEVICE inline MortonCodeType ExpandBits(MortonCodeType v)
2841
return v;
2942
}
3043

31-
// Calculates a 30-bit Morton code for the
32-
// given 3D point located within the unit cube [0,1].
44+
namespace detail {
45+
3346
template <class Point>
34-
requires std::is_convertible_v<
35-
decltype(std::declval<Point>()[std::declval<int>()]),
36-
float> [[maybe_unused]] PBAT_HOST_DEVICE inline MortonCodeType
37-
Morton3D(Point x)
47+
concept CMorton3dPoint = requires(Point p)
48+
{
49+
{
50+
p[0]
51+
} -> std::convertible_to<float>;
52+
{
53+
p[1]
54+
} -> std::convertible_to<float>;
55+
{
56+
p[2]
57+
} -> std::convertible_to<float>;
58+
};
59+
60+
} // namespace detail
61+
62+
/**
63+
* @brief Calculates a 30-bit Morton code for the given 3D point located within the unit cube [0,1].
64+
* @tparam Point Type of the point
65+
* @param x 3D point located within the unit cube [0,1]
66+
* @return Morton code of x
67+
*/
68+
template <detail::CMorton3dPoint Point>
69+
[[maybe_unused]] PBAT_HOST_DEVICE inline MortonCodeType Morton3D(Point x)
3870
{
3971
using namespace std;
4072
MortonCodeType xx =

0 commit comments

Comments
 (0)