Skip to content

Commit

Permalink
add document; apply fix-format
Browse files Browse the repository at this point in the history
  • Loading branch information
luk036 committed May 16, 2024
1 parent f921a78 commit 730a4c0
Show file tree
Hide file tree
Showing 8 changed files with 440 additions and 357 deletions.
112 changes: 69 additions & 43 deletions include/recti/generic.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@
#include <cmath> // for abs

namespace recti {

/**
* @brief overlap
* @brief Checks if two objects overlap.
*
* The above code defines a template function called `overlap` that takes two
* arguments `lhs` and `rhs`. The function checks if the two arguments overlap
* with each other.
* This function checks if the two input objects `lhs` and `rhs` overlap with each other. It
* first checks if the `lhs` object has an `overlaps` member function that can be called with
* `rhs` as an argument. If so, it calls that function and returns the result. If not, it checks
* if the `rhs` object has an `overlaps` member function that can be called with `lhs` as an
* argument, and returns the result of that call. If neither object has an `overlaps` member
* function, the function simply checks if the two objects are equal and returns the result.
*
* .---------------------.
* | |
Expand All @@ -21,12 +23,11 @@ namespace recti {
* | |
* `----------------'
*
* @tparam U1
* @tparam U2
* @param[in] lhs
* @param[in] rhs
* @return true
* @return false
* @tparam U1 The type of the first object.
* @tparam U2 The type of the second object.
* @param lhs The first object to check for overlap.
* @param rhs The second object to check for overlap.
* @return `true` if the two objects overlap, `false` otherwise.
*/
template <typename U1, typename U2> //
constexpr auto overlap(const U1 &lhs, const U2 &rhs) -> bool {
Expand All @@ -40,24 +41,27 @@ namespace recti {
}

/**
* @brief contain
*
* The above code is defining a template function called `contain` that checks if one object
* contains another object.
* @brief Check if one object contains another object.
*
* This function checks if the first object `lhs` contains the second object `rhs`. It first
* checks if `lhs` has a `contains` member function that can be called with `rhs` as an
* argument, and returns the result of that call. If `lhs` does not have a `contains` member
* function, it checks if `rhs` has a `contains` member function that can be called with `lhs`
* as an argument, and returns `false` if that is the case (since `rhs` contains `lhs` implies
* that `lhs` does not contain `rhs`). If neither object has a `contains` member function, the
* function simply checks if the two objects are equal and returns the result.
*
* .---------------------.
* | .--. |
* | . | ---- | | |
* | `--' |
* `---------------------'
*
* @tparam U1
* @tparam U2
* @param[in] lhs
* @param[in] rhs
* @return true
* @return false
* @tparam U1 The type of the first object.
* @tparam U2 The type of the second object.
* @param lhs The first object to check for containment.
* @param rhs The second object to check for containment.
* @return `true` if the first object contains the second object, `false` otherwise.
*/
template <typename U1, typename U2> //
constexpr auto contain(const U1 &lhs, const U2 &rhs) -> bool {
Expand All @@ -70,10 +74,17 @@ namespace recti {
}
}

/* The above code is defining a template function called `intersection` that takes two
parameters `lhs` and `rhs`. The function returns the intersection of `lhs` and `rhs`. */
/**
* @brief intersection
* @brief Computes the intersection of two objects.
*
* This function computes the intersection of the two input objects `lhs` and `rhs`. It first
* checks if `lhs` has an `intersect_with` member function that can be called with `rhs` as an
* argument, and returns the result of that call. If `lhs` does not have an `intersect_with`
* member function, it checks if `rhs` has an `intersect_with` member function that can be
* called with `lhs` as an argument, and returns the result of that call. If neither object has
* an `intersect_with` member function, the function asserts that `lhs` and `rhs` are equal and
* returns `lhs`.
*
*
* .---------------------.
* | |
Expand All @@ -83,11 +94,11 @@ namespace recti {
* | |
* `----------------'
*
* @tparam U1
* @tparam U2
* @param[in] lhs
* @param[in] rhs
* @return constexpr auto
* @tparam U1 The type of the first object.
* @tparam U2 The type of the second object.
* @param[in] lhs The first object.
* @param[in] rhs The second object.
* @return The intersection of `lhs` and `rhs`.
*/
template <typename U1, typename U2> //
constexpr auto intersection(const U1 &lhs, const U2 &rhs) {
Expand All @@ -101,10 +112,8 @@ namespace recti {
}
}

/* The above code is defining a template function called `min_dist` that calculates the minimum
distance between two objects `lhs` and `rhs`. */
/**
* @brief min_dist
* @brief Calculates the minimum distance between two objects `lhs` and `rhs`.
*
* .-----------.
* | |
Expand All @@ -113,11 +122,19 @@ namespace recti {
* `-----------' | |
* | |
* `-------------'
* @tparam U1
* @tparam U2
* @param[in] lhs
* @param[in] rhs
* @return constexpr auto
*
* The function first checks if `lhs` has a `min_dist_with` member function that can be
* called with `rhs` as an argument, and returns the result of that call. If `lhs` does not
* have a `min_dist_with` member function, it checks if `rhs` has a `min_dist_with` member
* function that can be called with `lhs` as an argument, and returns the result of that
* call. If neither object has a `min_dist_with` member function, the function returns the
* absolute difference between `lhs` and `rhs`.
*
* @tparam U1 The type of the first object.
* @tparam U2 The type of the second object.
* @param[in] lhs The first object.
* @param[in] rhs The second object.
* @return The minimum distance between `lhs` and `rhs`.
*/
template <typename U1, typename U2> //
constexpr auto min_dist(const U1 &lhs, const U2 &rhs) {
Expand All @@ -131,13 +148,22 @@ namespace recti {
}

/**
* @brief min_dist with change
* @brief Calculates the minimum distance between two objects `lhs` and `rhs`, with the ability
* to handle a change in the objects.
*
* The function first checks if `lhs` has a `min_dist_change_with` member function that can be
* called with `rhs` as an argument, and returns the result of that call. If `lhs` does not have
* a `min_dist_change_with` member function, it checks if `rhs` has a `min_dist_change_with`
* member function that can be called with `lhs` as an argument, and returns the result of that
* call. If neither object has a `min_dist_change_with` member function, the function returns
* the absolute difference between `lhs` and `rhs`.
*
* @tparam U1
* @tparam U2
* @param[in] lhs
* @param[in] rhs
* @return constexpr auto
* @tparam U1 The type of the first object.
* @tparam U2 The type of the second object.
* @param[in] lhs The first object.
* @param[in] rhs The second object.
* @return The minimum distance between `lhs` and `rhs`, with the ability to handle a change in
* the objects.
*/
template <typename U1, typename U2> //
constexpr auto min_dist_change(U1 &lhs, U2 &rhs) {
Expand Down
Loading

0 comments on commit 730a4c0

Please sign in to comment.