From 0ef9330a0878fd4ecc7935c5605118f27afdaefc Mon Sep 17 00:00:00 2001 From: Andrey Pokidov Date: Tue, 12 Nov 2024 00:56:01 +0700 Subject: [PATCH] =?UTF-8?q?+dev=20=D0=BF=D1=80=D0=BE=D0=B5=D0=BA=D1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 1 - dev/geometry-dev.cbp | 50 +++++++++ dev/geometry-dev.depend | 109 ++++++++++++++++++++ dev/geometry-dev.layout | 10 ++ dev/geometry-dev.vcxproj | 165 +++++++++++++++++++++++++++++ dev/geometry-dev.vcxproj.filters | 22 ++++ dev/geometry-dev.vcxproj.user | 4 + dev/main.c | 172 +++++++++++++++++++++++++++++++ 8 files changed, 532 insertions(+), 1 deletion(-) create mode 100644 dev/geometry-dev.cbp create mode 100644 dev/geometry-dev.depend create mode 100644 dev/geometry-dev.layout create mode 100644 dev/geometry-dev.vcxproj create mode 100644 dev/geometry-dev.vcxproj.filters create mode 100644 dev/geometry-dev.vcxproj.user create mode 100644 dev/main.c diff --git a/.gitignore b/.gitignore index 328ca76..8a4a887 100644 --- a/.gitignore +++ b/.gitignore @@ -56,5 +56,4 @@ Mkfile.old dkms.conf bin obj -dev logs diff --git a/dev/geometry-dev.cbp b/dev/geometry-dev.cbp new file mode 100644 index 0000000..6495c70 --- /dev/null +++ b/dev/geometry-dev.cbp @@ -0,0 +1,50 @@ + + + + + + diff --git a/dev/geometry-dev.depend b/dev/geometry-dev.depend new file mode 100644 index 0000000..c469583 --- /dev/null +++ b/dev/geometry-dev.depend @@ -0,0 +1,109 @@ +# depslib dependency file v1.0 +1729764426 source:/home/andrey/Projects/Private/C/Geometry/dev/main.c + + + + + + + +1729526406 /home/andrey/Projects/Private/C/Geometry/src/geometry.h + "basis.h" + "angle.h" + "vector2.h" + "vector3.h" + "vector4.h" + "matrix2x2.h" + "matrix3x3.h" + "matrix4x4.h" + "tangent.h" + "rotation3.h" + "versor.h" + "affine_map2.h" + "affine_map3.h" + "affine_map4.h" + "position2.h" + "position3.h" + +1729427506 /home/andrey/Projects/Private/C/Geometry/src/basis.h + +1729764440 /home/andrey/Projects/Private/C/Geometry/src/angle.h + +1729503050 /home/andrey/Projects/Private/C/Geometry/src/vector2.h + "basis.h" + "angle.h" + + +1729502950 /home/andrey/Projects/Private/C/Geometry/src/vector3.h + "basis.h" + "angle.h" + + +1729500312 /home/andrey/Projects/Private/C/Geometry/src/vector4.h + "basis.h" + "angle.h" + + +1729490828 /home/andrey/Projects/Private/C/Geometry/src/matrix2x2.h + "vector2.h" + +1729612680 /home/andrey/Projects/Private/C/Geometry/src/matrix3x3.h + "vector3.h" + +1729490844 /home/andrey/Projects/Private/C/Geometry/src/matrix4x4.h + "vector4.h" + +1729490850 /home/andrey/Projects/Private/C/Geometry/src/tangent.h + + "basis.h" + "angle.h" + "vector2.h" + "matrix2x2.h" + +1729428324 /home/andrey/Projects/Private/C/Geometry/src/rotation3.h + "basis.h" + "angle.h" + "vector3.h" + +1729595110 /home/andrey/Projects/Private/C/Geometry/src/versor.h + + "basis.h" + "vector3.h" + "rotation3.h" + "matrix3x3.h" + "matrix4x4.h" + +1729503008 /home/andrey/Projects/Private/C/Geometry/src/affine_map2.h + "vector2.h" + "matrix2x2.h" + +1729502996 /home/andrey/Projects/Private/C/Geometry/src/affine_map3.h + "vector3.h" + "matrix3x3.h" + +1729503020 /home/andrey/Projects/Private/C/Geometry/src/affine_map4.h + "vector4.h" + "matrix4x4.h" + +1729426494 /home/andrey/Projects/Private/C/Geometry/src/cartesian-frame2.h + "vector2.h" + "tangent.h" + "affine_map2.h" + +1729444022 /home/andrey/Projects/Private/C/Geometry/src/cartesian-frame3.h + + "vector3.h" + "versor.h" + "affine_map3.h" + +1729593024 /home/andrey/Projects/Private/C/Geometry/src/position2.h + "vector2.h" + "tangent.h" + "affine_map2.h" + +1729593010 /home/andrey/Projects/Private/C/Geometry/src/position3.h + + "vector3.h" + "versor.h" + "affine_map3.h" + diff --git a/dev/geometry-dev.layout b/dev/geometry-dev.layout new file mode 100644 index 0000000..39a63a4 --- /dev/null +++ b/dev/geometry-dev.layout @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/dev/geometry-dev.vcxproj b/dev/geometry-dev.vcxproj new file mode 100644 index 0000000..b3c937c --- /dev/null +++ b/dev/geometry-dev.vcxproj @@ -0,0 +1,165 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + + + + + {40ca6fb4-135f-4d54-a8d9-7338ba56e6a7} + + + + 16.0 + Win32Proj + {46de6c8f-3179-4652-95cf-28d44ac4774a} + geometry-dev + 10.0 + + + + Application + true + v143 + Unicode + + + Application + false + v143 + true + Unicode + + + Application + true + v143 + Unicode + + + Application + false + v143 + true + Unicode + + + + + + + + + + + + + + + + + + + + + true + + + false + + + true + + + false + + + + Level3 + true + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + CompileAsC + $(SolutionDir)src;%(AdditionalIncludeDirectories) + + + Console + true + + + + + Level3 + true + true + true + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + CompileAsC + $(SolutionDir)src;%(AdditionalIncludeDirectories) + + + Console + true + true + true + + + + + Level3 + true + _DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + CompileAsC + $(SolutionDir)src;%(AdditionalIncludeDirectories) + + + Console + true + + + + + Level3 + true + true + true + NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + CompileAsC + MaxSpeed + $(SolutionDir)src;%(AdditionalIncludeDirectories) + Neither + Sync + NotSet + Precise + + + Console + true + true + true + + + + + + \ No newline at end of file diff --git a/dev/geometry-dev.vcxproj.filters b/dev/geometry-dev.vcxproj.filters new file mode 100644 index 0000000..669bc4e --- /dev/null +++ b/dev/geometry-dev.vcxproj.filters @@ -0,0 +1,22 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + Исходные файлы + + + \ No newline at end of file diff --git a/dev/geometry-dev.vcxproj.user b/dev/geometry-dev.vcxproj.user new file mode 100644 index 0000000..88a5509 --- /dev/null +++ b/dev/geometry-dev.vcxproj.user @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/dev/main.c b/dev/main.c new file mode 100644 index 0000000..9db6f02 --- /dev/null +++ b/dev/main.c @@ -0,0 +1,172 @@ +#include +#include +#include +#include + +#ifdef _WIN64 +#include +#else +#include +#endif // _WINDOWS_ + +SPVersor * allocate_versors(const unsigned int amount) +{ + return calloc(amount, sizeof(SPVersor)); +} + +SPVersor * make_zero_versors(const unsigned int amount) +{ + SPVersor * list = allocate_versors(amount); + + if (list == 0) { + return 0; + } + + for (unsigned int i = 0; i < amount; i++) { + sp_versor_reset(&list[i]); + } + + return list; +} + +SPVersor * make_random_versors(const unsigned int amount) +{ + SPVersor * list = allocate_versors(amount); + + if (list == 0) { + return 0; + } + + for (unsigned int i = 0; i < amount; i++) { + sp_versor_set( + (2.0f * rand()) / RAND_MAX - 1.0f, + (2.0f * rand()) / RAND_MAX - 1.0f, + (2.0f * rand()) / RAND_MAX - 1.0f, + (2.0f * rand()) / RAND_MAX - 1.0f, + &list[i] + ); + } + + return list; +} + +void print_versor(const SPVersor * versor) +{ + printf("(%f, %f, %f, %f) / %e\n", versor->_s0, versor->_x1, versor->_x2, versor->_x3, versor->_corrector - 1.0f); +} + +/*/ +int main() +{ + const unsigned int amount = 1000000; + +#ifdef _WIN64 + ULONGLONG now; + now = GetTickCount64(); + srand((unsigned int)(now & 0xfffffff)); +#else + struct timespec now; + clock_gettime(CLOCK_REALTIME, &now); + srand((unsigned int)(now.tv_nsec & 0xfffffff)); +#endif // _WIN64 + + SPVersor * versors1 = make_random_versors(amount); + + if (versors1 == 0) { + printf("Cannot allocate memory for versors1"); + return 0; + } + + SPVersor * versors2 = make_random_versors(amount); + + if (versors2 == 0) { + printf("Cannot allocate memory for versors2"); + free(versors1); + return 0; + } + + SPVersor * results = make_zero_versors(amount); + + if (results == 0) { + printf("Cannot allocate memory for results"); + free(versors2); + free(versors1); + return 0; + } + +#ifdef _WIN64 + ULONGLONG start, end; + start = GetTickCount64(); +#else + struct timespec start, end; + clock_gettime(CLOCK_REALTIME, &start); +#endif // _WIN64 + for (int j = 0; j < 1000; j++) { + for (unsigned int i = 0; i < amount; i++) { + sp_versor_combine2(&versors1[i], &versors2[i], &results[i]); + } + } + +#ifdef _WIN64 + end = GetTickCount64(); + + printf("Time: %lld\n", end - start); +#else + clock_gettime(CLOCK_REALTIME, &end); + + printf("Time: %lf\n", (end.tv_sec - start.tv_sec) * 1000.0 + (end.tv_nsec - start.tv_nsec) * 0.000001); +#endif // _WIN64 + + print_versor(versors1 + 10); + print_versor(versors2 + 10); + print_versor(results + 10); + + free(results); + free(versors2); + free(versors1); + return 0; +} + +/*/ + +void print_matrix(const DPMatrix3x3* matrix) +{ + printf("(%lf, %lf, %lf)\n", matrix->r1c1, matrix->r1c2, matrix->r1c3); + printf("(%lf, %lf, %lf)\n", matrix->r2c1, matrix->r2c2, matrix->r2c3); + printf("(%lf, %lf, %lf)\n\n", matrix->r3c1, matrix->r3c2, matrix->r3c3); +} + +int main() +{ + DPMatrix3x3 m1, m2, check; + + dp_matrix3x3_set_row1(1, 3, 5, &m1); + dp_matrix3x3_set_row2(2, 2, -1, &m1); + dp_matrix3x3_set_row3(2, 0, 4, &m1); + + printf("Initial matrix:\n"); + print_matrix(&m1); + + if (!dp_matrix3x3_make_inverted(&m1, &m2)) { + printf("Cannot get the inverted matrix.\n"); + return 0; + } + + printf("Inverted matrix:\n"); + + print_matrix(&m2); + + dp_matrix3x3_matrix_product(&m1, &m2, &check); + + printf("m1 * m2:\n"); + + print_matrix(&check); + + dp_matrix3x3_matrix_product(&m2, &m1, &check); + + printf("m2 * m1:\n"); + + print_matrix(&check); + + return 0; +}