Fixes a subtle problem with vm_test_parallel() wherein a relative error
was accidentally converted into an absolute error.
Instead of comparing the result of the cross product to the zero vector,
the two calculated components of the cross product are compared against
each other. This permits vectors whose cross product is a large number
but whose cross product partials are within relative error of each other
to be treated as parallel.
For example, the following two vectors may now be considered as parallel
whereas before they were not:
v1 = (1000004.0, 1.0, 1.0)
v2 = (1000000.0, 1.0, 1.0)
The relative difference between them is sufficiently small according to
vm_vec_equal() for them to be considered equal, but their cross product
would have elements whose magnitudes would be near 4.0 which would
otherwise indicate that they are not parallel. By comparing the partials
instead, a higher degree of consistency is maintained.
Signed-off-by: Peter Mitsis <[email protected]>
vm_vector_2_matrix was improperly guarded against bad parameters. In the
case I encountered the uvec was the negative of fvec which produced a
null vector when the cross product of the two vector was constructed.
These changes should fix that bug by ignoring the uvec parameter. Since
vm_vector_2_matrix and vm_vector_2_matrix_norm are basically the same, I
converted the former into an alias of the latter and only fixed that
code.
The routine vm_vec_normalize_quick_mag() did not normalize a vector.
Instead of dividing the vector by the 'quick magnitude', it multiplied
it. This routine was only called by one other routine (which was
fortunately unused)--vm_vec_normalized_dir_quick_mag().
Given both the incorrect behavior as well as their lack of use, those
routines have been removed.
Signed-off-by: Peter Mitsis <[email protected]>
Uses fl_abs() (which evaluates to fabsf()) instead of an if-else
statement to get the absolute value of a float. A compiler for the
x86 platform is able use SSE instructions to optimize calls to fabsf().
Signed-off-by: Peter Mitsis <[email protected]>
Replaces calls to double-precision floating point trig functions with
calls to single-precision floating point trig functions as follows:
cos() -> cosf()
sin() -> sinf()
tan() -> tanf()
acos() -> acosf()
asin() -> asinf()
atan() -> atanf()
This allows the compiler to avoid generating unnecessary instructions
that convert a float to a double and then a double back to a float.
Signed-off-by: Peter Mitsis <[email protected]>
Instead of performing three consecutive divisions, vm_vec_avg_n() now performs
one division at the start and three multiplications at the end. Recall that
multiplication is faster than division.
Signed-off-by: Peter Mitsis <[email protected]>
The routine atan2_safe() already contains a test that checks if both parameters
are zero--that is the point of the routine. Thus, there is no need for the
caller of atan2_safe() to perform that same check.
Signed-off-by: Peter Mitsis <[email protected]>
The routine vm_vec_normalize() always returns a value greater than zero.
Thus, there is no need to test its return value for values that are less
than or equal to zero.
Signed-off-by: Peter Mitsis <[email protected]>
The routine vm_vec_copy_normalize() always returns a value greater than zero.
Thus, there is no need to test its return value for values that are less than
or equal to zero.
Signed-off-by: Peter Mitsis <[email protected]>
Not only is the routine vm_fvec_matrix_interpolate() unused, it does not appear
to have been used for the duration of the project. The only reference to it
found in the history was in a removed comment. That comment indicated that it
was implemented in 1997.
Signed-off-by: Peter Mitsis <[email protected]>
Instead of perform three consecutive divisions, vm_vec_avg_n() now performs one
division at the start and three multiplications at the end. Recall that
multiplication is faster than division.
Signed-off-by: Peter Mitsis <[email protected]>
The routine atan2_safe() already contains a test that checks if both parameters
are zero--that is the point of the routine. Thus, there is no need for the
caller of atan2_safe() to perform that same check.
Signed-off-by: Peter Mitsis <[email protected]>