Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
Skyward Boardcore
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Avionics
Software Development
Skyward Boardcore
Commits
00b57387
Commit
00b57387
authored
1 year ago
by
Alberto Nidasio
Browse files
Options
Downloads
Patches
Plain Diff
tmp
parent
d33b4859
Branches
Branches containing commit
No related tags found
1 merge request
!233
Implement custom units
Pipeline
#7454
failed
1 year ago
Stage: build
Stage: test
Stage: lint
Changes
2
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/shared/units/Angle.h
+1
-4
1 addition, 4 deletions
src/shared/units/Angle.h
src/shared/units/Units.h
+12
-5
12 additions, 5 deletions
src/shared/units/Units.h
with
13 additions
and
9 deletions
src/shared/units/Angle.h
+
1
−
4
View file @
00b57387
...
...
@@ -34,10 +34,7 @@ namespace Angle
{
template
<
class
Ratio
=
std
::
ratio
<
1
>
>
class
Angle
:
public
Unit
<
Ratio
>
{
using
Unit
<
Ratio
>::
Unit
;
};
using
Angle
=
Unit
<
UnitKind
::
Angle
,
Ratio
>
;
using
Degree
=
Angle
<>
;
// Angle in degrees
using
Radian
=
// Angle in radians
...
...
This diff is collapsed.
Click to expand it.
src/shared/units/Units.h
+
12
−
5
View file @
00b57387
...
...
@@ -32,14 +32,20 @@ namespace Boardcore
namespace
Units
{
template
<
class
Ratio
=
std
::
ratio
<
1
>
>
enum
class
UnitKind
{
Angle
,
Length
};
template
<
UnitKind
Kind
,
class
Ratio
=
std
::
ratio
<
1
>
>
// Base class to implement custom measurement units logic.
class
Unit
{
public:
Unit
(
float
val
)
:
_value
(
val
){};
template
<
class
FromRatio
>
constexpr
explicit
Unit
(
Unit
<
FromRatio
>
const
&
from
)
constexpr
explicit
Unit
(
Unit
<
Kind
,
FromRatio
>
const
&
from
)
:
_value
(
from
.
template
value
<
Ratio
>())
{
}
...
...
@@ -67,10 +73,11 @@ private:
};
// Sum, Subtraction, Multiplication, Division
template
<
class
DerivedUnit
>
constexpr
auto
operator
+
(
const
DerivedUnit
&
lhs
,
const
DerivedUnit
&
rhs
)
template
<
UnitKind
Kind
,
class
Ratio
>
constexpr
auto
operator
+
(
const
Unit
<
Kind
,
Ratio
>
&
lhs
,
const
Unit
<
Kind
,
Ratio
>
&
rhs
)
{
return
Derived
Unit
(
lhs
.
template
value
()
+
rhs
.
template
value
());
return
Unit
(
lhs
.
template
value
()
+
rhs
.
template
value
());
}
template
<
class
DerivedUnit
>
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment