64 Commits

Author SHA1 Message Date
David Briscoe
39aee9a421 Fix angle_to to produce signed angle
angle_to was producing the angle from +x to the difference between a,b
which is unexpected. Instead, it should produce the smallest absolute
angle between the two vectors and be signed to indicate the direction of
rotation.

By using the old angle_to implementation and modifying equal() to print
out the failures, you can see the numbers that it was producing before
didn't make much sense:

    right:angle_to(down) = 45.0
    right:angle_to(left) = 0.0
    right:angle_to(up)   = -45.0
    down:angle_to(right) = -135.0
    down:angle_to(left)  = -45.0
    down:angle_to(up)    = -90.0
    left:angle_to(down)  = 135.0
    left:angle_to(up)    = -135.0
    up:angle_to(right)   = 135.0
    up:angle_to(down)    = 90.0
    up:angle_to(left)    = 45.0

Now it produces numbers you'd expect:

    right:angle_to(down) = -90.0
    right:angle_to(left) = 180.0
    right:angle_to(up)   = 90.0
    down:angle_to(right) = 90.0
    down:angle_to(left)  = -90.0
    down:angle_to(up)    = 180.0
    left:angle_to(down)  = 90.0
    left:angle_to(up)    = -90.0
    up:angle_to(right)   = -90.0
    up:angle_to(down)    = 180.0
    up:angle_to(left)    = 90.0

See also https://stackoverflow.com/questions/21483999/using-atan2-to-find-angle-between-two-vectors

Also added tests for angle_between.
2021-06-15 11:56:04 -07:00
mcc
ddb80f48e6 Compatibility note for 1.0 release and PR#48 test 2020-05-03 13:36:26 -04:00
mcclure
1000f1d6e5
Merge pull request #48 from mcclure/mat4-reverse
Consistency: mat4 multiply in wrong order
2020-05-03 13:13:11 -04:00
mcclure
61affeb669
Merge pull request #56 from mcclure/identity-quat
Fix for issue #55 (quat():to_angle_axis() returns gibberish)
2020-05-03 12:54:47 -04:00
mcc
336f416f29 Manual merge PR#53 2020-05-03 12:52:17 -04:00
mcc
f7497b9bf7 Manual merge PR#52 2020-05-03 12:50:42 -04:00
mcc
6e1cf4be56 Manual merge PR#51 2020-05-03 12:46:30 -04:00
mcclure
d4f7cd1280
Merge pull request #50 from mcclure/master
:round(precision) methods for vec2, vec3, bound2, bound3
2020-05-03 12:37:58 -04:00
mcclure
5601094c04
Merge pull request #49 from mcclure/vec4_cols
Column version of to_vec4s (to_vec4s_cols)
2020-05-03 12:37:22 -04:00
mcc
9cd858a0ef Add tests to identity-quat patch and also take an axis not a full value for the identity fallback 2020-04-25 18:32:48 -04:00
mcclure
86f0056397
Merge pull request #47 from mcclure/master-test-failures
Fix failing tests
2019-11-30 17:37:03 -05:00
mcc
185b19d766 vec2.to_vec3(z) creates a vec3 with the given z (or 0) 2019-11-30 11:31:22 -05:00
mcc
7452cc0c6c Simple methods for flipping a vector on exactly 1 axis 2019-11-30 11:25:00 -05:00
mcc
e3f817bf7e extend(vec) and extend_bound(bound) for bounds
expands bounds to cover new points
2019-11-30 01:24:48 -05:00
mcc
8e65db07ce :round(precision) methods for vec2, vec3, bound2, bound3
Uses utils.lua, which requires moving utils.round to a new _private_utils.lua
2019-11-30 00:03:55 -05:00
mcc
13cc666232 Column version of to_vec4s (to_vec4s_cols) for issue #32 2019-11-29 22:24:47 -05:00
mcc
d51a930e4a Consistency (issue #33): mat4 multiply in wrong order
This is a breaking change.
2019-11-29 22:12:22 -05:00
mcc
d845a479ac Fix typo in bound3 test which was breaking under LuaJIT 2019-11-29 21:08:04 -05:00
mcc
7667ea9a3d Fix typo in bound2 test which was breaking under LuaJIT 2019-11-29 17:55:03 -05:00
mcc
7fa1785469 Fix failing tests; this involves changing 2 bad tests and 1 bad behavior:
- vec2 to_polar/from_cartesian tests were testing for equality rather than using an epsilon.
- bound2.contains had two tests that were plain wrong.
- While I'm fixing the bounds test, bound2.contains and bound3.contains probably ought to test their own min and max values for inclusion.
- The implementation of mat4.look_at appears to be wrong. The final column was being set to 0,0,0,1 which comparing against other implementations does not seem to be correct. My replacement code is modeled on the method used in mat4x4_look_at() in linmath.h in GLFW, which says it's a reimplementation on the method from gluLookAt(). With this change the test passes as originally written.
2019-11-29 17:16:20 -05:00
mcc
b80543c242 Make vec2(vec2(1,2)) and vec3(vec3(1,2,3)) consistent between lua and luajit 2019-11-29 14:44:34 -05:00
Colby Klein
130fe2aca0
Merge pull request #30 from mcclure/aabb
Axis-aligned bounding box classes for 2 and 3 dimensions
2018-02-22 04:09:36 -08:00
mcc
7c18a65695 Bound2, bound3: Add tests and fix several major bugs so that those tests pass. 2018-01-27 00:46:56 -05:00
mcc
a41af4702b Quaternions: Add tests for component-wise to_angle_axis and from_angle_axis 2018-01-26 21:05:03 -05:00
bjorn
2ac5321bdf mat4:reflect; 2018-01-05 22:08:11 -08:00
Colby Klein
0ff68c69fd fix lerp for vec3, update tests for broken lerp case 2017-05-19 09:49:07 -07:00
Colby Klein
65e3676af5 swap lerp arg order, fix tests 2017-03-29 07:42:40 -07:00
Colby Klein
0b0bea16ef add some lerp/decay tests 2017-03-29 05:32:31 -07:00
Colby Klein
9776dbbf39 update quat test to reflect that pow() needs unit quats 2016-12-16 00:46:43 -08:00
karai17
08b23e394b Updated tests, fixed couple bugs 2016-12-15 19:57:31 -04:00
Colby Klein
d19a5addcb Fix failing tests caused by mul->scale 2016-08-21 20:42:44 -07:00
karai17
832648af33 Colby sucks 2016-07-26 23:16:30 -03:00
karai17
e25f4acef9 Fixed broken tests 2016-07-26 22:31:08 -03:00
karai17
b0e9714a0e added aabb_obb test 2016-07-26 01:21:49 -03:00
karai17
637bc5a413 Added many intersection tests 2016-07-26 00:44:15 -03:00
karai17
52814eed9f Added a few more specs, no new tests though 2016-07-25 02:07:24 -03:00
karai17
dc31605db6 Fixed mat4.look_at 2016-07-24 23:42:44 -03:00
karai17
96a63ce581 Added a few more mat4 tests 2016-07-24 11:35:48 -03:00
karai17
ce80e2c90a Added test for quat.to_string 2016-07-24 10:53:57 -03:00
karai17
f038ce2dc7 Increased test coverage of vec2, vec3, quat 2016-07-24 10:49:35 -03:00
karai17
c4fabe7f19 Made the tests less bad 2016-07-24 10:04:29 -03:00
karai17
2cb5d0970d Added to_frustum test 2016-07-24 04:43:06 -03:00
karai17
375f748c1f FFI'd color 2016-07-23 23:16:10 -03:00
karai17
481825cba4 What ARE birds?
We just don't know.
2016-07-23 05:21:03 -03:00
karai17
fbf329264d Blood. Sweat. Tears. Mostly blood. And sweat. And tears. 2016-07-23 03:23:06 -03:00
karai17
5f7a7f29fa Added quaternion tests
* Fixed an issue with is_quat, is_vec3, is_vec2, and is_mat4 methods
* Fixed a minor issue with local variables being declared too late
2016-07-21 20:04:32 -03:00
karai17
78b34590c5 vec2 and vec3 100% test coverage 2016-07-21 13:52:35 -03:00
karai17
4f9bc17bf4 Refactored mat4
Did some tidying up on quat, vec2, vec3, and utils
2016-07-19 23:55:21 -03:00
karai17
6ced5f397e Removed unneeded do blocks from tests 2016-07-15 22:19:22 -03:00
karai17
add0a71c05 Added tests for vec2 and vec3 2016-07-15 22:07:48 -03:00