diff options
author | Samuel Freilich <sfreilich@google.com> | 2022-03-04 11:25:11 -0800 |
---|---|---|
committer | Copybara-Service <copybara-worker@google.com> | 2022-03-04 11:25:41 -0800 |
commit | 8628205a2c2ff704f89f8d9cbab05e8732d4a480 (patch) | |
tree | 457063e4031a992aba70e5a75e2925599c1b3c59 | |
parent | b5393869c12fc4a485b91bf8acf244c140c8f182 (diff) | |
download | ink-stroke-modeler-8628205a2c2ff704f89f8d9cbab05e8732d4a480.tar.gz |
Fix some build warnings and some errors under GCC
This involved fixing three types of issues:
1. warning: control reaches end of non-void function
These were instances of exhaustive switch statements with nothing following to handle invalid values. Even if your switch is exhaustive, it's possible for an enum type to have a value that's not one of the specific enum values and thus not hit any of the cases in the switch statement. If that causes execution to hit the end of a non-void function without a return statement, that's undefined behavior. See https://abseil.io/tips/147.
This was a real (though hopefully irrelevant) bug in our handling of invalid input in `StrokeModeler::Update` and the output operator for `Input::EventType`.
2. warning: comparison of integer expressions of different signedness
Comparing unsigned and signed integer types does not work as you'd expect numeric comparisons between the two numbers in question to work, since the unsigned value gets naively cast to signed. Most of the cases of the warning cropping up were due to looping from zero to the size of a container, where the container size type is unsigned. In those cases, I use the container size type I'm comparing against, replacing:
`for(int i = 0; i < container.size(); i++)`
With:
`for(decltype(container.size()) i = 0; i < container.size(); i++)`
In a few cases, we're comparing an unsigned container size type with a user-provided int, which seems like a real bug. In those cases, I changed the logic to explicitly check for negative values, replacing:
`if (x < container.size())`
With:
`if (x < 0 || (uint) x < container.size())`
3. error: converting to 'ink::stroke_model::Duration' from initializer list would use explicit constructor
(Similar for Time.)
This is showing up in GCC in cases like:
```
const KalmanPredictorParams params{
...
.prediction_interval{1}}
```
Here we have a struct being initialized with aggregate initialization using designated initializers:
https://en.cppreference.com/w/cpp/language/aggregate_initialization
"Each direct non-static data member named by the designated initializer is initialized from the corresponding brace-or-equals initializer that follows the designator. Narrowing conversions are prohibited."
So here we should be initializing from the brace initializer. This is a class type and there's no equals sign, so it's direct list initialization:
https://en.cppreference.com/w/cpp/language/list_initialization
And that should allow explicit constructors. This is a known bug in GCC:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=91319
But that can be worked around by being explicit about those types in the aggregate initialization, replacing something like:
`{.time{1}}`
With something like:
`{.time{Time(1)}}`
(Sometimes changing that to the copy-list-initializer form with the equals for readability.)
PiperOrigin-RevId: 432492904
-rw-r--r-- | .bazelrc | 6 | ||||
-rw-r--r-- | .github/workflows/cmake-test.yaml | 3 | ||||
-rw-r--r-- | ink_stroke_modeler/internal/prediction/kalman_filter/axis_predictor_test.cc | 3 | ||||
-rw-r--r-- | ink_stroke_modeler/internal/prediction/kalman_predictor.cc | 3 | ||||
-rw-r--r-- | ink_stroke_modeler/internal/prediction/kalman_predictor_test.cc | 2 | ||||
-rw-r--r-- | ink_stroke_modeler/internal/stylus_state_modeler.cc | 6 | ||||
-rw-r--r-- | ink_stroke_modeler/internal/wobble_smoother_test.cc | 2 | ||||
-rw-r--r-- | ink_stroke_modeler/params_test.cc | 26 | ||||
-rw-r--r-- | ink_stroke_modeler/stroke_modeler.cc | 1 | ||||
-rw-r--r-- | ink_stroke_modeler/stroke_modeler_test.cc | 394 | ||||
-rw-r--r-- | ink_stroke_modeler/types.h | 1 | ||||
-rw-r--r-- | ink_stroke_modeler/types_test.cc | 2 |
12 files changed, 230 insertions, 219 deletions
@@ -1,6 +1,2 @@ -# Set up to use C++17 and Clang. This isn't a full CC toolchain configuration, -# but getting it to build somehow is a good first step, since the plan -# is not to primarily use Bazel externally (planning to use Gradle, which -# is favored by AOSP). -build --repo_env=CC=clang +# Set up to use C++17. build --cxxopt='-std=c++17'
\ No newline at end of file diff --git a/.github/workflows/cmake-test.yaml b/.github/workflows/cmake-test.yaml index d6f2549..405a230 100644 --- a/.github/workflows/cmake-test.yaml +++ b/.github/workflows/cmake-test.yaml @@ -6,9 +6,6 @@ jobs: cmake_test: runs-on: ubuntu-latest - env: - CXX: clang++ - steps: - uses: actions/checkout@v3 diff --git a/ink_stroke_modeler/internal/prediction/kalman_filter/axis_predictor_test.cc b/ink_stroke_modeler/internal/prediction/kalman_filter/axis_predictor_test.cc index 6818be7..40ba9f4 100644 --- a/ink_stroke_modeler/internal/prediction/kalman_filter/axis_predictor_test.cc +++ b/ink_stroke_modeler/internal/prediction/kalman_filter/axis_predictor_test.cc @@ -41,7 +41,8 @@ struct DataSet { void ValidateAxisPredictor(AxisPredictor* predictor, const DataSet& data) { predictor->Reset(); predictor->Update(data.initial_observation); - for (int i = 0; i < data.observation.size(); i++) { + for (decltype(data.observation.size()) i = 0; i < data.observation.size(); + i++) { predictor->Update(data.observation[i]); EXPECT_NEAR(data.position[i], predictor->GetPosition(), 0.0001); EXPECT_NEAR(data.velocity[i], predictor->GetVelocity(), 0.0001); diff --git a/ink_stroke_modeler/internal/prediction/kalman_predictor.cc b/ink_stroke_modeler/internal/prediction/kalman_predictor.cc index ba202dc..ab24540 100644 --- a/ink_stroke_modeler/internal/prediction/kalman_predictor.cc +++ b/ink_stroke_modeler/internal/prediction/kalman_predictor.cc @@ -57,7 +57,8 @@ void KalmanPredictor::Reset() { void KalmanPredictor::Update(Vec2 position, Time time) { last_position_received_ = position; sample_times_.push_back(time); - if (sample_times_.size() > predictor_params_.max_time_samples) + if (predictor_params_.max_time_samples < 0 || + sample_times_.size() > (uint)predictor_params_.max_time_samples) sample_times_.pop_front(); x_predictor_.Update(position.x); diff --git a/ink_stroke_modeler/internal/prediction/kalman_predictor_test.cc b/ink_stroke_modeler/internal/prediction/kalman_predictor_test.cc index 14babc7..66bac66 100644 --- a/ink_stroke_modeler/internal/prediction/kalman_predictor_test.cc +++ b/ink_stroke_modeler/internal/prediction/kalman_predictor_test.cc @@ -36,7 +36,7 @@ const KalmanPredictorParams kDefaultKalmanParams{ .process_noise = .00026458, .measurement_noise = .026458, .min_catchup_velocity = .01, - .prediction_interval{1. / 60}, + .prediction_interval = Duration(1. / 60), .confidence_params{.max_estimation_distance = .04, .min_travel_speed = 3, .max_travel_speed = 15, diff --git a/ink_stroke_modeler/internal/stylus_state_modeler.cc b/ink_stroke_modeler/internal/stylus_state_modeler.cc index 1cad85a..e7c1bbc 100644 --- a/ink_stroke_modeler/internal/stylus_state_modeler.cc +++ b/ink_stroke_modeler/internal/stylus_state_modeler.cc @@ -38,7 +38,8 @@ void StylusStateModeler::Update(Vec2 position, const StylusState &state) { positions_and_states_.push_back({position, state}); - if (positions_and_states_.size() > params_.max_input_samples) { + if (params_.max_input_samples < 0 || + positions_and_states_.size() > (uint)params_.max_input_samples) { positions_and_states_.pop_front(); } } @@ -66,7 +67,8 @@ StylusState StylusStateModeler::Query(Vec2 position) const { int closest_segment = -1; float min_distance = std::numeric_limits<float>::infinity(); float interp_value = 0; - for (int i = 0; i < positions_and_states_.size() - 1; ++i) { + for (decltype(positions_and_states_.size()) i = 0; + i < positions_and_states_.size() - 1; ++i) { const Vec2 segment_start = positions_and_states_[i].position; const Vec2 segment_end = positions_and_states_[i + 1].position; float param = NearestPointOnSegment(segment_start, segment_end, position); diff --git a/ink_stroke_modeler/internal/wobble_smoother_test.cc b/ink_stroke_modeler/internal/wobble_smoother_test.cc index 64a8965..f31ac9d 100644 --- a/ink_stroke_modeler/internal/wobble_smoother_test.cc +++ b/ink_stroke_modeler/internal/wobble_smoother_test.cc @@ -25,7 +25,7 @@ namespace stroke_model { namespace { const WobbleSmootherParams kDefaultParams{ - .timeout{.04}, .speed_floor = 1.31, .speed_ceiling = 1.44}; + .timeout = Duration(.04), .speed_floor = 1.31, .speed_ceiling = 1.44}; TEST(WobbleSmootherTest, SlowStraightLine) { // The line moves at 1 cm/s, which is below the floor of 1.31 cm/s. diff --git a/ink_stroke_modeler/params_test.cc b/ink_stroke_modeler/params_test.cc index 1f53aa8..113d038 100644 --- a/ink_stroke_modeler/params_test.cc +++ b/ink_stroke_modeler/params_test.cc @@ -32,7 +32,7 @@ const KalmanPredictorParams kGoodKalmanParams{ .min_catchup_velocity = 1, .acceleration_weight = -1, .jerk_weight = 200, - .prediction_interval{1}, + .prediction_interval{Duration(1)}, .confidence_params{.desired_number_of_samples = 10, .max_estimation_distance = 1, .min_travel_speed = 6, @@ -42,7 +42,7 @@ const KalmanPredictorParams kGoodKalmanParams{ const StrokeModelParams kGoodStrokeModelParams{ .wobble_smoother_params{ - .timeout{.5}, .speed_floor = 1, .speed_ceiling = 20}, + .timeout = Duration(.5), .speed_floor = 1, .speed_ceiling = 20}, .position_modeler_params{.spring_mass_constant = .2, .drag_constant = 4}, .sampling_params{.min_output_rate = 3, .end_of_stroke_stopping_distance = 1e-6, @@ -96,23 +96,25 @@ TEST(ParamsTest, ValidateStylusStateModelerParams) { } TEST(ParamsTest, ValidateWobbleSmootherParams) { - EXPECT_TRUE(ValidateWobbleSmootherParams( - {.timeout{1}, .speed_floor = 2, .speed_ceiling = 3}) - .ok()); - EXPECT_TRUE(ValidateWobbleSmootherParams( - {.timeout{0}, .speed_floor = 0, .speed_ceiling = 0}) - .ok()); + EXPECT_TRUE( + ValidateWobbleSmootherParams( + {.timeout = Duration(1), .speed_floor = 2, .speed_ceiling = 3}) + .ok()); + EXPECT_TRUE( + ValidateWobbleSmootherParams( + {.timeout = Duration(0), .speed_floor = 0, .speed_ceiling = 0}) + .ok()); EXPECT_EQ(ValidateWobbleSmootherParams( - {.timeout{-1}, .speed_floor = 2, .speed_ceiling = 5}) + {.timeout = Duration(-1), .speed_floor = 2, .speed_ceiling = 5}) .code(), absl::StatusCode::kInvalidArgument); EXPECT_EQ(ValidateWobbleSmootherParams( - {.timeout{1}, .speed_floor = -2, .speed_ceiling = 1}) + {.timeout = Duration(1), .speed_floor = -2, .speed_ceiling = 1}) .code(), absl::StatusCode::kInvalidArgument); EXPECT_EQ(ValidateWobbleSmootherParams( - {.timeout{1}, .speed_floor = 7, .speed_ceiling = 4}) + {.timeout = Duration(1), .speed_floor = 7, .speed_ceiling = 4}) .code(), absl::StatusCode::kInvalidArgument); } @@ -231,7 +233,7 @@ TEST(ParamsTest, ValidateStrokeModelParams) { { auto bad_params = kGoodStrokeModelParams; bad_params.prediction_params = - KalmanPredictorParams{.prediction_interval{-1}}; + KalmanPredictorParams{.prediction_interval = Duration(-1)}; EXPECT_EQ(ValidateStrokeModelParams(bad_params).code(), absl::StatusCode::kInvalidArgument); } diff --git a/ink_stroke_modeler/stroke_modeler.cc b/ink_stroke_modeler/stroke_modeler.cc index f73a11d..917d2d6 100644 --- a/ink_stroke_modeler/stroke_modeler.cc +++ b/ink_stroke_modeler/stroke_modeler.cc @@ -121,6 +121,7 @@ absl::StatusOr<std::vector<Result>> StrokeModeler::Update(const Input &input) { case Input::EventType::kUp: return ProcessUpEvent(input); } + return absl::InvalidArgumentError("Invalid EventType."); } absl::StatusOr<std::vector<Result>> StrokeModeler::Predict() const { diff --git a/ink_stroke_modeler/stroke_modeler_test.cc b/ink_stroke_modeler/stroke_modeler_test.cc index 531b12b..00f1dba 100644 --- a/ink_stroke_modeler/stroke_modeler_test.cc +++ b/ink_stroke_modeler/stroke_modeler_test.cc @@ -36,7 +36,7 @@ constexpr float kTol = 1e-4; // These parameters use cm for distance and seconds for time. const StrokeModelParams kDefaultParams{ .wobble_smoother_params{ - .timeout{.04}, .speed_floor = 1.31, .speed_ceiling = 1.44}, + .timeout = Duration(.04), .speed_floor = 1.31, .speed_ceiling = 1.44}, .position_modeler_params{.spring_mass_constant = 11.f / 32400, .drag_constant = 72.f}, .sampling_params{.min_output_rate = 180, @@ -81,9 +81,10 @@ TEST(StrokeModelerTest, InputRateSlowerThanMinOutputRate) { .position = {3, 4}, .time = time}); ASSERT_TRUE(results.ok()); - EXPECT_THAT(*results, - ElementsAre(ResultNear( - {.position = {3, 4}, .velocity = {0, 0}, .time{0}}, kTol))); + EXPECT_THAT( + *results, + ElementsAre(ResultNear( + {.position = {3, 4}, .velocity = {0, 0}, .time = Time(0)}, kTol))); results = modeler.Predict(); ASSERT_TRUE(results.ok()); @@ -96,66 +97,66 @@ TEST(StrokeModelerTest, InputRateSlowerThanMinOutputRate) { ASSERT_TRUE(results.ok()); EXPECT_THAT(*results, ElementsAre(ResultNear({.position = {3.0019, 4.0019}, .velocity = {0.4007, 0.4007}, - .time{0.0048}}, + .time = Time(0.0048)}, kTol), ResultNear({.position = {3.0069, 4.0069}, .velocity = {1.0381, 1.0381}, - .time{0.0095}}, + .time = Time(0.0095)}, kTol), ResultNear({.position = {3.0154, 4.0154}, .velocity = {1.7883, 1.7883}, - .time{0.0143}}, + .time = Time(0.0143)}, kTol), ResultNear({.position = {3.0276, 4.0276}, .velocity = {2.5626, 2.5626}, - .time{0.0190}}, + .time = Time(0.0190)}, kTol), ResultNear({.position = {3.0433, 4.0433}, .velocity = {3.3010, 3.3010}, - .time{0.0238}}, + .time = Time(0.0238)}, kTol), ResultNear({.position = {3.0622, 4.0622}, .velocity = {3.9665, 3.9665}, - .time{0.0286}}, + .time = Time(0.0286)}, kTol), ResultNear({.position = {3.0838, 4.0838}, .velocity = {4.5397, 4.5397}, - .time{0.0333}}, + .time = Time(0.0333)}, kTol))); results = modeler.Predict(); ASSERT_TRUE(results.ok()); EXPECT_THAT(*results, ElementsAre(ResultNear({.position = {3.1095, 4.1095}, .velocity = {4.6253, 4.6253}, - .time{0.0389}}, + .time = Time(0.0389)}, kTol), ResultNear({.position = {3.1331, 4.1331}, .velocity = {4.2563, 4.2563}, - .time{0.0444}}, + .time = Time(0.0444)}, kTol), ResultNear({.position = {3.1534, 4.1534}, .velocity = {3.6479, 3.6479}, - .time{0.0500}}, + .time = Time(0.0500)}, kTol), ResultNear({.position = {3.1698, 4.1698}, .velocity = {2.9512, 2.9512}, - .time{0.0556}}, + .time = Time(0.0556)}, kTol), ResultNear({.position = {3.1824, 4.1824}, .velocity = {2.2649, 2.2649}, - .time{0.0611}}, + .time = Time(0.0611)}, kTol), ResultNear({.position = {3.1915, 4.1915}, .velocity = {1.6473, 1.6473}, - .time{0.0667}}, + .time = Time(0.0667)}, kTol), ResultNear({.position = {3.1978, 4.1978}, .velocity = {1.1269, 1.1269}, - .time{0.0722}}, + .time = Time(0.0722)}, kTol), ResultNear({.position = {3.1992, 4.1992}, .velocity = {1.0232, 1.0232}, - .time{0.0736}}, + .time = Time(0.0736)}, kTol))); time += kDeltaTime; @@ -165,66 +166,66 @@ TEST(StrokeModelerTest, InputRateSlowerThanMinOutputRate) { ASSERT_TRUE(results.ok()); EXPECT_THAT(*results, ElementsAre(ResultNear({.position = {3.1086, 4.1058}, .velocity = {5.2142, 4.6131}, - .time{0.0381}}, + .time = Time(0.0381)}, kTol), ResultNear({.position = {3.1368, 4.1265}, .velocity = {5.9103, 4.3532}, - .time{0.0429}}, + .time = Time(0.0429)}, kTol), ResultNear({.position = {3.1681, 4.1450}, .velocity = {6.5742, 3.8917}, - .time{0.0476}}, + .time = Time(0.0476)}, kTol), ResultNear({.position = {3.2022, 4.1609}, .velocity = {7.1724, 3.3285}, - .time{0.0524}}, + .time = Time(0.0524)}, kTol), ResultNear({.position = {3.2388, 4.1739}, .velocity = {7.6876, 2.7361}, - .time{0.0571}}, + .time = Time(0.0571)}, kTol), ResultNear({.position = {3.2775, 4.1842}, .velocity = {8.1138, 2.1640}, - .time{0.0619}}, + .time = Time(0.0619)}, kTol), ResultNear({.position = {3.3177, 4.1920}, .velocity = {8.4531, 1.6436}, - .time{0.0667}}, + .time = Time(0.0667)}, kTol))); results = modeler.Predict(); ASSERT_TRUE(results.ok()); EXPECT_THAT(*results, ElementsAre(ResultNear({.position = {3.3625, 4.1982}, .velocity = {8.0545, 1.1165}, - .time{0.0722}}, + .time = Time(0.0722)}, kTol), ResultNear({.position = {3.4018, 4.2021}, .velocity = {7.0831, 0.6987}, - .time{0.0778}}, + .time = Time(0.0778)}, kTol), ResultNear({.position = {3.4344, 4.2043}, .velocity = {5.8564, 0.3846}, - .time{0.0833}}, + .time = Time(0.0833)}, kTol), ResultNear({.position = {3.4598, 4.2052}, .velocity = {4.5880, 0.1611}, - .time{0.0889}}, + .time = Time(0.0889)}, kTol), ResultNear({.position = {3.4788, 4.2052}, .velocity = {3.4098, 0.0124}, - .time{0.0944}}, + .time = Time(0.0944)}, kTol), ResultNear({.position = {3.4921, 4.2048}, .velocity = {2.3929, -0.0780}, - .time{0.1000}}, + .time = Time(0.1000)}, kTol), ResultNear({.position = {3.4976, 4.2045}, .velocity = {1.9791, -0.1015}, - .time{0.1028}}, + .time = Time(0.1028)}, kTol), ResultNear({.position = {3.5001, 4.2044}, .velocity = {1.7911, -0.1098}, - .time{0.1042}}, + .time = Time(0.1042)}, kTol))); time += kDeltaTime; @@ -236,59 +237,59 @@ TEST(StrokeModelerTest, InputRateSlowerThanMinOutputRate) { ASSERT_TRUE(results.ok()); EXPECT_THAT(*results, ElementsAre(ResultNear({.position = {3.3583, 4.1996}, .velocity = {8.5122, 1.5925}, - .time{0.0714}}, + .time = Time(0.0714)}, kTol), ResultNear({.position = {3.3982, 4.2084}, .velocity = {8.3832, 1.8534}, - .time{0.0762}}, + .time = Time(0.0762)}, kTol), ResultNear({.position = {3.4369, 4.2194}, .velocity = {8.1393, 2.3017}, - .time{0.0810}}, + .time = Time(0.0810)}, kTol), ResultNear({.position = {3.4743, 4.2329}, .velocity = {7.8362, 2.8434}, - .time{0.0857}}, + .time = Time(0.0857)}, kTol), ResultNear({.position = {3.5100, 4.2492}, .velocity = {7.5143, 3.4101}, - .time{0.0905}}, + .time = Time(0.0905)}, kTol), ResultNear({.position = {3.5443, 4.2680}, .velocity = {7.2016, 3.9556}, - .time{0.0952}}, + .time = Time(0.0952)}, kTol), ResultNear({.position = {3.5773, 4.2892}, .velocity = {6.9159, 4.4505}, - .time{0.1000}}, + .time = Time(0.1000)}, kTol), ResultNear({.position = {3.6115, 4.3141}, .velocity = {6.1580, 4.4832}, - .time{0.1056}}, + .time = Time(0.1056)}, kTol), ResultNear({.position = {3.6400, 4.3369}, .velocity = {5.1434, 4.0953}, - .time{0.1111}}, + .time = Time(0.1111)}, kTol), ResultNear({.position = {3.6626, 4.3563}, .velocity = {4.0671, 3.4902}, - .time{0.1167}}, + .time = Time(0.1167)}, kTol), ResultNear({.position = {3.6796, 4.3719}, .velocity = {3.0515, 2.8099}, - .time{0.1222}}, + .time = Time(0.1222)}, kTol), ResultNear({.position = {3.6916, 4.3838}, .velocity = {2.1648, 2.1462}, - .time{0.1278}}, + .time = Time(0.1278)}, kTol), ResultNear({.position = {3.6996, 4.3924}, .velocity = {1.4360, 1.5529}, - .time{0.1333}}, + .time = Time(0.1333)}, kTol), ResultNear({.position = {3.7028, 4.3960}, .velocity = {1.1520, 1.3044}, - .time{0.1361}}, + .time = Time(0.1361)}, kTol))); // The stroke is finished, so there's nothing to predict anymore. @@ -308,9 +309,10 @@ TEST(StrokeModelerTest, InputRateFasterThanMinOutputRate) { .position = {5, -3}, .time = time}); ASSERT_TRUE(results.ok()); - EXPECT_THAT(*results, - ElementsAre(ResultNear( - {.position = {5, -3}, .velocity = {0, 0}, .time{2}}, kTol))); + EXPECT_THAT( + *results, + ElementsAre(ResultNear( + {.position = {5, -3}, .velocity = {0, 0}, .time = Time(2)}, kTol))); results = modeler.Predict(); ASSERT_TRUE(results.ok()); @@ -321,49 +323,48 @@ TEST(StrokeModelerTest, InputRateFasterThanMinOutputRate) { .position = {5, -3.1}, .time = time}); ASSERT_TRUE(results.ok()); - EXPECT_THAT( - *results, - ElementsAre(ResultNear( - {.position = {5, -3.0033}, .velocity = {0, -0.9818}, .time{2.0033}}, - kTol))); + EXPECT_THAT(*results, ElementsAre(ResultNear({.position = {5, -3.0033}, + .velocity = {0, -0.9818}, + .time = Time(2.0033)}, + kTol))); results = modeler.Predict(); ASSERT_TRUE(results.ok()); EXPECT_THAT(*results, ElementsAre(ResultNear({.position = {5, -3.0153}, .velocity = {0, -2.1719}, - .time{2.0089}}, + .time = Time(2.0089)}, kTol), ResultNear({.position = {5, -3.0303}, .velocity = {0, -2.6885}, - .time{2.0144}}, + .time = Time(2.0144)}, kTol), ResultNear({.position = {5, -3.0456}, .velocity = {0, -2.7541}, - .time{2.0200}}, + .time = Time(2.0200)}, kTol), ResultNear({.position = {5, -3.0597}, .velocity = {0, -2.5430}, - .time{2.0256}}, + .time = Time(2.0256)}, kTol), ResultNear({.position = {5, -3.0718}, .velocity = {0, -2.1852}, - .time{2.0311}}, + .time = Time(2.0311)}, kTol), ResultNear({.position = {5, -3.0817}, .velocity = {0, -1.7719}, - .time{2.0367}}, + .time = Time(2.0367)}, kTol), ResultNear({.position = {5, -3.0893}, .velocity = {0, -1.3628}, - .time{2.0422}}, + .time = Time(2.0422)}, kTol), ResultNear({.position = {5, -3.0948}, .velocity = {0, -0.9934}, - .time{2.0478}}, + .time = Time(2.0478)}, kTol), ResultNear({.position = {5, -3.0986}, .velocity = {0, -0.6815}, - .time{2.0533}}, + .time = Time(2.0533)}, kTol))); time += kDeltaTime; @@ -373,46 +374,46 @@ TEST(StrokeModelerTest, InputRateFasterThanMinOutputRate) { ASSERT_TRUE(results.ok()); EXPECT_THAT(*results, ElementsAre(ResultNear({.position = {4.9992, -3.0114}, .velocity = {-0.2455, -2.4322}, - .time{2.0067}}, + .time = Time(2.0067)}, kTol))); results = modeler.Predict(); ASSERT_TRUE(results.ok()); EXPECT_THAT(*results, ElementsAre(ResultNear({.position = {4.9962, -3.0344}, .velocity = {-0.5430, -4.1368}, - .time{2.0122}}, + .time = Time(2.0122)}, kTol), ResultNear({.position = {4.9924, -3.0609}, .velocity = {-0.6721, -4.7834}, - .time{2.0178}}, + .time = Time(2.0178)}, kTol), ResultNear({.position = {4.9886, -3.0873}, .velocity = {-0.6885, -4.7365}, - .time{2.0233}}, + .time = Time(2.0233)}, kTol), ResultNear({.position = {4.9851, -3.1110}, .velocity = {-0.6358, -4.2778}, - .time{2.0289}}, + .time = Time(2.0289)}, kTol), ResultNear({.position = {4.9820, -3.1311}, .velocity = {-0.5463, -3.6137}, - .time{2.0344}}, + .time = Time(2.0344)}, kTol), ResultNear({.position = {4.9796, -3.1471}, .velocity = {-0.4430, -2.8867}, - .time{2.0400}}, + .time = Time(2.0400)}, kTol), ResultNear({.position = {4.9777, -3.1593}, .velocity = {-0.3407, -2.1881}, - .time{2.0456}}, + .time = Time(2.0456)}, kTol), ResultNear({.position = {4.9763, -3.1680}, .velocity = {-0.2484, -1.5700}, - .time{2.0511}}, + .time = Time(2.0511)}, kTol), ResultNear({.position = {4.9754, -3.1739}, .velocity = {-0.1704, -1.0564}, - .time{2.0567}}, + .time = Time(2.0567)}, kTol))); time += kDeltaTime; @@ -422,46 +423,46 @@ TEST(StrokeModelerTest, InputRateFasterThanMinOutputRate) { ASSERT_TRUE(results.ok()); EXPECT_THAT(*results, ElementsAre(ResultNear({.position = {4.9953, -3.0237}, .velocity = {-1.1603, -3.7004}, - .time{2.0100}}, + .time = Time(2.0100)}, kTol))); results = modeler.Predict(); ASSERT_TRUE(results.ok()); EXPECT_THAT(*results, ElementsAre(ResultNear({.position = {4.9828, -3.0521}, .velocity = {-2.2559, -5.1049}, - .time{2.0156}}, + .time = Time(2.0156)}, kTol), ResultNear({.position = {4.9677, -3.0825}, .velocity = {-2.7081, -5.4835}, - .time{2.0211}}, + .time = Time(2.0211)}, kTol), ResultNear({.position = {4.9526, -3.1115}, .velocity = {-2.7333, -5.2122}, - .time{2.0267}}, + .time = Time(2.0267)}, kTol), ResultNear({.position = {4.9387, -3.1369}, .velocity = {-2.4999, -4.5756}, - .time{2.0322}}, + .time = Time(2.0322)}, kTol), ResultNear({.position = {4.9268, -3.1579}, .velocity = {-2.1326, -3.7776}, - .time{2.0378}}, + .time = Time(2.0378)}, kTol), ResultNear({.position = {4.9173, -3.1743}, .velocity = {-1.7184, -2.9554}, - .time{2.0433}}, + .time = Time(2.0433)}, kTol), ResultNear({.position = {4.9100, -3.1865}, .velocity = {-1.3136, -2.1935}, - .time{2.0489}}, + .time = Time(2.0489)}, kTol), ResultNear({.position = {4.9047, -3.1950}, .velocity = {-0.9513, -1.5369}, - .time{2.0544}}, + .time = Time(2.0544)}, kTol), ResultNear({.position = {4.9011, -3.2006}, .velocity = {-0.6475, -1.0032}, - .time{2.0600}}, + .time = Time(2.0600)}, kTol))); time += kDeltaTime; @@ -471,50 +472,50 @@ TEST(StrokeModelerTest, InputRateFasterThanMinOutputRate) { ASSERT_TRUE(results.ok()); EXPECT_THAT(*results, ElementsAre(ResultNear({.position = {4.9868, -3.0389}, .velocity = {-2.5540, -4.5431}, - .time{2.0133}}, + .time = Time(2.0133)}, kTol))); results = modeler.Predict(); ASSERT_TRUE(results.ok()); EXPECT_THAT(*results, ElementsAre(ResultNear({.position = {4.9636, -3.0687}, .velocity = {-4.1801, -5.3627}, - .time{2.0189}}, + .time = Time(2.0189)}, kTol), ResultNear({.position = {4.9370, -3.0985}, .velocity = {-4.7757, -5.3670}, - .time{2.0244}}, + .time = Time(2.0244)}, kTol), ResultNear({.position = {4.9109, -3.1256}, .velocity = {-4.6989, -4.8816}, - .time{2.0300}}, + .time = Time(2.0300)}, kTol), ResultNear({.position = {4.8875, -3.1486}, .velocity = {-4.2257, -4.1466}, - .time{2.0356}}, + .time = Time(2.0356)}, kTol), ResultNear({.position = {4.8677, -3.1671}, .velocity = {-3.5576, -3.3287}, - .time{2.0411}}, + .time = Time(2.0411)}, kTol), ResultNear({.position = {4.8520, -3.1812}, .velocity = {-2.8333, -2.5353}, - .time{2.0467}}, + .time = Time(2.0467)}, kTol), ResultNear({.position = {4.8401, -3.1914}, .velocity = {-2.1411, -1.8288}, - .time{2.0522}}, + .time = Time(2.0522)}, kTol), ResultNear({.position = {4.8316, -3.1982}, .velocity = {-1.5312, -1.2386}, - .time{2.0578}}, + .time = Time(2.0578)}, kTol), ResultNear({.position = {4.8280, -3.2010}, .velocity = {-1.2786, -1.0053}, - .time{2.0606}}, + .time = Time(2.0606)}, kTol), ResultNear({.position = {4.8272, -3.2017}, .velocity = {-1.2209, -0.9529}, - .time{2.0613}}, + .time = Time(2.0613)}, kTol))); time += kDeltaTime; @@ -524,46 +525,46 @@ TEST(StrokeModelerTest, InputRateFasterThanMinOutputRate) { ASSERT_TRUE(results.ok()); EXPECT_THAT(*results, ElementsAre(ResultNear({.position = {4.9726, -3.0565}, .velocity = {-4.2660, -5.2803}, - .time{2.0167}}, + .time = Time(2.0167)}, kTol))); results = modeler.Predict(); ASSERT_TRUE(results.ok()); EXPECT_THAT(*results, ElementsAre(ResultNear({.position = {4.9381, -3.0894}, .velocity = {-6.2018, -5.9261}, - .time{2.0222}}, + .time = Time(2.0222)}, kTol), ResultNear({.position = {4.9004, -3.1215}, .velocity = {-6.7995, -5.7749}, - .time{2.0278}}, + .time = Time(2.0278)}, kTol), ResultNear({.position = {4.8640, -3.1501}, .velocity = {-6.5400, -5.1591}, - .time{2.0333}}, + .time = Time(2.0333)}, kTol), ResultNear({.position = {4.8319, -3.1741}, .velocity = {-5.7897, -4.3207}, - .time{2.0389}}, + .time = Time(2.0389)}, kTol), ResultNear({.position = {4.8051, -3.1932}, .velocity = {-4.8133, -3.4248}, - .time{2.0444}}, + .time = Time(2.0444)}, kTol), ResultNear({.position = {4.7841, -3.2075}, .velocity = {-3.7898, -2.5759}, - .time{2.0500}}, + .time = Time(2.0500)}, kTol), ResultNear({.position = {4.7683, -3.2176}, .velocity = {-2.8312, -1.8324}, - .time{2.0556}}, + .time = Time(2.0556)}, kTol), ResultNear({.position = {4.7572, -3.2244}, .velocity = {-1.9986, -1.2198}, - .time{2.0611}}, + .time = Time(2.0611)}, kTol), ResultNear({.position = {4.7526, -3.2271}, .velocity = {-1.6580, -0.9805}, - .time{2.0639}}, + .time = Time(2.0639)}, kTol))); time += kDeltaTime; @@ -573,50 +574,50 @@ TEST(StrokeModelerTest, InputRateFasterThanMinOutputRate) { ASSERT_TRUE(results.ok()); EXPECT_THAT(*results, ElementsAre(ResultNear({.position = {4.9529, -3.0778}, .velocity = {-5.9184, -6.4042}, - .time{2.0200}}, + .time = Time(2.0200)}, kTol))); results = modeler.Predict(); ASSERT_TRUE(results.ok()); EXPECT_THAT(*results, ElementsAre(ResultNear({.position = {4.9101, -3.1194}, .velocity = {-7.6886, -7.4784}, - .time{2.0256}}, + .time = Time(2.0256)}, kTol), ResultNear({.position = {4.8654, -3.1607}, .velocity = {-8.0518, -7.4431}, - .time{2.0311}}, + .time = Time(2.0311)}, kTol), ResultNear({.position = {4.8235, -3.1982}, .velocity = {-7.5377, -6.7452}, - .time{2.0367}}, + .time = Time(2.0367)}, kTol), ResultNear({.position = {4.7872, -3.2299}, .velocity = {-6.5440, -5.7133}, - .time{2.0422}}, + .time = Time(2.0422)}, kTol), ResultNear({.position = {4.7574, -3.2553}, .velocity = {-5.3529, -4.5748}, - .time{2.0478}}, + .time = Time(2.0478)}, kTol), ResultNear({.position = {4.7344, -3.2746}, .velocity = {-4.1516, -3.4758}, - .time{2.0533}}, + .time = Time(2.0533)}, kTol), ResultNear({.position = {4.7174, -3.2885}, .velocity = {-3.0534, -2.5004}, - .time{2.0589}}, + .time = Time(2.0589)}, kTol), ResultNear({.position = {4.7056, -3.2979}, .velocity = {-2.1169, -1.6879}, - .time{2.0644}}, + .time = Time(2.0644)}, kTol), ResultNear({.position = {4.7030, -3.3000}, .velocity = {-1.9283, -1.5276}, - .time{2.0658}}, + .time = Time(2.0658)}, kTol), ResultNear({.position = {4.7017, -3.3010}, .velocity = {-1.8380, -1.4512}, - .time{2.0665}}, + .time = Time(2.0665)}, kTol))); time += kDeltaTime; @@ -626,46 +627,46 @@ TEST(StrokeModelerTest, InputRateFasterThanMinOutputRate) { ASSERT_TRUE(results.ok()); EXPECT_THAT(*results, ElementsAre(ResultNear({.position = {4.9288, -3.1046}, .velocity = {-7.2260, -8.0305}, - .time{2.0233}}, + .time = Time(2.0233)}, kTol))); results = modeler.Predict(); ASSERT_TRUE(results.ok()); EXPECT_THAT(*results, ElementsAre(ResultNear({.position = {4.8816, -3.1582}, .velocity = {-8.4881, -9.6525}, - .time{2.0289}}, + .time = Time(2.0289)}, kTol), ResultNear({.position = {4.8345, -3.2124}, .velocity = {-8.4738, -9.7482}, - .time{2.0344}}, + .time = Time(2.0344)}, kTol), ResultNear({.position = {4.7918, -3.2619}, .velocity = {-7.6948, -8.9195}, - .time{2.0400}}, + .time = Time(2.0400)}, kTol), ResultNear({.position = {4.7555, -3.3042}, .velocity = {-6.5279, -7.6113}, - .time{2.0456}}, + .time = Time(2.0456)}, kTol), ResultNear({.position = {4.7264, -3.3383}, .velocity = {-5.2343, -6.1345}, - .time{2.0511}}, + .time = Time(2.0511)}, kTol), ResultNear({.position = {4.7043, -3.3643}, .velocity = {-3.9823, -4.6907}, - .time{2.0567}}, + .time = Time(2.0567)}, kTol), ResultNear({.position = {4.6884, -3.3832}, .velocity = {-2.8691, -3.3980}, - .time{2.0622}}, + .time = Time(2.0622)}, kTol), ResultNear({.position = {4.6776, -3.3961}, .velocity = {-1.9403, -2.3135}, - .time{2.0678}}, + .time = Time(2.0678)}, kTol), ResultNear({.position = {4.6752, -3.3990}, .velocity = {-1.7569, -2.0983}, - .time{2.0692}}, + .time = Time(2.0692)}, kTol))); time += kDeltaTime; @@ -675,46 +676,46 @@ TEST(StrokeModelerTest, InputRateFasterThanMinOutputRate) { ASSERT_TRUE(results.ok()); EXPECT_THAT(*results, ElementsAre(ResultNear({.position = {4.9022, -3.1387}, .velocity = {-7.9833, -10.2310}, - .time{2.0267}}, + .time = Time(2.0267)}, kTol))); results = modeler.Predict(); ASSERT_TRUE(results.ok()); EXPECT_THAT(*results, ElementsAre(ResultNear({.position = {4.8549, -3.2079}, .velocity = {-8.5070, -12.4602}, - .time{2.0322}}, + .time = Time(2.0322)}, kTol), ResultNear({.position = {4.8102, -3.2783}, .velocity = {-8.0479, -12.6650}, - .time{2.0378}}, + .time = Time(2.0378)}, kTol), ResultNear({.position = {4.7711, -3.3429}, .velocity = {-7.0408, -11.6365}, - .time{2.0433}}, + .time = Time(2.0433)}, kTol), ResultNear({.position = {4.7389, -3.3983}, .velocity = {-5.7965, -9.9616}, - .time{2.0489}}, + .time = Time(2.0489)}, kTol), ResultNear({.position = {4.7137, -3.4430}, .velocity = {-4.5230, -8.0510}, - .time{2.0544}}, + .time = Time(2.0544)}, kTol), ResultNear({.position = {4.6951, -3.4773}, .velocity = {-3.3477, -6.1727}, - .time{2.0600}}, + .time = Time(2.0600)}, kTol), ResultNear({.position = {4.6821, -3.5022}, .velocity = {-2.3381, -4.4846}, - .time{2.0656}}, + .time = Time(2.0656)}, kTol), ResultNear({.position = {4.6737, -3.5192}, .velocity = {-1.5199, -3.0641}, - .time{2.0711}}, + .time = Time(2.0711)}, kTol), ResultNear({.position = {4.6718, -3.5231}, .velocity = {-1.3626, -2.7813}, - .time{2.0725}}, + .time = Time(2.0725)}, kTol))); time += kDeltaTime; @@ -726,43 +727,43 @@ TEST(StrokeModelerTest, InputRateFasterThanMinOutputRate) { ASSERT_TRUE(results.ok()); EXPECT_THAT(*results, ElementsAre(ResultNear({.position = {4.8753, -3.1797}, .velocity = {-8.0521, -12.3049}, - .time{2.0300}}, + .time = Time(2.0300)}, kTol), ResultNear({.position = {4.8325, -3.2589}, .velocity = {-7.7000, -14.2607}, - .time{2.0356}}, + .time = Time(2.0356)}, kTol), ResultNear({.position = {4.7948, -3.3375}, .velocity = {-6.7888, -14.1377}, - .time{2.0411}}, + .time = Time(2.0411)}, kTol), ResultNear({.position = {4.7636, -3.4085}, .velocity = {-5.6249, -12.7787}, - .time{2.0467}}, + .time = Time(2.0467)}, kTol), ResultNear({.position = {4.7390, -3.4685}, .velocity = {-4.4152, -10.8015}, - .time{2.0522}}, + .time = Time(2.0522)}, kTol), ResultNear({.position = {4.7208, -3.5164}, .velocity = {-3.2880, -8.6333}, - .time{2.0578}}, + .time = Time(2.0578)}, kTol), ResultNear({.position = {4.7079, -3.5528}, .velocity = {-2.3128, -6.5475}, - .time{2.0633}}, + .time = Time(2.0633)}, kTol), ResultNear({.position = {4.6995, -3.5789}, .velocity = {-1.5174, -4.7008}, - .time{2.0689}}, + .time = Time(2.0689)}, kTol), ResultNear({.position = {4.6945, -3.5965}, .velocity = {-0.9022, -3.1655}, - .time{2.0744}}, + .time = Time(2.0744)}, kTol), ResultNear({.position = {4.6942, -3.5976}, .velocity = {-0.8740, -3.0899}, - .time{2.0748}}, + .time = Time(2.0748)}, kTol))); // The stroke is finished, so there's nothing to predict anymore. @@ -782,9 +783,10 @@ TEST(StrokeModelerTest, WobbleSmoothed) { .position = {-6, -2}, .time = time}); ASSERT_TRUE(results.ok()); - EXPECT_THAT(*results, - ElementsAre(ResultNear( - {.position = {-6, -2}, .velocity = {0, 0}, .time{4}}, kTol))); + EXPECT_THAT( + *results, + ElementsAre(ResultNear( + {.position = {-6, -2}, .velocity = {0, 0}, .time = Time(4)}, kTol))); time += kDeltaTime; results = modeler.Update({.event_type = Input::EventType::kMove, @@ -793,19 +795,19 @@ TEST(StrokeModelerTest, WobbleSmoothed) { ASSERT_TRUE(results.ok()); EXPECT_THAT(*results, ElementsAre(ResultNear({.position = {-6.0001, -2}, .velocity = {-0.0328, 0}, - .time{4.0042}}, + .time = Time(4.0042)}, kTol), ResultNear({.position = {-6.0005, -2}, .velocity = {-0.0869, 0}, - .time{4.0084}}, + .time = Time(4.0084)}, kTol), ResultNear({.position = {-6.0011, -2}, .velocity = {-0.1531, 0}, - .time{4.0125}}, + .time = Time(4.0125)}, kTol), ResultNear({.position = {-6.0021, -2}, .velocity = {-0.2244, 0}, - .time{4.0167}}, + .time = Time(4.0167)}, kTol))); time += kDeltaTime; @@ -815,19 +817,19 @@ TEST(StrokeModelerTest, WobbleSmoothed) { ASSERT_TRUE(results.ok()); EXPECT_THAT(*results, ElementsAre(ResultNear({.position = {-6.0032, -2.0001}, .velocity = {-0.2709, -0.0205}, - .time{4.0209}}, + .time = Time(4.0209)}, kTol), ResultNear({.position = {-6.0044, -2.0003}, .velocity = {-0.2977, -0.0543}, - .time{4.0251}}, + .time = Time(4.0251)}, kTol), ResultNear({.position = {-6.0057, -2.0007}, .velocity = {-0.3093, -0.0956}, - .time{4.0292}}, + .time = Time(4.0292)}, kTol), ResultNear({.position = {-6.0070, -2.0013}, .velocity = {-0.3097, -0.1401}, - .time{4.0334}}, + .time = Time(4.0334)}, kTol))); time += kDeltaTime; @@ -837,19 +839,19 @@ TEST(StrokeModelerTest, WobbleSmoothed) { ASSERT_TRUE(results.ok()); EXPECT_THAT(*results, ElementsAre(ResultNear({.position = {-6.0084, -2.0021}, .velocity = {-0.3350, -0.1845}, - .time{4.0376}}, + .time = Time(4.0376)}, kTol), ResultNear({.position = {-6.0100, -2.0030}, .velocity = {-0.3766, -0.2266}, - .time{4.0418}}, + .time = Time(4.0418)}, kTol), ResultNear({.position = {-6.0118, -2.0041}, .velocity = {-0.4273, -0.2649}, - .time{4.0459}}, + .time = Time(4.0459)}, kTol), ResultNear({.position = {-6.0138, -2.0054}, .velocity = {-0.4818, -0.2986}, - .time{4.0501}}, + .time = Time(4.0501)}, kTol))); time += kDeltaTime; @@ -859,19 +861,19 @@ TEST(StrokeModelerTest, WobbleSmoothed) { ASSERT_TRUE(results.ok()); EXPECT_THAT(*results, ElementsAre(ResultNear({.position = {-6.0160, -2.0068}, .velocity = {-0.5157, -0.3478}, - .time{4.0543}}, + .time = Time(4.0543)}, kTol), ResultNear({.position = {-6.0182, -2.0085}, .velocity = {-0.5334, -0.4054}, - .time{4.0585}}, + .time = Time(4.0585)}, kTol), ResultNear({.position = {-6.0204, -2.0105}, .velocity = {-0.5389, -0.4658}, - .time{4.0626}}, + .time = Time(4.0626)}, kTol), ResultNear({.position = {-6.0227, -2.0126}, .velocity = {-0.5356, -0.5251}, - .time{4.0668}}, + .time = Time(4.0668)}, kTol))); } @@ -927,7 +929,7 @@ TEST(StrokeModelerTest, IgnoreInputsBeforeTDown) { EXPECT_EQ(modeler .Update({.event_type = Input::EventType::kMove, .position = {0, 0}, - .time{0}}) + .time = Time(0)}) .status() .code(), absl::StatusCode::kFailedPrecondition); @@ -935,7 +937,7 @@ TEST(StrokeModelerTest, IgnoreInputsBeforeTDown) { EXPECT_EQ(modeler .Update({.event_type = Input::EventType::kUp, .position = {0, 0}, - .time{1}}) + .time = Time(1)}) .status() .code(), absl::StatusCode::kFailedPrecondition); @@ -945,28 +947,31 @@ TEST(StrokeModelerTest, IgnoreTDownWhileStrokeIsInProgress) { StrokeModeler modeler; ASSERT_TRUE(modeler.Reset(kDefaultParams).ok()); - absl::StatusOr<std::vector<Result>> results = modeler.Update( - {.event_type = Input::EventType::kDown, .position = {0, 0}, .time{0}}); + absl::StatusOr<std::vector<Result>> results = + modeler.Update({.event_type = Input::EventType::kDown, + .position = {0, 0}, + .time = Time(0)}); ASSERT_TRUE(results.ok()); EXPECT_THAT(*results, Not(IsEmpty())); EXPECT_EQ(modeler .Update({.event_type = Input::EventType::kDown, .position = {1, 1}, - .time{1}}) + .time = Time(1)}) .status() .code(), absl::StatusCode::kFailedPrecondition); - results = modeler.Update( - {.event_type = Input::EventType::kMove, .position = {1, 1}, .time{1}}); + results = modeler.Update({.event_type = Input::EventType::kMove, + .position = {1, 1}, + .time = Time(1)}); ASSERT_TRUE(results.ok()); EXPECT_THAT(*results, Not(IsEmpty())); EXPECT_EQ(modeler .Update({.event_type = Input::EventType::kDown, .position = {2, 2}, - .time{2}}) + .time = Time(2)}) .status() .code(), absl::StatusCode::kFailedPrecondition); @@ -1280,19 +1285,20 @@ TEST(StrokeModelerTest, GenerateOutputOnTUpEvenIfNoTimeDelta) { .position = {5, 5}, .time = time}); ASSERT_TRUE(results.ok()); - EXPECT_THAT(*results, - ElementsAre(ResultNear( - {.position = {5, 5}, .velocity = {0, 0}, .time{0}}, kTol))); + EXPECT_THAT( + *results, + ElementsAre(ResultNear( + {.position = {5, 5}, .velocity = {0, 0}, .time = Time(0)}, kTol))); time += kDeltaTime; results = modeler.Update({.event_type = Input::EventType::kMove, .position = {5, 5}, .time = time}); ASSERT_TRUE(results.ok()); - EXPECT_THAT( - *results, - ElementsAre(ResultNear( - {.position = {5, 5}, .velocity = {0, 0}, .time{0.002}}, kTol))); + EXPECT_THAT(*results, + ElementsAre(ResultNear( + {.position = {5, 5}, .velocity = {0, 0}, .time = Time(0.002)}, + kTol))); results = modeler.Update( {.event_type = Input::EventType::kUp, .position = {5, 5}, .time = time}); @@ -1300,35 +1306,39 @@ TEST(StrokeModelerTest, GenerateOutputOnTUpEvenIfNoTimeDelta) { EXPECT_THAT( *results, ElementsAre(ResultNear( - {.position = {5, 5}, .velocity = {0, 0}, .time{0.0076}}, kTol))); + {.position = {5, 5}, .velocity = {0, 0}, .time = Time(0.0076)}, + kTol))); } TEST(StrokeModelerTest, RejectInputIfNegativeTimeDelta) { StrokeModeler modeler; ASSERT_TRUE(modeler.Reset(kDefaultParams).ok()); - absl::StatusOr<std::vector<Result>> results = modeler.Update( - {.event_type = Input::EventType::kDown, .position = {0, 0}, .time{0}}); + absl::StatusOr<std::vector<Result>> results = + modeler.Update({.event_type = Input::EventType::kDown, + .position = {0, 0}, + .time = Time(0)}); ASSERT_TRUE(results.ok()); EXPECT_THAT(*results, Not(IsEmpty())); EXPECT_EQ(modeler .Update({.event_type = Input::EventType::kMove, .position = {1, 1}, - .time{-.1}}) + .time = Time(-.1)}) .status() .code(), absl::StatusCode::kInvalidArgument); - results = modeler.Update( - {.event_type = Input::EventType::kMove, .position = {1, 1}, .time{1}}); + results = modeler.Update({.event_type = Input::EventType::kMove, + .position = {1, 1}, + .time = Time(1)}); ASSERT_TRUE(results.ok()); EXPECT_THAT(*results, Not(IsEmpty())); EXPECT_EQ(modeler .Update({.event_type = Input::EventType::kUp, .position = {1, 1}, - .time{.9}}) + .time = Time(.9)}) .status() .code(), absl::StatusCode::kInvalidArgument); @@ -1341,7 +1351,7 @@ TEST(StrokeModelerTest, RejectDuplicateInput) { absl::StatusOr<std::vector<Result>> results = modeler.Update({.event_type = Input::EventType::kDown, .position = {0, 0}, - .time{0}, + .time = Time(0), .pressure = .2, .tilt = .3, .orientation = .4}); @@ -1351,7 +1361,7 @@ TEST(StrokeModelerTest, RejectDuplicateInput) { EXPECT_EQ(modeler .Update({.event_type = Input::EventType::kDown, .position = {0, 0}, - .time{0}, + .time = Time(0), .pressure = .2, .tilt = .3, .orientation = .4}) @@ -1361,7 +1371,7 @@ TEST(StrokeModelerTest, RejectDuplicateInput) { results = modeler.Update({.event_type = Input::EventType::kMove, .position = {1, 2}, - .time{1}, + .time = Time(1), .pressure = .1, .tilt = .2, .orientation = .3}); @@ -1371,7 +1381,7 @@ TEST(StrokeModelerTest, RejectDuplicateInput) { EXPECT_EQ(modeler .Update({.event_type = Input::EventType::kMove, .position = {1, 2}, - .time{1}, + .time = Time(1), .pressure = .1, .tilt = .2, .orientation = .3}) diff --git a/ink_stroke_modeler/types.h b/ink_stroke_modeler/types.h index fcec7b0..922c0f7 100644 --- a/ink_stroke_modeler/types.h +++ b/ink_stroke_modeler/types.h @@ -329,6 +329,7 @@ inline std::ostream &operator<<(std::ostream &s, Input::EventType event_type) { case Input::EventType::kUp: return s << "Up"; } + return s << "UnknownEventType<" << event_type << ">"; } inline std::ostream &operator<<(std::ostream &s, const Input &input) { diff --git a/ink_stroke_modeler/types_test.cc b/ink_stroke_modeler/types_test.cc index 70cfed8..e812d76 100644 --- a/ink_stroke_modeler/types_test.cc +++ b/ink_stroke_modeler/types_test.cc @@ -201,7 +201,7 @@ TEST(TypesTest, InputEquality) { EXPECT_EQ(kBaseline, Input()); EXPECT_NE(kBaseline, Input{.event_type = Input::EventType::kMove}); EXPECT_NE(kBaseline, (Input{.position = {1, -1}})); - EXPECT_NE(kBaseline, Input{.time{1}}); + EXPECT_NE(kBaseline, Input{.time = Time(1)}); EXPECT_NE(kBaseline, Input{.pressure = .5}); EXPECT_NE(kBaseline, Input{.tilt = .2}); EXPECT_NE(kBaseline, Input{.orientation = .7}); |