Skip to content
This repository has been archived by the owner on Feb 22, 2024. It is now read-only.

Commit

Permalink
Add point2d unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
joseviccruz committed Sep 17, 2023
1 parent f87e75d commit 480c2b3
Show file tree
Hide file tree
Showing 5 changed files with 767 additions and 8 deletions.
7 changes: 7 additions & 0 deletions robocin/geometry/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,10 @@ robocin_cpp_library(
HDRS point2d.h
SRCS point2d.cpp
)

robocin_cpp_test(
NAME point2d_test
HDRS ../utility/internal/test/epsilon_injector.h
SRCS point2d_test.cpp
DEPS point2d
)
2 changes: 1 addition & 1 deletion robocin/geometry/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ various methods and operators for manipulating and performing calculations with
### Comparison Operators

- `bool operator==(const Point2D& other) const`: Equality operator that checks if two points are equal;
- `std::three_way_comparable auto operator<=>(const Point2D& other) const`: Three-way comparison operator that compares
- `auto operator<=>(const Point2D& other) const`: Three-way comparison operator that compares
two points and returns their relative ordering;

### Swap
Expand Down
1 change: 1 addition & 0 deletions robocin/geometry/internal/point2d_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#ifndef ROBOCIN_GEOMETRY_POINT2D_INTERNAL_H
#define ROBOCIN_GEOMETRY_POINT2D_INTERNAL_H

#include <iterator>
#include <type_traits>

namespace robocin::point2d_internal {
Expand Down
14 changes: 7 additions & 7 deletions robocin/geometry/point2d.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@
#ifndef ROBOCIN_GEOMETRY_POINT2D_H
#define ROBOCIN_GEOMETRY_POINT2D_H

#include "robocin/geometry/internal/point2d_internal.h"
#include "robocin/utility/fuzzy_compare.h"

#include <cmath>
#include <iostream>
#include <numeric>
#include <optional>
#include <stdexcept>

#include "robocin/geometry/internal/point2d_internal.h"
#include "robocin/utility/fuzzy_compare.h"

namespace robocin {

template <class T>
Expand Down Expand Up @@ -120,7 +120,7 @@ struct Point2D {
}
}

inline constexpr std::three_way_comparable auto operator<=>(const Point2D& other) const {
inline constexpr auto operator<=>(const Point2D& other) const {
if constexpr (has_epsilon_v<value_type>) {
if (auto x_cmp = fuzzyCmpThreeWay(x, other.x); std::is_neq(x_cmp)) {
return x_cmp;
Expand Down Expand Up @@ -208,7 +208,7 @@ struct Point2D {
[[nodiscard]] constexpr Point2D rotatedCCW(value_type t) &&
requires(std::floating_point<value_type>)
{
return rotateCW(t), std::move(*this);
return rotateCCW(t), std::move(*this);
}
[[nodiscard]] constexpr Point2D rotatedCCW(value_type t) const&
requires(std::floating_point<value_type>)
Expand Down Expand Up @@ -247,11 +247,11 @@ struct Point2D {
{
if constexpr (has_epsilon_v<value_type>) {
if (value_type norm = this->norm(); not fuzzyIsZero(norm)) {
x *= norm, y *= norm;
x /= norm, y /= norm;
}
} else {
if (value_type norm = this->norm()) {
x *= norm, y *= norm;
x /= norm, y /= norm;
}
}
}
Expand Down
Loading

0 comments on commit 480c2b3

Please sign in to comment.