diff --git a/.clang-tidy b/.clang-tidy index 541ea53..a1fa4b1 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -7,19 +7,19 @@ Checks: > performance-*, portability-*, readability-*, + -bugprone-easily-swappable-parameters, -google-readability-namespace-comments, -google-runtime-int, -google-runtime-references, + -llvmlibc-callee-namespace, -misc-non-private-member-variables-in-classes, - -readability-named-parameter, + -modernize-macro-to-enum, + -modernize-use-trailing-return-type, -readability-braces-around-statements, - -readability-magic-numbers - -llvmlibc-callee-namespace - -bugprone-easily-swappable-parameters - -readability-magic-numbers - -readability-identifier-length - -readability-identifier-naming - -modernize-macro-to-enum + -readability-identifier-length, + -readability-identifier-naming, + -readability-magic-numbers, + -readability-named-parameter CheckOptions: - { key: readability-identifier-naming.NamespaceCase, value: lower_case } @@ -27,7 +27,6 @@ CheckOptions: - { key: readability-identifier-naming.StructCase, value: CamelCase } - { key: readability-identifier-naming.TemplateParameterCase, value: CamelCase } - { key: readability-identifier-naming.FunctionCase, value: CamelCase } - - { key: readability-identifier-naming.VariableCase, value: lower_case } - { key: readability-identifier-naming.PrivateMemberSuffix, value: _ } - { key: readability-identifier-naming.ProtectedMemberSuffix, value: _ } - { key: readability-identifier-naming.MacroDefinitionCase, value: UPPER_CASE } @@ -41,3 +40,4 @@ CheckOptions: - { key: readability-identifier-naming.MemberConstantPrefix, value: k } - { key: readability-identifier-naming.StaticConstantCase, value: CamelCase } - { key: readability-identifier-naming.StaticConstantPrefix, value: k } + - { key: readability-identifier-naming.VariableCase, value: CamelCase } diff --git a/lib/BleFingerprint/FilteredDistance.cpp b/lib/BleFingerprint/FilteredDistance.cpp index 5d42351..6c42b55 100644 --- a/lib/BleFingerprint/FilteredDistance.cpp +++ b/lib/BleFingerprint/FilteredDistance.cpp @@ -15,16 +15,16 @@ void FilteredDistance::initSpike(float dist) { readings[i] = dist; } total = dist * NUM_READINGS; - totalSquared = dist * dist * NUM_READINGS; // Initialize sum of squared distances + totalSquared = dist * dist * NUM_READINGS; // Initialize sum of squared distances } float FilteredDistance::removeSpike(float dist) { - total -= readings[readIndex]; // Subtract the last reading - totalSquared -= readings[readIndex] * readings[readIndex]; // Subtract the square of the last reading + total -= readings[readIndex]; // Subtract the last reading + totalSquared -= readings[readIndex] * readings[readIndex]; // Subtract the square of the last reading - readings[readIndex] = dist; // Read the sensor - total += readings[readIndex]; // Add the reading to the total - totalSquared += readings[readIndex] * readings[readIndex]; // Add the square of the reading + readings[readIndex] = dist; // Read the sensor + total += readings[readIndex]; // Add the reading to the total + totalSquared += readings[readIndex] * readings[readIndex]; // Add the square of the reading readIndex = (readIndex + 1) % NUM_READINGS; // Advance to the next position in the array @@ -69,7 +69,9 @@ float FilteredDistance::getAlpha(float cutoff, float dT) { } const float FilteredDistance::getVariance() const { - float mean = total / static_cast(NUM_READINGS); - float meanOfSquares = totalSquared / static_cast(NUM_READINGS); - return meanOfSquares - (mean * mean); // Variance formula: E(X^2) - (E(X))^2 + auto mean = total / static_cast(NUM_READINGS); + auto meanOfSquares = totalSquared / static_cast(NUM_READINGS); + auto variance = meanOfSquares - (mean * mean); // Variance formula: E(X^2) - (E(X))^2 + if (variance < 0.0f) return 0.0f; + return variance; }