That gives the change of storing that data in flash storage in some
architectures. That doesn't happen yet though, some extra changes are required
for that to happen.
We don't actually need all of them, since the second half is for the opposite
triangles. In that case we just need to negate the resulting vector when
changing basis.
That function was only being used by the unit tests and the benchmark. In order
to remove memory usage, the triangles will be removed, since we don't actually
need to keep them in real situations. Thus, this patch removes that function
and copy those triangles to the test and benchmark.
This is the second optimization. With that we don't have to iterate over the
umbrella's components.
The table below summarizes the mean CPU time in ns from the brenchmark results
on an Intel(R) Core(TM) i7-3520M CPU @ 2.90GHz processor:
| Naive implementation | First Optimization | Second Optimization
------------------------------------------------------------------------
Min. | 26.0 | 28.00 | 26.0
1st Qu.| 78.0 | 48.75 | 39.0
Median | 132.0 | 57.00 | 41.0
Mean | 130.1 | 61.20 | 41.6
3rd Qu.| 182.2 | 76.00 | 47.0
Max. | 234.0 | 98.00 | 54.0
If v is the null vector, then alpha * v is still the null vector for any alpha
as a real number. That means that the null vector doesn't cross any section.
This is a first optimization of the algorithm. The struct for the neighbor
umbrella has only one member, but new members will be added in the next
optimization.
The table below summarizes the mean CPU time in ns from the brenchmark results
on an Intel(R) Core(TM) i7-3520M CPU @ 2.90GHz processor:
Cases | Naive implementation | First Optimization
--------------------------------------------------
Min. | 26.0 | 28.00
1st Qu.| 78.0 | 48.75
Median | 132.0 | 57.00
Mean | 130.1 | 61.20
3rd Qu.| 182.2 | 76.00
Max. | 234.0 | 98.00
This optimization reduces the mean time for the worst case (Max. line) by more
than 50%.
- Change the order of the icosahedron triangles so that there's a uniform way of
finding the opposite triangle. The order visually still makes sense.
- Change test to accommodate the order change.
Avoid warnings like:
[2130/2168] Compiling libraries/AP_Math/tests/test_math.cpp
../../libraries/AP_Math/tests/test_math.cpp: In member function ‘virtual void MathTest_IsZero_Test::TestBody()’:
../../libraries/AP_Math/tests/test_math.cpp:73:196: warning: converting ‘false’ to pointer type for argument 1 of ‘char
testing::internal::IsNullLiteralHelper(testing::internal::Secret*)’ [-Wconversion-null]
../../libraries/AP_Math/tests/test_math.cpp:74:199: warning: converting ‘false’ to pointer type for argument 1 of ‘char
testing::internal::IsNullLiteralHelper(testing::internal::Secret*)’ [-Wconversion-null]
Use EXPECT_TRUE() and EXPECT_FALSE() from gtest instead.
The new function can deal with a variable number of function parameters.
Additionally, I renamed the functions to norm(), because this is the
standard name used in several other projects.
When using wrap_180_cd() we are adding a small float (180 * 100) to a
possibly big number. This may lose float precision as illustrated by the
unit test failing:
OUT: ../../libraries/AP_Math/tests/test_math.cpp:195: Failure
OUT: Value of: wrap_180_cd(-3600000000.f)
OUT: Actual: -80
OUT: Expected: 0.f
OUT: Which is: 0
These functions (or variants thereof) now have unit tests:
- is_zero()
- is_equal()
- sq()
- pythagorous()
- constrain()
- wrap_180()
- wrap_360()
Some tests in wrap_180_cd are failing: -180 should be wrapped to 180,
not -180.