It's non-transparent what wcmTilt2R actually does at the moment, so generate
a test table from the current code and test against that. This
way we at least know when we're breaking something.

Exception: wraparound value generates +900 instead of -900.  We must not
send +900, our max range is 899, then we wrap again. This function isn't
supposed to generate this value, so manually fixed up.

Signed-off-by: Peter Hutterer <peter.hutte...@who-t.net>
---
 test/wacom-tests.c |  114 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 114 insertions(+), 0 deletions(-)

diff --git a/test/wacom-tests.c b/test/wacom-tests.c
index 23bfba6..8ada826 100644
--- a/test/wacom-tests.c
+++ b/test/wacom-tests.c
@@ -316,6 +316,119 @@ test_suppress(void)
        new.pressure = old.pressure;
 }
 
+static void
+test_tilt_to_rotation(void)
+{
+#if 0
+       This table below was generated from wcmTilt2R with the following code
+
+       for (angle = 0; angle < 360; angle++)
+       {
+               double rad = angle * M_PI / 180.0;
+               double x, y;
+               x = sin(rad);
+               y = cos(rad);
+
+               /* wcmTilt2R only uses it for the angle anyway, let's try to
+               get as precise as possible */
+               ds.tiltx = x * 1000;
+               ds.tilty = y * 1000;
+               ds.rotation = 0;
+
+               wcmTilt2R(&ds);
+
+               printf("{ %d, %d, %d},\n", ds.tiltx, ds.tilty, ds.rotation);
+       }
+#endif
+
+       int rotation_table[][3] = {
+               { 17, 999, 20}, { 34, 999, 15}, { 52, 998, 10}, { 69, 997, 5}, 
{ 87, 996, 0},
+               { 104, 994, -5}, { 121, 992, -10}, { 139, 990, -15}, { 156, 
987, -20}, { 173, 984, -25},
+               { 190, 981, -30}, { 207, 978, -35}, { 224, 974, -40}, { 241, 
970, -45}, { 258, 965, -50},
+               { 275, 961, -55}, { 292, 956, -60}, { 309, 951, -65}, { 325, 
945, -70}, { 342, 939, -75},
+               { 358, 933, -80}, { 374, 927, -85}, { 390, 920, -90}, { 406, 
913, -95}, { 422, 906, -100},
+               { 438, 898, -105}, { 453, 891, -110}, { 469, 882, -115}, { 484, 
874, -120}, { 499, 866, -125},
+               { 515, 857, -130}, { 529, 848, -135}, { 544, 838, -140}, { 559, 
829, -145}, { 573, 819, -150},
+               { 587, 809, -155}, { 601, 798, -160}, { 615, 788, -165}, { 629, 
777, -170}, { 642, 766, -175},
+               { 656, 754, -180}, { 669, 743, -185}, { 681, 731, -190}, { 694, 
719, -195}, { 707, 707, -200},
+               { 719, 694, -205}, { 731, 681, -210}, { 743, 669, -215}, { 754, 
656, -220}, { 766, 642, -225},
+               { 777, 629, -230}, { 788, 615, -235}, { 798, 601, -240}, { 809, 
587, -245}, { 819, 573, -250},
+               { 829, 559, -255}, { 838, 544, -260}, { 848, 529, -265}, { 857, 
515, -270}, { 866, 500, -275},
+               { 874, 484, -280}, { 882, 469, -285}, { 891, 453, -290}, { 898, 
438, -295}, { 906, 422, -300},
+               { 913, 406, -305}, { 920, 390, -310}, { 927, 374, -315}, { 933, 
358, -320}, { 939, 342, -325},
+               { 945, 325, -330}, { 951, 309, -335}, { 956, 292, -340}, { 961, 
275, -345}, { 965, 258, -350},
+               { 970, 241, -355}, { 974, 224, -360}, { 978, 207, -365}, { 981, 
190, -370}, { 984, 173, -375},
+               { 987, 156, -380}, { 990, 139, -385}, { 992, 121, -390}, { 994, 
104, -395}, { 996, 87, -400},
+               { 997, 69, -405}, { 998, 52, -410}, { 999, 34, -415}, { 999, 
17, -420}, { 1000, 0, -425},
+               { 999, -17, -430}, { 999, -34, -435}, { 998, -52, -440}, { 997, 
-69, -445}, { 996, -87, -450},
+               { 994, -104, -455}, { 992, -121, -460}, { 990, -139, -465}, { 
987, -156, -470}, { 984, -173, -475},
+               { 981, -190, -480}, { 978, -207, -485}, { 974, -224, -490}, { 
970, -241, -495}, { 965, -258, -500},
+               { 961, -275, -505}, { 956, -292, -510}, { 951, -309, -515}, { 
945, -325, -520}, { 939, -342, -525},
+               { 933, -358, -530}, { 927, -374, -535}, { 920, -390, -540}, { 
913, -406, -545}, { 906, -422, -550},
+               { 898, -438, -555}, { 891, -453, -560}, { 882, -469, -565}, { 
874, -484, -570}, { 866, -499, -575},
+               { 857, -515, -580}, { 848, -529, -585}, { 838, -544, -590}, { 
829, -559, -595}, { 819, -573, -600},
+               { 809, -587, -605}, { 798, -601, -610}, { 788, -615, -615}, { 
777, -629, -620}, { 766, -642, -625},
+               { 754, -656, -630}, { 743, -669, -635}, { 731, -681, -640}, { 
719, -694, -645}, { 707, -707, -650},
+               { 694, -719, -655}, { 681, -731, -660}, { 669, -743, -665}, { 
656, -754, -670}, { 642, -766, -675},
+               { 629, -777, -680}, { 615, -788, -685}, { 601, -798, -690}, { 
587, -809, -695}, { 573, -819, -700},
+               { 559, -829, -705}, { 544, -838, -710}, { 529, -848, -715}, { 
515, -857, -720}, { 499, -866, -725},
+               { 484, -874, -730}, { 469, -882, -735}, { 453, -891, -740}, { 
438, -898, -745}, { 422, -906, -750},
+               { 406, -913, -755}, { 390, -920, -760}, { 374, -927, -765}, { 
358, -933, -770}, { 342, -939, -775},
+               { 325, -945, -780}, { 309, -951, -785}, { 292, -956, -790}, { 
275, -961, -795}, { 258, -965, -800},
+               { 241, -970, -805}, { 224, -974, -810}, { 207, -978, -815}, { 
190, -981, -820}, { 173, -984, -825},
+               { 156, -987, -830}, { 139, -990, -835}, { 121, -992, -840}, { 
104, -994, -845}, { 87, -996, -850},
+               { 69, -997, -855}, { 52, -998, -860}, { 34, -999, -865}, { 17, 
-999, -870}, { 0, -1000, -875},
+               { -17, -999, -880}, { -34, -999, -885}, { -52, -998, -890}, { 
-69, -997, -895}, { -87, -996, -900},
+               { -104, -994, 895}, { -121, -992, 890}, { -139, -990, 885}, { 
-156, -987, 880}, { -173, -984, 875},
+               { -190, -981, 870}, { -207, -978, 865}, { -224, -974, 860}, { 
-241, -970, 855}, { -258, -965, 850},
+               { -275, -961, 845}, { -292, -956, 840}, { -309, -951, 835}, { 
-325, -945, 830}, { -342, -939, 825},
+               { -358, -933, 820}, { -374, -927, 815}, { -390, -920, 810}, { 
-406, -913, 805}, { -422, -906, 800},
+               { -438, -898, 795}, { -453, -891, 790}, { -469, -882, 785}, { 
-484, -874, 780}, { -500, -866, 775},
+               { -515, -857, 770}, { -529, -848, 765}, { -544, -838, 760}, { 
-559, -829, 755}, { -573, -819, 750},
+               { -587, -809, 745}, { -601, -798, 740}, { -615, -788, 735}, { 
-629, -777, 730}, { -642, -766, 725},
+               { -656, -754, 720}, { -669, -743, 715}, { -681, -731, 710}, { 
-694, -719, 705}, { -707, -707, 700},
+               { -719, -694, 695}, { -731, -681, 690}, { -743, -669, 685}, { 
-754, -656, 680}, { -766, -642, 675},
+               { -777, -629, 670}, { -788, -615, 665}, { -798, -601, 660}, { 
-809, -587, 655}, { -819, -573, 650},
+               { -829, -559, 645}, { -838, -544, 640}, { -848, -529, 635}, { 
-857, -515, 630}, { -866, -500, 625},
+               { -874, -484, 620}, { -882, -469, 615}, { -891, -453, 610}, { 
-898, -438, 605}, { -906, -422, 600},
+               { -913, -406, 595}, { -920, -390, 590}, { -927, -374, 585}, { 
-933, -358, 580}, { -939, -342, 575},
+               { -945, -325, 570}, { -951, -309, 565}, { -956, -292, 560}, { 
-961, -275, 555}, { -965, -258, 550},
+               { -970, -241, 545}, { -974, -224, 540}, { -978, -207, 535}, { 
-981, -190, 530}, { -984, -173, 525},
+               { -987, -156, 520}, { -990, -139, 515}, { -992, -121, 510}, { 
-994, -104, 505}, { -996, -87, 500},
+               { -997, -69, 495}, { -998, -52, 490}, { -999, -34, 485}, { 
-999, -17, 480}, { -1000, 0, 475},
+               { -999, 17, 470}, { -999, 34, 465}, { -998, 52, 460}, { -997, 
69, 455}, { -996, 87, 450},
+               { -994, 104, 445}, { -992, 121, 440}, { -990, 139, 435}, { 
-987, 156, 430}, { -984, 173, 425},
+               { -981, 190, 420}, { -978, 207, 415}, { -974, 224, 410}, { 
-970, 241, 405}, { -965, 258, 400},
+               { -961, 275, 395}, { -956, 292, 390}, { -951, 309, 385}, { 
-945, 325, 380}, { -939, 342, 375},
+               { -933, 358, 370}, { -927, 374, 365}, { -920, 390, 360}, { 
-913, 406, 355}, { -906, 422, 350},
+               { -898, 438, 345}, { -891, 453, 340}, { -882, 469, 335}, { 
-874, 484, 330}, { -866, 500, 325},
+               { -857, 515, 320}, { -848, 529, 315}, { -838, 544, 310}, { 
-829, 559, 305}, { -819, 573, 300},
+               { -809, 587, 295}, { -798, 601, 290}, { -788, 615, 285}, { 
-777, 629, 280}, { -766, 642, 275},
+               { -754, 656, 270}, { -743, 669, 265}, { -731, 681, 260}, { 
-719, 694, 255}, { -707, 707, 250},
+               { -694, 719, 245}, { -681, 731, 240}, { -669, 743, 235}, { 
-656, 754, 230}, { -642, 766, 225},
+               { -629, 777, 220}, { -615, 788, 215}, { -601, 798, 210}, { 
-587, 809, 205}, { -573, 819, 200},
+               { -559, 829, 195}, { -544, 838, 190}, { -529, 848, 185}, { 
-515, 857, 180}, { -500, 866, 175},
+               { -484, 874, 170}, { -469, 882, 165}, { -453, 891, 160}, { 
-438, 898, 155}, { -422, 906, 150},
+               { -406, 913, 145}, { -390, 920, 140}, { -374, 927, 135}, { 
-358, 933, 130}, { -342, 939, 125},
+               { -325, 945, 120}, { -309, 951, 115}, { -292, 956, 110}, { 
-275, 961, 105}, { -258, 965, 100},
+               { -241, 970, 95}, { -224, 974, 90}, { -207, 978, 85}, { -190, 
981, 80}, { -173, 984, 75},
+               { -156, 987, 70}, { -139, 990, 65}, { -121, 992, 60}, { -104, 
994, 55}, { -87, 996, 50},
+               { -69, 997, 45}, { -52, 998, 40}, { -34, 999, 35}, { -17, 999, 
30},
+       };
+       int i;
+       WacomDeviceState ds = {0};
+
+       for (i = 0; i < ARRAY_SIZE(rotation_table); i++)
+       {
+               ds.rotation = 0;
+               ds.tiltx = rotation_table[i][0];
+               ds.tilty = rotation_table[i][1];
+               wcmTilt2R(&ds);
+               g_assert(ds.rotation == rotation_table[i][2]);
+       }
+}
+
+
 int main(int argc, char** argv)
 {
        g_test_init(&argc, &argv, NULL);
@@ -324,6 +437,7 @@ int main(int argc, char** argv)
        g_test_add_func("/common/normalize_pressure", test_normalize_pressure);
        g_test_add_func("/common/test_suppress", test_suppress);
        g_test_add_func("/xfree86/initial_size", test_initial_size);
+       g_test_add_func("/filter/tilt_to_rotation", test_tilt_to_rotation);
        return g_test_run();
 }
 
-- 
1.7.4


------------------------------------------------------------------------------
Colocation vs. Managed Hosting
A question and answer guide to determining the best fit
for your organization - today and in the future.
http://p.sf.net/sfu/internap-sfd2d
_______________________________________________
Linuxwacom-devel mailing list
Linuxwacom-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linuxwacom-devel

Reply via email to