Skip to content

Commit 31d3359

Browse files
authored
Merge pull request #42 from orange-cpp/feature/new-codestyle
Feature/new codestyle
2 parents b06fd00 + dd738f3 commit 31d3359

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+1322
-1371
lines changed

.clang-format

Lines changed: 41 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,64 @@
1-
# Generated from CLion C/C++ Code Style settings
2-
---
3-
Language: Cpp
1+
# Generated by CLion for Stroustrup
2+
# The Stroustrup style, named after Bjarne Stroustrup, the creator of C++, is similar to the K&R style but differs
3+
# in its treatment of the class definitions and the placement of braces in certain contexts. The opening brace is
4+
# placed on the same line as the control statement, and the closing brace is on its own line.
45
BasedOnStyle: LLVM
6+
57
AccessModifierOffset: -4
6-
AlignConsecutiveAssignments: false
7-
AlignConsecutiveDeclarations: false
8-
AlignOperands: true
8+
AlignConsecutiveAssignments: None
9+
AlignConsecutiveBitFields: None
10+
AlignConsecutiveDeclarations: None
11+
AlignConsecutiveMacros: AcrossEmptyLinesAndComments
912
AlignTrailingComments: false
10-
AllowShortBlocksOnASingleLine: false
13+
AllowShortBlocksOnASingleLine: Never
1114
AllowShortFunctionsOnASingleLine: None
12-
AlwaysBreakTemplateDeclarations: Yes
13-
BraceWrapping:
15+
AllowShortIfStatementsOnASingleLine: false
16+
AllowShortLoopsOnASingleLine: false
17+
BreakTemplateDeclarations: Leave
18+
BreakBeforeBraces: Custom
19+
BraceWrapping:
1420
AfterCaseLabel: true
1521
AfterClass: true
22+
AfterFunction: true
1623
AfterControlStatement: true
24+
SplitEmptyFunction: true
1725
AfterEnum: true
18-
AfterFunction: true
1926
AfterNamespace: true
2027
AfterStruct: true
2128
AfterUnion: true
2229
AfterExternBlock: true
23-
BeforeCatch: false
24-
BeforeElse: false
30+
BeforeCatch: true
31+
BeforeElse: true
2532
BeforeLambdaBody: true
26-
BeforeWhile: false
27-
IndentBraces: false
28-
SplitEmptyFunction: true
33+
BeforeWhile: true
2934
SplitEmptyRecord: true
3035
SplitEmptyNamespace: true
31-
BreakBeforeBraces: Custom
32-
BreakConstructorInitializers: AfterColon
33-
BreakConstructorInitializersBeforeComma: false
36+
BreakBeforeBinaryOperators: All
37+
BreakBeforeConceptDeclarations: false
3438
ColumnLimit: 120
35-
ConstructorInitializerAllOnOneLineOrOnePerLine: false
36-
ContinuationIndentWidth: 8
37-
IncludeCategories:
38-
- Regex: '^<.*'
39-
Priority: 1
40-
- Regex: '^".*'
41-
Priority: 2
42-
- Regex: '.*'
43-
Priority: 3
44-
IncludeIsMainRegex: '([-_](test|unittest))?$'
45-
IndentCaseLabels: true
39+
IncludeBlocks: Merge
40+
IndentExternBlock: Indent
41+
IndentRequiresClause: false
4642
IndentWidth: 4
47-
InsertNewlineAtEOF: true
48-
MacroBlockBegin: ''
49-
MacroBlockEnd: ''
50-
MaxEmptyLinesToKeep: 2
43+
ContinuationIndentWidth: 8
44+
KeepEmptyLinesAtTheStartOfBlocks: false
5145
NamespaceIndentation: All
5246
PointerAlignment: Left
53-
SpaceAfterCStyleCast: true
47+
SortUsingDeclarations: true
5448
SpaceAfterTemplateKeyword: false
49+
SpaceBeforeCtorInitializerColon: false
50+
SpaceBeforeParens: Custom
51+
SpaceBeforeParensOptions:
52+
AfterControlStatements: true
53+
AfterFunctionDeclarationName: false
54+
AfterFunctionDefinitionName: false
55+
AfterForeachMacros: true
56+
AfterIfMacros: true
57+
AfterOverloadedOperator: false
58+
BeforeNonEmptyParentheses: false
5559
SpaceBeforeRangeBasedForLoopColon: false
5660
SpaceInEmptyParentheses: false
57-
SpacesInAngles: false
58-
SpacesInConditionalStatement: false
5961
SpacesInCStyleCastParentheses: false
60-
SpacesInParentheses: false
61-
TabWidth: 4
62-
...
62+
SpacesInConditionalStatement: false
63+
SpacesInContainerLiterals: false
64+
SpacesInParentheses: false

include/omath/3d_primitives/box.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
namespace omath::primitives
1212
{
1313
[[nodiscard]]
14-
std::array<Triangle<Vector3<float>>, 12> CreateBox(const Vector3<float>& top, const Vector3<float>& bottom,
15-
const Vector3<float>& dirForward, const Vector3<float>& dirRight,
14+
std::array<Triangle<Vector3<float>>, 12> create_box(const Vector3<float>& top, const Vector3<float>& bottom,
15+
const Vector3<float>& dir_forward, const Vector3<float>& dir_right,
1616
float ratio = 4.f);
1717
}

include/omath/angle.hpp

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,9 @@
33
//
44

55
#pragma once
6+
#include "omath/angles.hpp"
67
#include <algorithm>
78
#include <utility>
8-
#include "omath/angles.hpp"
9-
109

1110
namespace omath
1211
{
@@ -17,14 +16,14 @@ namespace omath
1716
};
1817

1918
template<class Type = float, Type min = Type(0), Type max = Type(360), AngleFlags flags = AngleFlags::Normalized>
20-
requires std::is_arithmetic_v<Type>
19+
requires std::is_arithmetic_v<Type>
2120
class Angle
2221
{
2322
Type m_angle;
2423
constexpr explicit Angle(const Type& degrees)
2524
{
2625
if constexpr (flags == AngleFlags::Normalized)
27-
m_angle = angles::WrapAngle(degrees, min, max);
26+
m_angle = angles::wrap_angle(degrees, min, max);
2827

2928
else if constexpr (flags == AngleFlags::Clamped)
3029
m_angle = std::clamp(degrees, min, max);
@@ -37,17 +36,17 @@ namespace omath
3736

3837
public:
3938
[[nodiscard]]
40-
constexpr static Angle FromDegrees(const Type& degrees)
39+
constexpr static Angle from_degrees(const Type& degrees)
4140
{
4241
return Angle{degrees};
4342
}
44-
constexpr Angle() : m_angle(0)
43+
constexpr Angle(): m_angle(0)
4544
{
4645
}
4746
[[nodiscard]]
48-
constexpr static Angle FromRadians(const Type& degrees)
47+
constexpr static Angle from_radians(const Type& degrees)
4948
{
50-
return Angle{angles::RadiansToDegrees<Type>(degrees)};
49+
return Angle{angles::radians_to_degrees<Type>(degrees)};
5150
}
5251

5352
[[nodiscard]]
@@ -57,51 +56,51 @@ namespace omath
5756
}
5857

5958
[[nodiscard]]
60-
constexpr Type AsDegrees() const
59+
constexpr Type as_degrees() const
6160
{
6261
return m_angle;
6362
}
6463

6564
[[nodiscard]]
66-
constexpr Type AsRadians() const
65+
constexpr Type as_radians() const
6766
{
68-
return angles::DegreesToRadians(m_angle);
67+
return angles::degrees_to_radians(m_angle);
6968
}
7069

7170
[[nodiscard]]
72-
Type Sin() const
71+
Type sin() const
7372
{
74-
return std::sin(AsRadians());
73+
return std::sin(as_radians());
7574
}
7675

7776
[[nodiscard]]
78-
Type Cos() const
77+
Type cos() const
7978
{
80-
return std::cos(AsRadians());
79+
return std::cos(as_radians());
8180
}
8281

8382
[[nodiscard]]
84-
Type Tan() const
83+
Type tan() const
8584
{
86-
return std::tan(AsRadians());
85+
return std::tan(as_radians());
8786
}
8887

8988
[[nodiscard]]
90-
Type Atan() const
89+
Type atan() const
9190
{
92-
return std::atan(AsRadians());
91+
return std::atan(as_radians());
9392
}
9493

9594
[[nodiscard]]
96-
Type Cot() const
95+
Type cot() const
9796
{
98-
return Cos() / Sin();
97+
return cos() / sin();
9998
}
10099

101100
constexpr Angle& operator+=(const Angle& other)
102101
{
103102
if constexpr (flags == AngleFlags::Normalized)
104-
m_angle = angles::WrapAngle(m_angle + other.m_angle, min, max);
103+
m_angle = angles::wrap_angle(m_angle + other.m_angle, min, max);
105104

106105
else if constexpr (flags == AngleFlags::Clamped)
107106
m_angle = std::clamp(m_angle + other.m_angle, min, max);
@@ -115,7 +114,8 @@ namespace omath
115114
}
116115

117116
[[nodiscard]]
118-
constexpr std::partial_ordering operator<=>(const Angle& other) const = default;
117+
constexpr std::partial_ordering operator<=>(const Angle& other) const
118+
= default;
119119

120120
constexpr Angle& operator-=(const Angle& other)
121121
{
@@ -126,7 +126,7 @@ namespace omath
126126
constexpr Angle& operator+(const Angle& other)
127127
{
128128
if constexpr (flags == AngleFlags::Normalized)
129-
return {angles::WrapAngle(m_angle + other.m_angle, min, max)};
129+
return {angles::wrap_angle(m_angle + other.m_angle, min, max)};
130130

131131
else if constexpr (flags == AngleFlags::Clamped)
132132
return {std::clamp(m_angle + other.m_angle, min, max)};

include/omath/angles.hpp

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -10,54 +10,55 @@ namespace omath::angles
1010
{
1111
template<class Type>
1212
requires std::is_floating_point_v<Type>
13-
[[nodiscard]] constexpr Type RadiansToDegrees(const Type& radians)
13+
[[nodiscard]] constexpr Type radians_to_degrees(const Type& radians)
1414
{
15-
return radians * (Type(180) / std::numbers::pi_v<Type>);
15+
return radians * (static_cast<Type>(180) / std::numbers::pi_v<Type>);
1616
}
1717

1818
template<class Type>
1919
requires std::is_floating_point_v<Type>
20-
[[nodiscard]] constexpr Type DegreesToRadians(const Type& degrees)
20+
[[nodiscard]] constexpr Type degrees_to_radians(const Type& degrees)
2121
{
22-
return degrees * (std::numbers::pi_v<Type> / Type(180));
22+
return degrees * (std::numbers::pi_v<Type> / static_cast<Type>(180));
2323
}
2424

25-
template<class type>
26-
requires std::is_floating_point_v<type>
27-
[[nodiscard]] type HorizontalFovToVertical(const type& horFov, const type& aspect)
25+
template<class Type>
26+
requires std::is_floating_point_v<Type>
27+
[[nodiscard]] Type horizontal_fov_to_vertical(const Type& horizontal_fov, const Type& aspect)
2828
{
29-
const auto fovRad = DegreesToRadians(horFov);
29+
const auto fov_rad = degrees_to_radians(horizontal_fov);
3030

31-
const auto vertFov = type(2) * std::atan(std::tan(fovRad / type(2)) / aspect);
31+
const auto vert_fov = static_cast<Type>(2) * std::atan(std::tan(fov_rad / static_cast<Type>(2)) / aspect);
3232

33-
return RadiansToDegrees(vertFov);
33+
return radians_to_degrees(vert_fov);
3434
}
3535

3636
template<class Type>
3737
requires std::is_floating_point_v<Type>
38-
[[nodiscard]] Type VerticalFovToHorizontal(const Type& vertFov, const Type& aspect)
38+
[[nodiscard]] Type vertical_fov_to_horizontal(const Type& vertical_fov, const Type& aspect)
3939
{
40-
const auto fovRad = DegreesToRadians(vertFov);
40+
const auto fov_as_radians = degrees_to_radians(vertical_fov);
4141

42-
const auto horFov = Type(2) * std::atan(std::tan(fovRad / Type(2)) * aspect);
42+
const auto horizontal_fov
43+
= static_cast<Type>(2) * std::atan(std::tan(fov_as_radians / static_cast<Type>(2)) * aspect);
4344

44-
return RadiansToDegrees(horFov);
45+
return radians_to_degrees(horizontal_fov);
4546
}
4647

4748
template<class Type>
4849
requires std::is_arithmetic_v<Type>
49-
[[nodiscard]] Type WrapAngle(const Type& angle, const Type& min, const Type& max)
50+
[[nodiscard]] Type wrap_angle(const Type& angle, const Type& min, const Type& max)
5051
{
5152
if (angle <= max && angle >= min)
5253
return angle;
5354

5455
const Type range = max - min;
5556

56-
Type wrappedAngle = std::fmod(angle - min, range);
57+
Type wrapped_angle = std::fmod(angle - min, range);
5758

58-
if (wrappedAngle < 0)
59-
wrappedAngle += range;
59+
if (wrapped_angle < 0)
60+
wrapped_angle += range;
6061

61-
return wrappedAngle + min;
62+
return wrapped_angle + min;
6263
}
63-
}
64+
} // namespace omath::angles

include/omath/collision/line_tracer.hpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,25 +14,24 @@ namespace omath::collision
1414
Vector3<float> start;
1515
Vector3<float> end;
1616
bool infinite_length = false;
17+
1718
[[nodiscard]]
18-
Vector3<float> DirectionVector() const;
19+
Vector3<float> direction_vector() const;
1920

2021
[[nodiscard]]
21-
Vector3<float> DirectionVectorNormalized() const;
22+
Vector3<float> direction_vector_normalized() const;
2223
};
2324
class LineTracer
2425
{
2526
public:
2627
LineTracer() = delete;
2728

28-
2929
[[nodiscard]]
30-
static bool CanTraceLine(const Ray& ray, const Triangle<Vector3<float>>& triangle);
31-
30+
static bool can_trace_line(const Ray& ray, const Triangle<Vector3<float>>& triangle);
3231

3332
// Realization of Möller–Trumbore intersection algorithm
3433
// https://en.wikipedia.org/wiki/M%C3%B6ller%E2%80%93Trumbore_intersection_algorithm
3534
[[nodiscard]]
36-
static Vector3<float> GetRayHitPoint(const Ray& ray, const Triangle<Vector3<float>>& triangle);
35+
static Vector3<float> get_ray_hit_point(const Ray& ray, const Triangle<Vector3<float>>& triangle);
3736
};
38-
}
37+
} // namespace omath::collision

0 commit comments

Comments
 (0)