Skip to content

Commit b7caabc

Browse files
authored
Review/modify/add the API doc (math folder) (#1184)
In olp-cpp-sdk-core/include/math, review and modify the existing documentation and add missing descriptions so that we have fewer errors when building the API ref. Relates-To: OLPEDGE-1447 Signed-off-by: Halyna Dumych <[email protected]>
1 parent 00935d2 commit b7caabc

File tree

4 files changed

+207
-115
lines changed

4 files changed

+207
-115
lines changed

olp-cpp-sdk-core/include/olp/core/math/AlignedBox.h

Lines changed: 105 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -27,269 +27,284 @@
2727
namespace olp {
2828
namespace math {
2929
/**
30-
* This type trait tries to map a type to another one which can handle
31-
* arithmetic overflows.
30+
* @brief Maps an integer type to the one that
31+
* can handle arithmetic overflows.
3232
*
33-
* For integer types less than 64 bits, it maps to a larger type which can
34-
* handle overflows. The default implementation handles types including
35-
* floating-point ones. Specialization is used to handle integer types.
36-
* @note for float, it can overflow as well. However, the overflow case in
37-
* reality is relatively rare compared to the integer types. Also if T itself is
38-
* 64-bit integer type, it can overflow as well.
33+
* For integer types less than 64 bits, it maps to a larger type that can
34+
* handle overflows. The default implementation handles types, including
35+
* the floating-point ones. Specifications are used to handle integer types.
36+
*
37+
* @note For float, it can overflow as well. However, the overflow case
38+
* is relatively rare compared to the integer types. Also if `T` itself is
39+
* a 64-bit integer type, it can overflow as well.
3940
*/
4041
template <typename T,
4142
int IntegerBits = std::is_integral<T>::value ? sizeof(T) * 8 : 0,
4243
bool IsSigned = std::numeric_limits<T>::is_signed>
4344
struct OverflowTrait {
45+
/// An alias for the integer type.
4446
using Type = T;
4547
};
4648

47-
/** Specialization for 8-bit signed integers */
49+
/// A specialization for 8-bit signed integers.
4850
template <typename T>
4951
struct OverflowTrait<T, 8, true> {
52+
/// An alias for the `int16_t` integer type.
5053
using Type = int16_t;
5154
};
5255

53-
/** Specialization for 8-bit unsigned integers */
56+
/// A specialization for 8-bit unsigned integers.
5457
template <typename T>
5558
struct OverflowTrait<T, 8, false> {
59+
/// An alias for the `uint16_t` integer type.
5660
using Type = uint16_t;
5761
};
5862

59-
/** Specialization for 16-bit signed integers */
63+
/// A specialization for 16-bit signed integers.
6064
template <typename T>
6165
struct OverflowTrait<T, 16, true> {
66+
/// An alias for the `int32_t` integer type.
6267
using Type = int32_t;
6368
};
6469

65-
/** Specialization for 16-bit unsigned integers */
70+
/// A specialization for 16-bit unsigned integers.
6671
template <typename T>
6772
struct OverflowTrait<T, 16, false> {
73+
/// An alias for `uint32_t` integer type.
6874
using Type = uint32_t;
6975
};
7076

71-
/** Specialization for 32-bit signed integers */
77+
/// A specialization for 32-bit signed integers.
7278
template <typename T>
7379
struct OverflowTrait<T, 32, true> {
80+
/// An alias for the `int64_t` integer type.
7481
using Type = int64_t;
7582
};
7683

77-
/** Specialization for 32-bit unsigned integers */
84+
/// A specialization for 32-bit unsigned integers.
7885
template <typename T>
7986
struct OverflowTrait<T, 32, false> {
87+
/// An alias for the `uint64_t` integer type.
8088
using Type = uint64_t;
8189
};
8290

8391
/**
84-
* An aligned bounding-box implementation.
92+
* @brief The aligned bounding-box implementation.
8593
*
86-
* @tparam T - The real type.
87-
* @tparam N - The box dimensions.
94+
* @tparam T The real type.
95+
* @tparam N The box dimensions.
8896
*/
8997
template <typename T, unsigned int N>
9098
class AlignedBox {
9199
public:
92-
static const unsigned int numCorners =
93-
1 << N; /*!< Number of corners for the box. */
94-
static const unsigned int dimensions = N; /*!< Box dimensions. */
95-
96-
using ValueType = T; /*!< The box value type. */
100+
/// The number of corners for the box.
101+
static const unsigned int numCorners = 1 << N;
102+
/// The box dimensions.
103+
static const unsigned int dimensions = N;
104+
105+
/// An alias for the box value type.
106+
using ValueType = T;
107+
/// An alias for the overflow trait.
97108
using OverflowType = typename OverflowTrait<T>::Type;
98-
using VectorType = Vector<ValueType, N>; /*!< VectorType of the box. */
109+
/// An alias for the vector type of the box.
110+
using VectorType = Vector<ValueType, N>;
111+
/// An alias for the overflow vector type.
99112
using OverflowVectorType = Vector<OverflowType, N>;
100113

114+
/// An alias for the corner points array type.
101115
using CornerArrayType =
102116
typename std::array<VectorType,
103-
numCorners>; /*!< Corner points array type. */
117+
numCorners>;
104118

105119
/**
106-
* Default constructor.
120+
* @brief Creates an `AlignedBox` instance.
107121
*
108-
* An empty box is constructed.
122+
* An empty box is created.
109123
*/
110124
AlignedBox();
111125

112126
/**
113-
* @brief Constructor.
127+
* @brief Creates an `AlignedBox` instance.
114128
*
115-
* If the any components of min are greater than max an
116-
* empty box will result.
129+
* If any component of `min` is greater than `max`,
130+
* an empty box is created.
117131
*
118-
* @param[in] min - The box minimum point.
119-
* @param[in] max - The box maximum point.
132+
* @param[in] min The box minimum point.
133+
* @param[in] max The box maximum point.
120134
*/
121135
AlignedBox(const VectorType& min, const VectorType& max);
122136

123137
/**
124-
* @brief Copy constructor.
138+
* @brief Creates a copy of the `AlignedBox` instance.
125139
*
126-
* @tparam OtherT - Real type of the box being copied.
127-
* @param[in] other - The box to be copied.
140+
* @tparam OtherT The real type of the box being copied.
141+
* @param[in] other The box to be copied.
128142
*/
129143
template <typename OtherT>
130144
AlignedBox(const AlignedBox<OtherT, N>& other);
131145

132146
/**
133-
* @brief Reset the box to empty.
147+
* @brief Resets the box to empty.
134148
*/
135149
void Reset();
136150

137151
/**
138-
* @brief Reset the box to a new min/max.
152+
* @brief Resets the box to the new minimum and maximum points.
139153
*
140-
* If the any components of min are greater than max an
141-
* empty box will result.
154+
* If any component of `min` is greater than `max`,
155+
* an empty box is created.
142156
*
143-
* @param[in] min - The box minimum point.
144-
* @param[in] max - The box maximum point.
157+
* @param[in] min The box minimum point.
158+
* @param[in] max The box maximum point.
145159
*/
146160
void Reset(const VectorType& min, const VectorType& max);
147161

148162
/**
149-
* @brief Test if the box is empty.
163+
* @brief Tests whether the box is empty.
150164
*
151-
* @return - True if the box is empty.
165+
* @return True if the box is empty; false otherwise.
152166
*/
153167
bool Empty() const;
154168

155169
/**
156-
* @brief Get the center of the box.
170+
* @brief Gets the center point of the box.
157171
*
158172
* The center of an empty box is undefined.
159173
*
160-
* @return - Box center point.
174+
* @return The box center point.
161175
*/
162176
VectorType Center() const;
163177

164178
/**
165-
* @brief Get the size of the box.
179+
* @brief Gets the size of the box.
166180
*
167181
* The size of an empty box is zero.
168182
*
169-
* @return - The size along each dimension.
170-
* @note overflow might happen. E.g. max is INT_MAX and min is INT_MIN.
183+
* @return The size of each dimension.
184+
*
185+
* @note An overflow might happen. For example,
186+
* when `max` is `INT_MAX` and `min` is `INT_MIN`.
171187
*/
172188
VectorType Size() const;
173189

174190
/**
175-
* @brief Get the box minimum corner point.
191+
* @brief Gets the box minimum corner point.
176192
*
177193
* The minimum corner point of an empty box is undefined.
178194
*
179-
* @return - Box minimum point.
195+
* @return The minimum point of the box.
180196
*/
181197
const VectorType& Minimum() const;
182198

183199
/**
184-
* @brief Get the box maximum corner point.
200+
* @brief Gets the box maximum corner point.
185201
*
186202
* The maximum corner point of an empty box is undefined.
187203
*
188-
* @return - Box maximum point.
204+
* @return The maximum point of the box.
189205
*/
190206
const VectorType& Maximum() const;
191207

192208
/**
193-
* @brief Get the corner points of the box.
209+
* @brief Gets the corner points of the box.
194210
*
195211
* The corner points of an empty box are undefined.
196212
*
197-
* @return - An array containing the box corner points.
213+
* @return An array containing the box corner points.
198214
*/
199215
CornerArrayType Corners() const;
200216
/**
201-
* @brief Test if a box contains a point.
217+
* @brief Tests whether the box contains a point.
202218
*
203219
* This test is inclusive.
220+
*
221+
* @param point The point to be tested.
222+
* @param epsilon The epsilon around the point.
204223
*
205-
* @param[in] point - The point to be tested.
206-
*
207-
* @return - True if the point is contained by the box.
224+
* @return True if the box contains the point; false otherwise.
208225
*/
209226
bool Contains(const VectorType& point, T epsilon = T()) const;
210227

211228
/**
212-
* @brief Test if a box contains another box
229+
* @brief Tests whether the box contains another box.
213230
*
214-
* @param[in] box Aligned box
231+
* @param[in] box The aligned box.
215232
*
216-
* @return True if the box is contained by the box.
233+
* @return True if the box contains another box; false otherwise.
217234
*/
218235
bool Contains(const AlignedBox& box) const;
219236

220237
/**
221-
* @brief Test if a box intersects another box.
238+
* @brief Tests whether the box intersects another box.
222239
*
223-
* The test box is considered to be insecting if it is
224-
* contained by the box.
240+
* A test box is considered to be intersecting if
241+
* another box contains it.
225242
*
226-
* @param[in] box - The box to be tested.
243+
* @param[in] box The box to be tested.
227244
*
228-
* @return - True if the boxes intersect.
245+
* @return True if the boxes intersect; false otherwise.
229246
*/
230247
bool Intersects(const AlignedBox& box) const;
231248

232249
/**
233-
* @brief Compute the nearest point on the box to a point.
250+
* @brief Computes the nearest point on the box to a point.
234251
*
235252
* The nearest point to an empty box is undefined.
236253
*
237-
* @param[in] point - Point from which to find the nearest point.
254+
* @param[in] point The point from which to find the nearest point.
238255
*
239-
* @return - The nearest point on the box to the specified point.
256+
* @return The nearest point on the box to the specified point.
240257
*/
241258
VectorType NearestPoint(const VectorType& point) const;
242259

243260
/**
244-
* @brief Compute the distance to the box.
261+
* @brief Computes the distance from a point to the box.
245262
*
246-
* A point on or inside the box will have a distance of zero.
263+
* A point on or inside the box has a distance of zero.
247264
*
248265
* The distance to an empty box is undefined.
249266
*
250-
* @param[in] point - Point from which to find the distance.
267+
* @param[in] point The point from which to find the distance.
251268
*
252-
* @return - The distance between the point and the box.
269+
* @return The distance between the point and the box.
253270
*/
254271
ValueType Distance(const VectorType& point) const;
255272

256273
/**
257-
* @brief Compute the squared distance to the box.
274+
* @brief Computes the squared distance from a point to the box.
258275
*
259-
* A point on or inside the box will have a squared distance of zero.
276+
* A point on or inside the box has a squared distance of zero.
260277
*
261278
* The squared distance to an empty box is undefined.
262279
*
263-
* @param[in] point - Point from which to find the squared distance.
280+
* @param[in] point The point from which to find the squared distance.
264281
*
265-
* @return - The squared distance between the point and the box.
282+
* @return The squared distance between the point and the box.
266283
*/
267284
ValueType Distance2(const VectorType& point) const;
268285

269286
/**
270-
* @brief Equality operator.
271-
*
272-
* @param[in] box - Other box.
287+
* @brief Checks whether two boxes are equal.
273288
*
274-
* @return - True if the boxes are equal.
289+
* @param[in] box The other box.
275290
*/
276291
bool operator==(const AlignedBox& box) const;
277292

278293
/**
279-
* @brief Inequality operator.
280-
*
281-
* @param[in] box - Other box.
294+
* @brief Checks whether two boxes are not equal.
282295
*
283-
* @return - True if the boxes are not equal.
296+
* @param[in] box The other box.
284297
*/
285298
bool operator!=(const AlignedBox& box) const;
286299

287300
private:
288301
template <typename U, unsigned int X>
289302
friend class AlignedBox;
290303

291-
VectorType minimum_; /*!< Box min point. */
292-
VectorType maximum_; /*!< Box max point. */
304+
/// The box minimum point.
305+
VectorType minimum_;
306+
/// The box maximum point.
307+
VectorType maximum_;
293308
};
294309

295310
#ifndef NDEBUG
@@ -300,8 +315,9 @@ bool CheckAddOperationOverflow(T a, T b) {
300315
}
301316
#endif
302317

318+
/// The 3D double-precision box type.
303319
using AlignedBox3d =
304-
AlignedBox<double, 3>; /*!< Three dimension double-precision box type. */
320+
AlignedBox<double, 3>;
305321

306322
template <typename T, unsigned int N>
307323
AlignedBox<T, N>::AlignedBox()
@@ -332,7 +348,7 @@ void AlignedBox<T, N>::Reset(const VectorType& min, const VectorType& max) {
332348
template <typename T, unsigned int N>
333349
typename AlignedBox<T, N>::VectorType AlignedBox<T, N>::Center() const {
334350
#ifndef NDEBUG
335-
// Check for possible 64-bit integer overflow/underflow
351+
// Checks for possible 64-bit integer overflows or underflows.
336352
if (std::numeric_limits<OverflowType>::is_integer &&
337353
sizeof(OverflowType) * 8 == 64) {
338354
for (unsigned dim = 0; dim < dimensions; ++dim) {
@@ -442,7 +458,7 @@ auto AlignedBox<T, N>::Distance2(const VectorType& point) const -> ValueType {
442458
template <typename T, unsigned int N>
443459
bool AlignedBox<T, N>::operator==(const AlignedBox& box) const {
444460
//
445-
// If either box is empty than check which ones are
461+
// If either box is empty, checks which ones are
446462
// empty.
447463
//
448464
bool thisEmpty = Empty();

0 commit comments

Comments
 (0)