-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add
STANDARD_GRAVITY
Constant (#348)
It took me a little while to figure out exactly what I wanted to do here. Initially, I was going to _deprecate_ the standard gravity unit. Then I realized we need it to define certain other units, such as the correspondence between "pounds" as a force and a mass --- and I didn't want to introduce a circular dependency between `:units` and `:constants`. Then I was going to deprecate only the _quantity maker_, `standard_gravity`. But then I realized it would be weird to create a situation where certain units have quantity makers, and certain other ones don't. In the end, I think the right move is to just provide standard gravity as a new constant. This is the preferred way to interact with it, but the old ways will still be there for the foreseeable future. Follow-on to #90.
- Loading branch information
Showing
4 changed files
with
69 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// Copyright 2024 Aurora Operations, Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#include "au/constant.hh" | ||
#include "au/units/standard_gravity.hh" | ||
|
||
namespace au { | ||
|
||
constexpr auto STANDARD_GRAVITY = make_constant(StandardGravity{}); | ||
|
||
} // namespace au |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// Copyright 2024 Aurora Operations, Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#include "au/constants/standard_gravity.hh" | ||
|
||
#include "au/testing.hh" | ||
#include "au/units/meters.hh" | ||
#include "au/units/seconds.hh" | ||
#include "gtest/gtest.h" | ||
|
||
namespace au { | ||
namespace { | ||
|
||
using ::testing::StrEq; | ||
|
||
TEST(StandardGravity, HasExpectedValue) { | ||
// g_0 = 9.80665 m/s^2 | ||
|
||
// Test approximate value (guard against powers-of-10 type errors). | ||
constexpr auto defining_units = meters / pow<2>(seconds); | ||
constexpr auto val = defining_units(9.80665); | ||
constexpr auto err = defining_units(0.00001); | ||
EXPECT_THAT(STANDARD_GRAVITY.as<double>(defining_units), IsNear(val, err)); | ||
|
||
// Test exact value. | ||
EXPECT_THAT(STANDARD_GRAVITY.in<int>(defining_units / pow<5>(mag<10>())), | ||
SameTypeAndValue(980'665)); | ||
} | ||
|
||
TEST(StandardGravity, HasExpectedLabel) { EXPECT_THAT(unit_label(STANDARD_GRAVITY), StrEq("g_0")); } | ||
|
||
} // namespace | ||
} // namespace au |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters