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

Commit 43ca90f

Browse files
committed
Add point2d unit tests
1 parent f87e75d commit 43ca90f

5 files changed

Lines changed: 768 additions & 8 deletions

File tree

robocin/geometry/CMakeLists.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,10 @@ robocin_cpp_library(
33
HDRS point2d.h
44
SRCS point2d.cpp
55
)
6+
7+
robocin_cpp_test(
8+
NAME point2d_test
9+
HDRS ../utility/internal/test/epsilon_injector.h
10+
SRCS point2d_test.cpp
11+
DEPS point2d
12+
)

robocin/geometry/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ various methods and operators for manipulating and performing calculations with
8686
### Comparison Operators
8787

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

9292
### Swap

robocin/geometry/internal/point2d_internal.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#ifndef ROBOCIN_GEOMETRY_POINT2D_INTERNAL_H
77
#define ROBOCIN_GEOMETRY_POINT2D_INTERNAL_H
88

9+
#include <iterator>
910
#include <type_traits>
1011

1112
namespace robocin::point2d_internal {

robocin/geometry/point2d.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@
66
#ifndef ROBOCIN_GEOMETRY_POINT2D_H
77
#define ROBOCIN_GEOMETRY_POINT2D_H
88

9+
#include "robocin/geometry/internal/point2d_internal.h"
10+
#include "robocin/utility/fuzzy_compare.h"
11+
912
#include <cmath>
1013
#include <iostream>
1114
#include <numeric>
1215
#include <optional>
1316
#include <stdexcept>
1417

15-
#include "robocin/geometry/internal/point2d_internal.h"
16-
#include "robocin/utility/fuzzy_compare.h"
17-
1818
namespace robocin {
1919

2020
template <class T>
@@ -120,7 +120,7 @@ struct Point2D {
120120
}
121121
}
122122

123-
inline constexpr std::three_way_comparable auto operator<=>(const Point2D& other) const {
123+
inline constexpr auto operator<=>(const Point2D& other) const {
124124
if constexpr (has_epsilon_v<value_type>) {
125125
if (auto x_cmp = fuzzyCmpThreeWay(x, other.x); std::is_neq(x_cmp)) {
126126
return x_cmp;
@@ -208,7 +208,7 @@ struct Point2D {
208208
[[nodiscard]] constexpr Point2D rotatedCCW(value_type t) &&
209209
requires(std::floating_point<value_type>)
210210
{
211-
return rotateCW(t), std::move(*this);
211+
return rotateCCW(t), std::move(*this);
212212
}
213213
[[nodiscard]] constexpr Point2D rotatedCCW(value_type t) const&
214214
requires(std::floating_point<value_type>)
@@ -247,11 +247,11 @@ struct Point2D {
247247
{
248248
if constexpr (has_epsilon_v<value_type>) {
249249
if (value_type norm = this->norm(); not fuzzyIsZero(norm)) {
250-
x *= norm, y *= norm;
250+
x /= norm, y /= norm;
251251
}
252252
} else {
253253
if (value_type norm = this->norm()) {
254-
x *= norm, y *= norm;
254+
x /= norm, y /= norm;
255255
}
256256
}
257257
}

0 commit comments

Comments
 (0)