From 13d3b67822f9e8b2f6cfc96933abeef054d37085 Mon Sep 17 00:00:00 2001 From: Pierre Joye Date: Thu, 26 Aug 2021 22:40:15 +0700 Subject: Fix #402, negative determinant fails, only 0 or not finite should fail --- tests/CMakeLists.txt | 1 + tests/gdmatrix/CMakeLists.txt | 5 +++++ tests/gdmatrix/bug00402.c | 30 ++++++++++++++++++++++++++++++ 3 files changed, 36 insertions(+) create mode 100644 tests/gdmatrix/CMakeLists.txt create mode 100644 tests/gdmatrix/bug00402.c (limited to 'tests') diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 51f09c4..25a19ba 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -78,6 +78,7 @@ if (BUILD_TEST) gdimagestringup16 gdimagetruecolortopalette gdinterpolatedscale + gdmatrix gdnewfilectx gdtest gdtiled diff --git a/tests/gdmatrix/CMakeLists.txt b/tests/gdmatrix/CMakeLists.txt new file mode 100644 index 0000000..1035246 --- /dev/null +++ b/tests/gdmatrix/CMakeLists.txt @@ -0,0 +1,5 @@ +LIST(APPEND TESTS_FILES + bug00402 +) + +ADD_GD_TESTS() diff --git a/tests/gdmatrix/bug00402.c b/tests/gdmatrix/bug00402.c new file mode 100644 index 0000000..15529b6 --- /dev/null +++ b/tests/gdmatrix/bug00402.c @@ -0,0 +1,30 @@ +#include "gd.h" +#include +#include "gdtest.h" +#include +int main() +{ + double matrix[6] = { + 0.000000, 0.150000, + 0.150000, -0.000000, + 0.000000, 0.000000 + }; + double matrix_inv[6]; + double matrix_inv_exp[6] = { + 0.0000000000, 6.6666666667, + 6.6666666667, -0.0000000000, + -0.0000000000, 0.0000000000 + }; + + int res = gdAffineInvert(matrix_inv, matrix); + + for (int i=0; i < 6; i++) { + double rounded_res = round(matrix_inv[i] * 10); + double rounded_exp = round(matrix_inv_exp[i] * 10); + if (rounded_res != rounded_exp) { + printf("%i failed %f exp %f", i, matrix_inv[i], matrix_inv_exp[i]); + return -1; + } + } + return res; +} -- cgit v1.2.1