From fd4353239b154a732d9ffc531aa0807b23fd0983 Mon Sep 17 00:00:00 2001 From: pavl_g Date: Tue, 2 May 2023 09:19:36 +0300 Subject: [PATCH 01/17] arithmos-core: base libvector2d api --- arithmos-core/CMakeLists.txt | 17 +++++-- arithmos-core/src/include/coordinate.h | 41 +++++++++++++++++ arithmos-core/src/include/foobar.h | 37 --------------- arithmos-core/src/include/vector2d.h | 46 +++++++++++++++++++ arithmos-core/src/libfoo/destroy_foo.c | 4 -- arithmos-core/src/libfoo/do_foo.c | 10 ---- arithmos-core/src/libfoo/init_foo.c | 4 -- arithmos-core/src/libvector2d/vector2d_add.c | 9 ++++ .../src/libvector2d/vector2d_angle.c | 11 +++++ .../src/libvector2d/vector2d_dot_product.c | 5 ++ .../src/libvector2d/vector2d_is_dependent.c | 5 ++ .../src/libvector2d/vector2d_length.c | 5 ++ arithmos-core/src/libvector2d/vector2d_lerp.c | 13 ++++++ .../src/libvector2d/vector2d_normalize.c | 8 ++++ .../src/libvector2d/vector2d_polar.c | 5 ++ .../src/libvector2d/vector2d_scalar_add.c | 7 +++ .../src/libvector2d/vector2d_scalar_divide.c | 7 +++ .../src/libvector2d/vector2d_scalar_moduluo.c | 5 ++ .../libvector2d/vector2d_scalar_multiply.c | 7 +++ .../libvector2d/vector2d_scalar_subtract.c | 7 +++ .../src/libvector2d/vector2d_subtract.c | 9 ++++ 21 files changed, 203 insertions(+), 59 deletions(-) create mode 100644 arithmos-core/src/include/coordinate.h delete mode 100644 arithmos-core/src/include/foobar.h create mode 100644 arithmos-core/src/include/vector2d.h delete mode 100644 arithmos-core/src/libfoo/destroy_foo.c delete mode 100644 arithmos-core/src/libfoo/do_foo.c delete mode 100644 arithmos-core/src/libfoo/init_foo.c create mode 100644 arithmos-core/src/libvector2d/vector2d_add.c create mode 100644 arithmos-core/src/libvector2d/vector2d_angle.c create mode 100644 arithmos-core/src/libvector2d/vector2d_dot_product.c create mode 100644 arithmos-core/src/libvector2d/vector2d_is_dependent.c create mode 100644 arithmos-core/src/libvector2d/vector2d_length.c create mode 100644 arithmos-core/src/libvector2d/vector2d_lerp.c create mode 100644 arithmos-core/src/libvector2d/vector2d_normalize.c create mode 100644 arithmos-core/src/libvector2d/vector2d_polar.c create mode 100644 arithmos-core/src/libvector2d/vector2d_scalar_add.c create mode 100644 arithmos-core/src/libvector2d/vector2d_scalar_divide.c create mode 100644 arithmos-core/src/libvector2d/vector2d_scalar_moduluo.c create mode 100644 arithmos-core/src/libvector2d/vector2d_scalar_multiply.c create mode 100644 arithmos-core/src/libvector2d/vector2d_scalar_subtract.c create mode 100644 arithmos-core/src/libvector2d/vector2d_subtract.c diff --git a/arithmos-core/CMakeLists.txt b/arithmos-core/CMakeLists.txt index 955b018..699f9f8 100644 --- a/arithmos-core/CMakeLists.txt +++ b/arithmos-core/CMakeLists.txt @@ -14,13 +14,22 @@ set(CMAKE_CXX_COMPILER "${TOOLCHAIN_HOME}/bin/avr-g++") set(COMPILER_OPTIONS "-mmcu=${TARGET} -O3") set(toolchain_headers "${TOOLCHAIN_HOME}/toolchain/include/") -set(libfoobar "${CMAKE_CURRENT_SOURCE_DIR}/src/libfoo/do_foo.c" - "${CMAKE_CURRENT_SOURCE_DIR}/src/libfoo/init_foo.c" - "${CMAKE_CURRENT_SOURCE_DIR}/src/libfoo/destroy_foo.c") +set(libvector2d "${CMAKE_CURRENT_SOURCE_DIR}/src/libvector2d/vector2d_add.c" + "${CMAKE_CURRENT_SOURCE_DIR}/src/libvector2d/vector2d_angle.c" + "${CMAKE_CURRENT_SOURCE_DIR}/src/libvector2d/vector2d_dot_product.c" + "${CMAKE_CURRENT_SOURCE_DIR}/src/libvector2d/vector2d_length.c" + "${CMAKE_CURRENT_SOURCE_DIR}/src/libvector2d/vector2d_lerp.c" + "${CMAKE_CURRENT_SOURCE_DIR}/src/libvector2d/vector2d_normalize.c" + "${CMAKE_CURRENT_SOURCE_DIR}/src/libvector2d/vector2d_polar.c" + "${CMAKE_CURRENT_SOURCE_DIR}/src/libvector2d/vector2d_scalar_add.c" + "${CMAKE_CURRENT_SOURCE_DIR}/src/libvector2d/vector2d_scalar_divide.c" + "${CMAKE_CURRENT_SOURCE_DIR}/src/libvector2d/vector2d_scalar_multiply.c" + "${CMAKE_CURRENT_SOURCE_DIR}/src/libvector2d/vector2d_scalar_subtract.c" + "${CMAKE_CURRENT_SOURCE_DIR}/src/libvector2d/vector2d_subtract.c") set(headers "${toolchain_headers}" "${CMAKE_CURRENT_SOURCE_DIR}/src/include/") -set(sources ${libfoobar}) +set(sources ${libvector2d}) # add a library target add_library(${library} STATIC ${sources}) diff --git a/arithmos-core/src/include/coordinate.h b/arithmos-core/src/include/coordinate.h new file mode 100644 index 0000000..a4efb32 --- /dev/null +++ b/arithmos-core/src/include/coordinate.h @@ -0,0 +1,41 @@ +#ifndef _COORDINATE_H_ +#define _COORDINATE_H_ + +#include + +#if defined (_VECTOR2D_USE_INT8_) +# define coordinate uint8_t +# define vector2d_pow(v, p) ((uint8_t) powf(v, p)) +# define vector2d_atan2(y, x) ((uint8_t) atan2f(y, x)) +# define vector2d_acos(v) ((uint8_t) acosf(v)) +#elif defined (_VECTOR2D_USE_INT16_) +# define coordinate uint16_t +# define vector2d_pow(v, p) ((uint16_t) powf(v, p)) +# define vector2d_atan2(y, x) ((uint16_t) atan2f(y, x)) +# define vector2d_acos(v) ((uint16_t) acosf(v)) +#elif defined (_VECTOR2D_USE_INT32_) +# define coordinate uint32_t +# define vector2d_pow(v, p) ((uint32_t) powf(v, p)) +# define vector2d_atan2(y, x) ((uint32_t) atan2f(y, x)) +# define vector2d_acos(v) ((uint32_t) acosf(v)) +#elif defined (_VECTOR2D_USE_INT64_) +# define coordinate uint64_t +# define vector2d_pow(v, p) ((uint64_t) powf(v, p)) +# define vector2d_atan2(y, x) ((uint64_t) atan2l(y, x)) +# define vector2d_acos(v) ((uint64_t) acosl(v)) +#elif defined (_VECTOR2D_USE_DOUBLE_) +# define coordinate double +# define vector2d_pow(v, p) ((double) powf(v, p)) +# define vector2d_atan2(y, x) ((double) atan2l(y, x)) +# define vector2d_acos(v) ((double) acosl(v)) +#else +# define coordinate float +# define vector2d_pow(v, p) ((float) powf(v, p)) +# define vector2d_atan2(y, x) ((float) atan2f(y, x)) +# define vector2d_acos(v) ((float) acosf(v)) +#endif + +#define vector2d_sqrt(v) vector2d_pow(v, 0.5) +#define vector2d_abs(v) ((coordinate) vector2d_sqrt(vector2d_pow(v, 2))) + +#endif // _COORDINATE_H_ \ No newline at end of file diff --git a/arithmos-core/src/include/foobar.h b/arithmos-core/src/include/foobar.h deleted file mode 100644 index 2607214..0000000 --- a/arithmos-core/src/include/foobar.h +++ /dev/null @@ -1,37 +0,0 @@ -#ifndef _FOOBAR_H_ -#define _FOOBAR_H_ - -#include - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * @brief Callbacks data structure. - */ -typedef struct { - void (*on_foo_created)(void**); - void (*on_foo_destroyed)(void**); -} foobar_callbacks; - -/** - * @brief Compilation unit code. - */ -extern void init_foo(); - -/** - * @brief Compilation unit code. - */ -extern void do_foo(); - -/** - * @brief Compilation unit code. - */ -extern void destroy_foo(); - -#ifdef __cplusplus -} -#endif - -#endif //_FOOBAR_H_ diff --git a/arithmos-core/src/include/vector2d.h b/arithmos-core/src/include/vector2d.h new file mode 100644 index 0000000..8d1a610 --- /dev/null +++ b/arithmos-core/src/include/vector2d.h @@ -0,0 +1,46 @@ +#ifndef _vector2d_H_ +#define _vector2d_H_ + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct { + coordinate x; + coordinate y; +} vector2d; + +extern vector2d* vector2d_scalar_add(vector2d*, coordinate); + +extern vector2d* vector2d_scalar_subtract(vector2d*, coordinate); + +extern vector2d* vector2d_scalar_multiply(vector2d*, coordinate); + +extern vector2d* vector2d_scalar_divide(vector2d*, coordinate); + +extern vector2d* vector2d_normalize(vector2d*); + +extern vector2d vector2d_add(vector2d, vector2d); + +extern vector2d vector2d_subtract(vector2d, vector2d); + +extern vector2d vector2d_lerp(vector2d, vector2d, coordinate); + +extern coordinate vector2d_dot_product(vector2d, vector2d); + +extern coordinate vector2d_angle(vector2d, vector2d); + +extern coordinate vector2d_length(vector2d); + +extern coordinate vector2d_polar(vector2d); + +extern int vector2d_is_dependent(vector2d, vector2d); + +#ifdef __cplusplus +} +#endif + +#endif //_vector2d_H_ diff --git a/arithmos-core/src/libfoo/destroy_foo.c b/arithmos-core/src/libfoo/destroy_foo.c deleted file mode 100644 index 96823e7..0000000 --- a/arithmos-core/src/libfoo/destroy_foo.c +++ /dev/null @@ -1,4 +0,0 @@ -#include - -void destroy_foo() { -} \ No newline at end of file diff --git a/arithmos-core/src/libfoo/do_foo.c b/arithmos-core/src/libfoo/do_foo.c deleted file mode 100644 index a713053..0000000 --- a/arithmos-core/src/libfoo/do_foo.c +++ /dev/null @@ -1,10 +0,0 @@ -/** - * @brief Represents a compilation unit defining a function definition. - * @author pavl_g. - * @copyright Unlicensed license. - */ -#include - -void do_foo() { - printf("Fetch me a tank of coffee!\n"); -} \ No newline at end of file diff --git a/arithmos-core/src/libfoo/init_foo.c b/arithmos-core/src/libfoo/init_foo.c deleted file mode 100644 index 99ff7de..0000000 --- a/arithmos-core/src/libfoo/init_foo.c +++ /dev/null @@ -1,4 +0,0 @@ -#include - -void init_foo() { -} \ No newline at end of file diff --git a/arithmos-core/src/libvector2d/vector2d_add.c b/arithmos-core/src/libvector2d/vector2d_add.c new file mode 100644 index 0000000..1c3032d --- /dev/null +++ b/arithmos-core/src/libvector2d/vector2d_add.c @@ -0,0 +1,9 @@ +#include + +vector2d vector2d_add(vector2d vec0, vector2d vec1) { + vector2d summation = { + vec0.x + vec1.x, + vec0.y + vec1.y + }; + return summation; +} \ No newline at end of file diff --git a/arithmos-core/src/libvector2d/vector2d_angle.c b/arithmos-core/src/libvector2d/vector2d_angle.c new file mode 100644 index 0000000..b99a232 --- /dev/null +++ b/arithmos-core/src/libvector2d/vector2d_angle.c @@ -0,0 +1,11 @@ +#include + +coordinate vector2d_angle(vector2d vec0, vector2d vec1) { + // 1) find the dot product + coordinate product = vector2d_dot_product(vec0, vec1); + // 2) find the norm of both vectors + coordinate vec0_norm = vector2d_length(vec0); + coordinate vec1_norm = vector2d_length(vec1); + // 3) find the angle of their inner product in this vector space + return vector2d_acos(product / (vec0_norm * vec1_norm)); +} \ No newline at end of file diff --git a/arithmos-core/src/libvector2d/vector2d_dot_product.c b/arithmos-core/src/libvector2d/vector2d_dot_product.c new file mode 100644 index 0000000..c2262c9 --- /dev/null +++ b/arithmos-core/src/libvector2d/vector2d_dot_product.c @@ -0,0 +1,5 @@ +#include + +coordinate vector2d_dot_product(vector2d vec0, vector2d vec1) { + return vec0.x * vec1.x + vec0.y * vec1.y; +} \ No newline at end of file diff --git a/arithmos-core/src/libvector2d/vector2d_is_dependent.c b/arithmos-core/src/libvector2d/vector2d_is_dependent.c new file mode 100644 index 0000000..545b6c5 --- /dev/null +++ b/arithmos-core/src/libvector2d/vector2d_is_dependent.c @@ -0,0 +1,5 @@ +#include + +int vector2d_is_dependent(vector2d vec0, vector2d vec1) { + return 0; +} \ No newline at end of file diff --git a/arithmos-core/src/libvector2d/vector2d_length.c b/arithmos-core/src/libvector2d/vector2d_length.c new file mode 100644 index 0000000..731eeca --- /dev/null +++ b/arithmos-core/src/libvector2d/vector2d_length.c @@ -0,0 +1,5 @@ +#include + +coordinate vector2d_length(vector2d vec) { + return vector2d_sqrt(vector2d_pow(vec.x, 2) + vector2d_pow(vec.y, 2)); +} \ No newline at end of file diff --git a/arithmos-core/src/libvector2d/vector2d_lerp.c b/arithmos-core/src/libvector2d/vector2d_lerp.c new file mode 100644 index 0000000..5ecea7b --- /dev/null +++ b/arithmos-core/src/libvector2d/vector2d_lerp.c @@ -0,0 +1,13 @@ +#include + +vector2d vector2d_lerp(vector2d vec0, vector2d vec1, coordinate scale) { + // 1) find the absolute x_distance and y_distance + coordinate x_distance = vector2d_abs(vec0.x - vec1.x); + coordinate y_distance = vector2d_abs(vec0.y - vec1.y); + // 2) interpolate between components with a scale starting from the first vector + vector2d lerp = { + ((x_distance) * scale) + vec0.x, + ((y_distance) * scale) + vec0.y + }; + return lerp; +} \ No newline at end of file diff --git a/arithmos-core/src/libvector2d/vector2d_normalize.c b/arithmos-core/src/libvector2d/vector2d_normalize.c new file mode 100644 index 0000000..36f3ed5 --- /dev/null +++ b/arithmos-core/src/libvector2d/vector2d_normalize.c @@ -0,0 +1,8 @@ +#include + +vector2d* vector2d_normalize(vector2d* vec) { + coordinate length = { + vector2d_length(*vec) + }; + return vector2d_scalar_divide(vec, length); +} \ No newline at end of file diff --git a/arithmos-core/src/libvector2d/vector2d_polar.c b/arithmos-core/src/libvector2d/vector2d_polar.c new file mode 100644 index 0000000..81852a1 --- /dev/null +++ b/arithmos-core/src/libvector2d/vector2d_polar.c @@ -0,0 +1,5 @@ +#include + +coordinate vector2d_polar(vector2d vec) { + return vector2d_atan2(vec.y, vec.x); +} \ No newline at end of file diff --git a/arithmos-core/src/libvector2d/vector2d_scalar_add.c b/arithmos-core/src/libvector2d/vector2d_scalar_add.c new file mode 100644 index 0000000..6ef1884 --- /dev/null +++ b/arithmos-core/src/libvector2d/vector2d_scalar_add.c @@ -0,0 +1,7 @@ +#include + +vector2d* vector2d_scalar_add(vector2d* vec, coordinate scalar) { + vec->x += scalar; + vec->y += scalar; + return vec; +} \ No newline at end of file diff --git a/arithmos-core/src/libvector2d/vector2d_scalar_divide.c b/arithmos-core/src/libvector2d/vector2d_scalar_divide.c new file mode 100644 index 0000000..5c2ab34 --- /dev/null +++ b/arithmos-core/src/libvector2d/vector2d_scalar_divide.c @@ -0,0 +1,7 @@ +#include + +vector2d* vector2d_scalar_divide(vector2d* vec, coordinate scalar) { + vec->x /= scalar; + vec->y /= scalar; + return vec; +} \ No newline at end of file diff --git a/arithmos-core/src/libvector2d/vector2d_scalar_moduluo.c b/arithmos-core/src/libvector2d/vector2d_scalar_moduluo.c new file mode 100644 index 0000000..c8c1e33 --- /dev/null +++ b/arithmos-core/src/libvector2d/vector2d_scalar_moduluo.c @@ -0,0 +1,5 @@ +#include + +vector2d* vector2f_scalar_moduluo(vector2d* vec, coordinate scalar) { + return 0; +} \ No newline at end of file diff --git a/arithmos-core/src/libvector2d/vector2d_scalar_multiply.c b/arithmos-core/src/libvector2d/vector2d_scalar_multiply.c new file mode 100644 index 0000000..a5252bc --- /dev/null +++ b/arithmos-core/src/libvector2d/vector2d_scalar_multiply.c @@ -0,0 +1,7 @@ +#include + +vector2d* vector2d_scalar_multiply(vector2d* vec, coordinate scalar) { + vec->x *= scalar; + vec->y *= scalar; + return vec; +} \ No newline at end of file diff --git a/arithmos-core/src/libvector2d/vector2d_scalar_subtract.c b/arithmos-core/src/libvector2d/vector2d_scalar_subtract.c new file mode 100644 index 0000000..7733332 --- /dev/null +++ b/arithmos-core/src/libvector2d/vector2d_scalar_subtract.c @@ -0,0 +1,7 @@ +#include + +vector2d* vector2d_scalar_subtract(vector2d* vec, coordinate scalar) { + vec->x -= scalar; + vec->y -= scalar; + return vec; +} \ No newline at end of file diff --git a/arithmos-core/src/libvector2d/vector2d_subtract.c b/arithmos-core/src/libvector2d/vector2d_subtract.c new file mode 100644 index 0000000..2be4f63 --- /dev/null +++ b/arithmos-core/src/libvector2d/vector2d_subtract.c @@ -0,0 +1,9 @@ +#include + +vector2d vector2d_subtract(vector2d vec0, vector2d vec1) { + vector2d subtraction = { + vec0.x - vec1.x, + vec0.y - vec1.y + }; + return subtraction; +} \ No newline at end of file From b83071d7fc5cb127722f5fb04a7137dcd5346ae0 Mon Sep 17 00:00:00 2001 From: pavl_g Date: Tue, 2 May 2023 09:23:42 +0300 Subject: [PATCH 02/17] libvector2d: added library header folder --- .../src/include/{ => vectorspaces/vector2d}/coordinate.h | 4 ++++ .../src/include/{ => vectorspaces/vector2d}/vector2d.h | 2 +- arithmos-core/src/libvector2d/vector2d_add.c | 2 +- arithmos-core/src/libvector2d/vector2d_angle.c | 2 +- arithmos-core/src/libvector2d/vector2d_dot_product.c | 2 +- arithmos-core/src/libvector2d/vector2d_is_dependent.c | 2 +- arithmos-core/src/libvector2d/vector2d_length.c | 2 +- arithmos-core/src/libvector2d/vector2d_lerp.c | 2 +- arithmos-core/src/libvector2d/vector2d_normalize.c | 2 +- arithmos-core/src/libvector2d/vector2d_polar.c | 2 +- arithmos-core/src/libvector2d/vector2d_scalar_add.c | 2 +- arithmos-core/src/libvector2d/vector2d_scalar_divide.c | 2 +- arithmos-core/src/libvector2d/vector2d_scalar_moduluo.c | 2 +- arithmos-core/src/libvector2d/vector2d_scalar_multiply.c | 2 +- arithmos-core/src/libvector2d/vector2d_scalar_subtract.c | 2 +- arithmos-core/src/libvector2d/vector2d_subtract.c | 2 +- 16 files changed, 19 insertions(+), 15 deletions(-) rename arithmos-core/src/include/{ => vectorspaces/vector2d}/coordinate.h (95%) rename arithmos-core/src/include/{ => vectorspaces/vector2d}/vector2d.h (96%) diff --git a/arithmos-core/src/include/coordinate.h b/arithmos-core/src/include/vectorspaces/vector2d/coordinate.h similarity index 95% rename from arithmos-core/src/include/coordinate.h rename to arithmos-core/src/include/vectorspaces/vector2d/coordinate.h index a4efb32..5ffd00d 100644 --- a/arithmos-core/src/include/coordinate.h +++ b/arithmos-core/src/include/vectorspaces/vector2d/coordinate.h @@ -1,3 +1,7 @@ +#ifndef _vector2d_H_ +# error "Use vector2d instead of this!" +#endif + #ifndef _COORDINATE_H_ #define _COORDINATE_H_ diff --git a/arithmos-core/src/include/vector2d.h b/arithmos-core/src/include/vectorspaces/vector2d/vector2d.h similarity index 96% rename from arithmos-core/src/include/vector2d.h rename to arithmos-core/src/include/vectorspaces/vector2d/vector2d.h index 8d1a610..3cae935 100644 --- a/arithmos-core/src/include/vector2d.h +++ b/arithmos-core/src/include/vectorspaces/vector2d/vector2d.h @@ -2,7 +2,7 @@ #define _vector2d_H_ #include -#include +#include #ifdef __cplusplus extern "C" { diff --git a/arithmos-core/src/libvector2d/vector2d_add.c b/arithmos-core/src/libvector2d/vector2d_add.c index 1c3032d..e7a2fbc 100644 --- a/arithmos-core/src/libvector2d/vector2d_add.c +++ b/arithmos-core/src/libvector2d/vector2d_add.c @@ -1,4 +1,4 @@ -#include +#include vector2d vector2d_add(vector2d vec0, vector2d vec1) { vector2d summation = { diff --git a/arithmos-core/src/libvector2d/vector2d_angle.c b/arithmos-core/src/libvector2d/vector2d_angle.c index b99a232..51b2a8a 100644 --- a/arithmos-core/src/libvector2d/vector2d_angle.c +++ b/arithmos-core/src/libvector2d/vector2d_angle.c @@ -1,4 +1,4 @@ -#include +#include coordinate vector2d_angle(vector2d vec0, vector2d vec1) { // 1) find the dot product diff --git a/arithmos-core/src/libvector2d/vector2d_dot_product.c b/arithmos-core/src/libvector2d/vector2d_dot_product.c index c2262c9..b88a846 100644 --- a/arithmos-core/src/libvector2d/vector2d_dot_product.c +++ b/arithmos-core/src/libvector2d/vector2d_dot_product.c @@ -1,4 +1,4 @@ -#include +#include coordinate vector2d_dot_product(vector2d vec0, vector2d vec1) { return vec0.x * vec1.x + vec0.y * vec1.y; diff --git a/arithmos-core/src/libvector2d/vector2d_is_dependent.c b/arithmos-core/src/libvector2d/vector2d_is_dependent.c index 545b6c5..4380b61 100644 --- a/arithmos-core/src/libvector2d/vector2d_is_dependent.c +++ b/arithmos-core/src/libvector2d/vector2d_is_dependent.c @@ -1,4 +1,4 @@ -#include +#include int vector2d_is_dependent(vector2d vec0, vector2d vec1) { return 0; diff --git a/arithmos-core/src/libvector2d/vector2d_length.c b/arithmos-core/src/libvector2d/vector2d_length.c index 731eeca..ba70e82 100644 --- a/arithmos-core/src/libvector2d/vector2d_length.c +++ b/arithmos-core/src/libvector2d/vector2d_length.c @@ -1,4 +1,4 @@ -#include +#include coordinate vector2d_length(vector2d vec) { return vector2d_sqrt(vector2d_pow(vec.x, 2) + vector2d_pow(vec.y, 2)); diff --git a/arithmos-core/src/libvector2d/vector2d_lerp.c b/arithmos-core/src/libvector2d/vector2d_lerp.c index 5ecea7b..62d6f26 100644 --- a/arithmos-core/src/libvector2d/vector2d_lerp.c +++ b/arithmos-core/src/libvector2d/vector2d_lerp.c @@ -1,4 +1,4 @@ -#include +#include vector2d vector2d_lerp(vector2d vec0, vector2d vec1, coordinate scale) { // 1) find the absolute x_distance and y_distance diff --git a/arithmos-core/src/libvector2d/vector2d_normalize.c b/arithmos-core/src/libvector2d/vector2d_normalize.c index 36f3ed5..a5aa15d 100644 --- a/arithmos-core/src/libvector2d/vector2d_normalize.c +++ b/arithmos-core/src/libvector2d/vector2d_normalize.c @@ -1,4 +1,4 @@ -#include +#include vector2d* vector2d_normalize(vector2d* vec) { coordinate length = { diff --git a/arithmos-core/src/libvector2d/vector2d_polar.c b/arithmos-core/src/libvector2d/vector2d_polar.c index 81852a1..913f1b3 100644 --- a/arithmos-core/src/libvector2d/vector2d_polar.c +++ b/arithmos-core/src/libvector2d/vector2d_polar.c @@ -1,4 +1,4 @@ -#include +#include coordinate vector2d_polar(vector2d vec) { return vector2d_atan2(vec.y, vec.x); diff --git a/arithmos-core/src/libvector2d/vector2d_scalar_add.c b/arithmos-core/src/libvector2d/vector2d_scalar_add.c index 6ef1884..c557de9 100644 --- a/arithmos-core/src/libvector2d/vector2d_scalar_add.c +++ b/arithmos-core/src/libvector2d/vector2d_scalar_add.c @@ -1,4 +1,4 @@ -#include +#include vector2d* vector2d_scalar_add(vector2d* vec, coordinate scalar) { vec->x += scalar; diff --git a/arithmos-core/src/libvector2d/vector2d_scalar_divide.c b/arithmos-core/src/libvector2d/vector2d_scalar_divide.c index 5c2ab34..e85c850 100644 --- a/arithmos-core/src/libvector2d/vector2d_scalar_divide.c +++ b/arithmos-core/src/libvector2d/vector2d_scalar_divide.c @@ -1,4 +1,4 @@ -#include +#include vector2d* vector2d_scalar_divide(vector2d* vec, coordinate scalar) { vec->x /= scalar; diff --git a/arithmos-core/src/libvector2d/vector2d_scalar_moduluo.c b/arithmos-core/src/libvector2d/vector2d_scalar_moduluo.c index c8c1e33..35edeae 100644 --- a/arithmos-core/src/libvector2d/vector2d_scalar_moduluo.c +++ b/arithmos-core/src/libvector2d/vector2d_scalar_moduluo.c @@ -1,4 +1,4 @@ -#include +#include vector2d* vector2f_scalar_moduluo(vector2d* vec, coordinate scalar) { return 0; diff --git a/arithmos-core/src/libvector2d/vector2d_scalar_multiply.c b/arithmos-core/src/libvector2d/vector2d_scalar_multiply.c index a5252bc..5cf3b20 100644 --- a/arithmos-core/src/libvector2d/vector2d_scalar_multiply.c +++ b/arithmos-core/src/libvector2d/vector2d_scalar_multiply.c @@ -1,4 +1,4 @@ -#include +#include vector2d* vector2d_scalar_multiply(vector2d* vec, coordinate scalar) { vec->x *= scalar; diff --git a/arithmos-core/src/libvector2d/vector2d_scalar_subtract.c b/arithmos-core/src/libvector2d/vector2d_scalar_subtract.c index 7733332..e6f4d2c 100644 --- a/arithmos-core/src/libvector2d/vector2d_scalar_subtract.c +++ b/arithmos-core/src/libvector2d/vector2d_scalar_subtract.c @@ -1,4 +1,4 @@ -#include +#include vector2d* vector2d_scalar_subtract(vector2d* vec, coordinate scalar) { vec->x -= scalar; diff --git a/arithmos-core/src/libvector2d/vector2d_subtract.c b/arithmos-core/src/libvector2d/vector2d_subtract.c index 2be4f63..73e797e 100644 --- a/arithmos-core/src/libvector2d/vector2d_subtract.c +++ b/arithmos-core/src/libvector2d/vector2d_subtract.c @@ -1,4 +1,4 @@ -#include +#include vector2d vector2d_subtract(vector2d vec0, vector2d vec1) { vector2d subtraction = { From ca57774637d174dd8ce93e6fcef98ede822c53ed Mon Sep 17 00:00:00 2001 From: pavl_g Date: Wed, 3 May 2023 02:52:56 +0300 Subject: [PATCH 03/17] libvector2d: more vector functions and optimizations --- arithmos-core/CMakeLists.txt | 2 + .../vectorspaces/{vector2d => }/coordinate.h | 42 ++++++++++++++++--- .../include/vectorspaces/vector2d/vector2d.h | 6 ++- arithmos-core/src/libvector2d/vector2d_add.c | 2 +- .../src/libvector2d/vector2d_angle.c | 2 +- .../src/libvector2d/vector2d_distance.c | 5 +++ .../src/libvector2d/vector2d_dot_product.c | 2 +- .../src/libvector2d/vector2d_is_dependent.c | 2 +- .../src/libvector2d/vector2d_length.c | 2 +- arithmos-core/src/libvector2d/vector2d_lerp.c | 2 +- .../src/libvector2d/vector2d_normalize.c | 2 +- .../src/libvector2d/vector2d_polar.c | 2 +- .../src/libvector2d/vector2d_scalar_add.c | 2 +- .../src/libvector2d/vector2d_scalar_divide.c | 2 +- .../src/libvector2d/vector2d_scalar_moduluo.c | 6 ++- .../libvector2d/vector2d_scalar_multiply.c | 2 +- .../libvector2d/vector2d_scalar_subtract.c | 2 +- .../src/libvector2d/vector2d_subtract.c | 2 +- 18 files changed, 65 insertions(+), 22 deletions(-) rename arithmos-core/src/include/vectorspaces/{vector2d => }/coordinate.h (51%) create mode 100644 arithmos-core/src/libvector2d/vector2d_distance.c diff --git a/arithmos-core/CMakeLists.txt b/arithmos-core/CMakeLists.txt index 699f9f8..2779e0d 100644 --- a/arithmos-core/CMakeLists.txt +++ b/arithmos-core/CMakeLists.txt @@ -17,6 +17,7 @@ set(toolchain_headers "${TOOLCHAIN_HOME}/toolchain/include/") set(libvector2d "${CMAKE_CURRENT_SOURCE_DIR}/src/libvector2d/vector2d_add.c" "${CMAKE_CURRENT_SOURCE_DIR}/src/libvector2d/vector2d_angle.c" "${CMAKE_CURRENT_SOURCE_DIR}/src/libvector2d/vector2d_dot_product.c" + "${CMAKE_CURRENT_SOURCE_DIR}/src/libvector2d/vector2d_distance.c" "${CMAKE_CURRENT_SOURCE_DIR}/src/libvector2d/vector2d_length.c" "${CMAKE_CURRENT_SOURCE_DIR}/src/libvector2d/vector2d_lerp.c" "${CMAKE_CURRENT_SOURCE_DIR}/src/libvector2d/vector2d_normalize.c" @@ -25,6 +26,7 @@ set(libvector2d "${CMAKE_CURRENT_SOURCE_DIR}/src/libvector2d/vector2d_add.c" "${CMAKE_CURRENT_SOURCE_DIR}/src/libvector2d/vector2d_scalar_divide.c" "${CMAKE_CURRENT_SOURCE_DIR}/src/libvector2d/vector2d_scalar_multiply.c" "${CMAKE_CURRENT_SOURCE_DIR}/src/libvector2d/vector2d_scalar_subtract.c" + "${CMAKE_CURRENT_SOURCE_DIR}/src/libvector2d/vector2d_scalar_moduluo.c" "${CMAKE_CURRENT_SOURCE_DIR}/src/libvector2d/vector2d_subtract.c") set(headers "${toolchain_headers}" diff --git a/arithmos-core/src/include/vectorspaces/vector2d/coordinate.h b/arithmos-core/src/include/vectorspaces/coordinate.h similarity index 51% rename from arithmos-core/src/include/vectorspaces/vector2d/coordinate.h rename to arithmos-core/src/include/vectorspaces/coordinate.h index 5ffd00d..7370e08 100644 --- a/arithmos-core/src/include/vectorspaces/vector2d/coordinate.h +++ b/arithmos-core/src/include/vectorspaces/coordinate.h @@ -7,33 +7,63 @@ #include -#if defined (_VECTOR2D_USE_INT8_) +#if defined (_VECTOR2D_USE_UINT8_) # define coordinate uint8_t +# define mod_coordinate coordinate # define vector2d_pow(v, p) ((uint8_t) powf(v, p)) # define vector2d_atan2(y, x) ((uint8_t) atan2f(y, x)) # define vector2d_acos(v) ((uint8_t) acosf(v)) -#elif defined (_VECTOR2D_USE_INT16_) +#elif defined (_VECTOR2D_USE_INT8_) +# define coordinate int8_t +# define mod_coordinate coordinate +# define vector2d_pow(v, p) ((int8_t) powf(v, p)) +# define vector2d_atan2(y, x) ((int8_t) atan2f(y, x)) +# define vector2d_acos(v) ((int8_t) acosf(v)) +#elif defined (_VECTOR2D_USE_UINT16_) # define coordinate uint16_t +# define mod_coordinate coordinate # define vector2d_pow(v, p) ((uint16_t) powf(v, p)) # define vector2d_atan2(y, x) ((uint16_t) atan2f(y, x)) # define vector2d_acos(v) ((uint16_t) acosf(v)) -#elif defined (_VECTOR2D_USE_INT32_) +#elif defined (_VECTOR2D_USE_INT16_) +# define coordinate int16_t +# define mod_coordinate coordinate +# define vector2d_pow(v, p) ((int16_t) powf(v, p)) +# define vector2d_atan2(y, x) ((int16_t) atan2f(y, x)) +# define vector2d_acos(v) ((int16_t) acosf(v)) +#elif defined (_VECTOR2D_USE_UINT32_) # define coordinate uint32_t +# define mod_coordinate coordinate # define vector2d_pow(v, p) ((uint32_t) powf(v, p)) # define vector2d_atan2(y, x) ((uint32_t) atan2f(y, x)) # define vector2d_acos(v) ((uint32_t) acosf(v)) -#elif defined (_VECTOR2D_USE_INT64_) +#elif defined (_VECTOR2D_USE_INT32_) +# define coordinate int32_t +# define mod_coordinate coordinate +# define vector2d_pow(v, p) ((int32_t) powf(v, p)) +# define vector2d_atan2(y, x) ((int32_t) atan2f(y, x)) +# define vector2d_acos(v) ((int32_t) acosf(v)) +#elif defined (_VECTOR2D_USE_UINT64_) # define coordinate uint64_t -# define vector2d_pow(v, p) ((uint64_t) powf(v, p)) +# define mod_coordinate coordinate +# define vector2d_pow(v, p) ((uint64_t) powl(v, p)) # define vector2d_atan2(y, x) ((uint64_t) atan2l(y, x)) # define vector2d_acos(v) ((uint64_t) acosl(v)) +#elif defined (_VECTOR2D_USE_INT64_) +# define coordinate int64_t +# define mod_coordinate coordinate +# define vector2d_pow(v, p) ((int64_t) powl(v, p)) +# define vector2d_atan2(y, x) ((int64_t) atan2l(y, x)) +# define vector2d_acos(v) ((int64_t) acosl(v)) #elif defined (_VECTOR2D_USE_DOUBLE_) # define coordinate double -# define vector2d_pow(v, p) ((double) powf(v, p)) +# define mod_coordinate int64_t +# define vector2d_pow(v, p) ((double) powl(v, p)) # define vector2d_atan2(y, x) ((double) atan2l(y, x)) # define vector2d_acos(v) ((double) acosl(v)) #else # define coordinate float +# define mod_coordinate int32_t # define vector2d_pow(v, p) ((float) powf(v, p)) # define vector2d_atan2(y, x) ((float) atan2f(y, x)) # define vector2d_acos(v) ((float) acosf(v)) diff --git a/arithmos-core/src/include/vectorspaces/vector2d/vector2d.h b/arithmos-core/src/include/vectorspaces/vector2d/vector2d.h index 3cae935..53ca01a 100644 --- a/arithmos-core/src/include/vectorspaces/vector2d/vector2d.h +++ b/arithmos-core/src/include/vectorspaces/vector2d/vector2d.h @@ -2,7 +2,7 @@ #define _vector2d_H_ #include -#include +#include #ifdef __cplusplus extern "C" { @@ -37,6 +37,10 @@ extern coordinate vector2d_length(vector2d); extern coordinate vector2d_polar(vector2d); +extern vector2d* vector2f_scalar_moduluo(vector2d*, coordinate); + +extern coordinate vector2d_distance(vector2d, vector2d); + extern int vector2d_is_dependent(vector2d, vector2d); #ifdef __cplusplus diff --git a/arithmos-core/src/libvector2d/vector2d_add.c b/arithmos-core/src/libvector2d/vector2d_add.c index e7a2fbc..80a9dd7 100644 --- a/arithmos-core/src/libvector2d/vector2d_add.c +++ b/arithmos-core/src/libvector2d/vector2d_add.c @@ -1,4 +1,4 @@ -#include +#include vector2d vector2d_add(vector2d vec0, vector2d vec1) { vector2d summation = { diff --git a/arithmos-core/src/libvector2d/vector2d_angle.c b/arithmos-core/src/libvector2d/vector2d_angle.c index 51b2a8a..ab559f2 100644 --- a/arithmos-core/src/libvector2d/vector2d_angle.c +++ b/arithmos-core/src/libvector2d/vector2d_angle.c @@ -1,4 +1,4 @@ -#include +#include coordinate vector2d_angle(vector2d vec0, vector2d vec1) { // 1) find the dot product diff --git a/arithmos-core/src/libvector2d/vector2d_distance.c b/arithmos-core/src/libvector2d/vector2d_distance.c new file mode 100644 index 0000000..3114bd4 --- /dev/null +++ b/arithmos-core/src/libvector2d/vector2d_distance.c @@ -0,0 +1,5 @@ +#include + +coordinate vector2d_distance(vector2d vec0, vector2d vec1) { + return vector2d_length(vector2d_subtract(vec0, vec1)); +} \ No newline at end of file diff --git a/arithmos-core/src/libvector2d/vector2d_dot_product.c b/arithmos-core/src/libvector2d/vector2d_dot_product.c index b88a846..fc458fa 100644 --- a/arithmos-core/src/libvector2d/vector2d_dot_product.c +++ b/arithmos-core/src/libvector2d/vector2d_dot_product.c @@ -1,4 +1,4 @@ -#include +#include coordinate vector2d_dot_product(vector2d vec0, vector2d vec1) { return vec0.x * vec1.x + vec0.y * vec1.y; diff --git a/arithmos-core/src/libvector2d/vector2d_is_dependent.c b/arithmos-core/src/libvector2d/vector2d_is_dependent.c index 4380b61..4141353 100644 --- a/arithmos-core/src/libvector2d/vector2d_is_dependent.c +++ b/arithmos-core/src/libvector2d/vector2d_is_dependent.c @@ -1,4 +1,4 @@ -#include +#include int vector2d_is_dependent(vector2d vec0, vector2d vec1) { return 0; diff --git a/arithmos-core/src/libvector2d/vector2d_length.c b/arithmos-core/src/libvector2d/vector2d_length.c index ba70e82..cb001ac 100644 --- a/arithmos-core/src/libvector2d/vector2d_length.c +++ b/arithmos-core/src/libvector2d/vector2d_length.c @@ -1,4 +1,4 @@ -#include +#include coordinate vector2d_length(vector2d vec) { return vector2d_sqrt(vector2d_pow(vec.x, 2) + vector2d_pow(vec.y, 2)); diff --git a/arithmos-core/src/libvector2d/vector2d_lerp.c b/arithmos-core/src/libvector2d/vector2d_lerp.c index 62d6f26..d237c1f 100644 --- a/arithmos-core/src/libvector2d/vector2d_lerp.c +++ b/arithmos-core/src/libvector2d/vector2d_lerp.c @@ -1,4 +1,4 @@ -#include +#include vector2d vector2d_lerp(vector2d vec0, vector2d vec1, coordinate scale) { // 1) find the absolute x_distance and y_distance diff --git a/arithmos-core/src/libvector2d/vector2d_normalize.c b/arithmos-core/src/libvector2d/vector2d_normalize.c index a5aa15d..9e271cb 100644 --- a/arithmos-core/src/libvector2d/vector2d_normalize.c +++ b/arithmos-core/src/libvector2d/vector2d_normalize.c @@ -1,4 +1,4 @@ -#include +#include vector2d* vector2d_normalize(vector2d* vec) { coordinate length = { diff --git a/arithmos-core/src/libvector2d/vector2d_polar.c b/arithmos-core/src/libvector2d/vector2d_polar.c index 913f1b3..6c45a00 100644 --- a/arithmos-core/src/libvector2d/vector2d_polar.c +++ b/arithmos-core/src/libvector2d/vector2d_polar.c @@ -1,4 +1,4 @@ -#include +#include coordinate vector2d_polar(vector2d vec) { return vector2d_atan2(vec.y, vec.x); diff --git a/arithmos-core/src/libvector2d/vector2d_scalar_add.c b/arithmos-core/src/libvector2d/vector2d_scalar_add.c index c557de9..440c6f8 100644 --- a/arithmos-core/src/libvector2d/vector2d_scalar_add.c +++ b/arithmos-core/src/libvector2d/vector2d_scalar_add.c @@ -1,4 +1,4 @@ -#include +#include vector2d* vector2d_scalar_add(vector2d* vec, coordinate scalar) { vec->x += scalar; diff --git a/arithmos-core/src/libvector2d/vector2d_scalar_divide.c b/arithmos-core/src/libvector2d/vector2d_scalar_divide.c index e85c850..0536821 100644 --- a/arithmos-core/src/libvector2d/vector2d_scalar_divide.c +++ b/arithmos-core/src/libvector2d/vector2d_scalar_divide.c @@ -1,4 +1,4 @@ -#include +#include vector2d* vector2d_scalar_divide(vector2d* vec, coordinate scalar) { vec->x /= scalar; diff --git a/arithmos-core/src/libvector2d/vector2d_scalar_moduluo.c b/arithmos-core/src/libvector2d/vector2d_scalar_moduluo.c index 35edeae..6ddb53b 100644 --- a/arithmos-core/src/libvector2d/vector2d_scalar_moduluo.c +++ b/arithmos-core/src/libvector2d/vector2d_scalar_moduluo.c @@ -1,5 +1,7 @@ -#include +#include vector2d* vector2f_scalar_moduluo(vector2d* vec, coordinate scalar) { - return 0; + vec->x = ((mod_coordinate) vec->x) % ((mod_coordinate) scalar); + vec->y = ((mod_coordinate) vec->y) % ((mod_coordinate) scalar); + return vec; } \ No newline at end of file diff --git a/arithmos-core/src/libvector2d/vector2d_scalar_multiply.c b/arithmos-core/src/libvector2d/vector2d_scalar_multiply.c index 5cf3b20..561bba8 100644 --- a/arithmos-core/src/libvector2d/vector2d_scalar_multiply.c +++ b/arithmos-core/src/libvector2d/vector2d_scalar_multiply.c @@ -1,4 +1,4 @@ -#include +#include vector2d* vector2d_scalar_multiply(vector2d* vec, coordinate scalar) { vec->x *= scalar; diff --git a/arithmos-core/src/libvector2d/vector2d_scalar_subtract.c b/arithmos-core/src/libvector2d/vector2d_scalar_subtract.c index e6f4d2c..a9c5be6 100644 --- a/arithmos-core/src/libvector2d/vector2d_scalar_subtract.c +++ b/arithmos-core/src/libvector2d/vector2d_scalar_subtract.c @@ -1,4 +1,4 @@ -#include +#include vector2d* vector2d_scalar_subtract(vector2d* vec, coordinate scalar) { vec->x -= scalar; diff --git a/arithmos-core/src/libvector2d/vector2d_subtract.c b/arithmos-core/src/libvector2d/vector2d_subtract.c index 73e797e..809c699 100644 --- a/arithmos-core/src/libvector2d/vector2d_subtract.c +++ b/arithmos-core/src/libvector2d/vector2d_subtract.c @@ -1,4 +1,4 @@ -#include +#include vector2d vector2d_subtract(vector2d vec0, vector2d vec1) { vector2d subtraction = { From ed1cb5d94836e3c3dc01dd59a133b5c0062399c6 Mon Sep 17 00:00:00 2001 From: pavl_g Date: Mon, 15 May 2023 15:38:15 +0300 Subject: [PATCH 04/17] libvector2d: more utility functions and docs --- arithmos-core/CMakeLists.txt | 10 +- .../src/include/vectorspaces/coordinate.h | 4 +- .../include/vectorspaces/vector2d/vector2d.h | 207 ++++++++++++++++-- arithmos-core/src/libvector2d/vector2d_add.c | 3 +- .../src/libvector2d/vector2d_are_dependent.c | 6 + .../src/libvector2d/vector2d_are_parallel.c | 5 + .../libvector2d/vector2d_are_perpendicular.c | 5 + .../src/libvector2d/vector2d_divide.c | 8 + .../src/libvector2d/vector2d_extrapolate.c | 8 + ...vector2d_lerp.c => vector2d_interpolate.c} | 7 +- .../src/libvector2d/vector2d_is_dependent.c | 5 - .../src/libvector2d/vector2d_normalize.c | 7 +- .../src/libvector2d/vector2d_product.c | 8 + .../src/libvector2d/vector2d_scalar_add.c | 6 +- .../src/libvector2d/vector2d_scalar_divide.c | 6 +- .../src/libvector2d/vector2d_scalar_moduluo.c | 6 +- .../libvector2d/vector2d_scalar_multiply.c | 6 +- .../libvector2d/vector2d_scalar_subtract.c | 6 +- .../src/libvector2d/vector2d_subtract.c | 3 +- 19 files changed, 263 insertions(+), 53 deletions(-) create mode 100644 arithmos-core/src/libvector2d/vector2d_are_dependent.c create mode 100644 arithmos-core/src/libvector2d/vector2d_are_parallel.c create mode 100644 arithmos-core/src/libvector2d/vector2d_are_perpendicular.c create mode 100644 arithmos-core/src/libvector2d/vector2d_divide.c create mode 100644 arithmos-core/src/libvector2d/vector2d_extrapolate.c rename arithmos-core/src/libvector2d/{vector2d_lerp.c => vector2d_interpolate.c} (76%) delete mode 100644 arithmos-core/src/libvector2d/vector2d_is_dependent.c create mode 100644 arithmos-core/src/libvector2d/vector2d_product.c diff --git a/arithmos-core/CMakeLists.txt b/arithmos-core/CMakeLists.txt index 2779e0d..2dfdd06 100644 --- a/arithmos-core/CMakeLists.txt +++ b/arithmos-core/CMakeLists.txt @@ -17,17 +17,21 @@ set(toolchain_headers "${TOOLCHAIN_HOME}/toolchain/include/") set(libvector2d "${CMAKE_CURRENT_SOURCE_DIR}/src/libvector2d/vector2d_add.c" "${CMAKE_CURRENT_SOURCE_DIR}/src/libvector2d/vector2d_angle.c" "${CMAKE_CURRENT_SOURCE_DIR}/src/libvector2d/vector2d_dot_product.c" + "${CMAKE_CURRENT_SOURCE_DIR}/src/libvector2d/vector2d_product.c" + "${CMAKE_CURRENT_SOURCE_DIR}/src/libvector2d/vector2d_subtract.c" "${CMAKE_CURRENT_SOURCE_DIR}/src/libvector2d/vector2d_distance.c" "${CMAKE_CURRENT_SOURCE_DIR}/src/libvector2d/vector2d_length.c" - "${CMAKE_CURRENT_SOURCE_DIR}/src/libvector2d/vector2d_lerp.c" + "${CMAKE_CURRENT_SOURCE_DIR}/src/libvector2d/vector2d_interpolate.c" + "${CMAKE_CURRENT_SOURCE_DIR}/src/libvector2d/vector2d_extrapolate.c" + "${CMAKE_CURRENT_SOURCE_DIR}/src/libvector2d/vector2d_are_parallel.c" + "${CMAKE_CURRENT_SOURCE_DIR}/src/libvector2d/vector2d_are_perpendicular.c" "${CMAKE_CURRENT_SOURCE_DIR}/src/libvector2d/vector2d_normalize.c" "${CMAKE_CURRENT_SOURCE_DIR}/src/libvector2d/vector2d_polar.c" "${CMAKE_CURRENT_SOURCE_DIR}/src/libvector2d/vector2d_scalar_add.c" "${CMAKE_CURRENT_SOURCE_DIR}/src/libvector2d/vector2d_scalar_divide.c" "${CMAKE_CURRENT_SOURCE_DIR}/src/libvector2d/vector2d_scalar_multiply.c" "${CMAKE_CURRENT_SOURCE_DIR}/src/libvector2d/vector2d_scalar_subtract.c" - "${CMAKE_CURRENT_SOURCE_DIR}/src/libvector2d/vector2d_scalar_moduluo.c" - "${CMAKE_CURRENT_SOURCE_DIR}/src/libvector2d/vector2d_subtract.c") + "${CMAKE_CURRENT_SOURCE_DIR}/src/libvector2d/vector2d_scalar_moduluo.c") set(headers "${toolchain_headers}" "${CMAKE_CURRENT_SOURCE_DIR}/src/include/") diff --git a/arithmos-core/src/include/vectorspaces/coordinate.h b/arithmos-core/src/include/vectorspaces/coordinate.h index 7370e08..55213c1 100644 --- a/arithmos-core/src/include/vectorspaces/coordinate.h +++ b/arithmos-core/src/include/vectorspaces/coordinate.h @@ -1,5 +1,5 @@ -#ifndef _vector2d_H_ -# error "Use vector2d instead of this!" +#if !(defined _vector2d_H_ || defined _vector3d_H_) +# error "Use vector2d or vector3d instead of this!" #endif #ifndef _COORDINATE_H_ diff --git a/arithmos-core/src/include/vectorspaces/vector2d/vector2d.h b/arithmos-core/src/include/vectorspaces/vector2d/vector2d.h index 53ca01a..cb48785 100644 --- a/arithmos-core/src/include/vectorspaces/vector2d/vector2d.h +++ b/arithmos-core/src/include/vectorspaces/vector2d/vector2d.h @@ -1,3 +1,9 @@ +/** + * @brief The R(2) vectorspace to represent 2-dimensional vectors providing a + * powerful utility to operate on them. + * @author pavl_g. + * @copyright arithmos-native. + */ #ifndef _vector2d_H_ #define _vector2d_H_ @@ -8,40 +14,211 @@ extern "C" { #endif +/** + * @brief Represents a 2-dimensional (aka. R(2) space) vector point + * with a x-component and a y-component. + */ typedef struct { + /** + * @brief The x-coordinate (Vx->) component of this vector in the R(2) space. + */ coordinate x; + + /** + * @brief The y-coordinate (Vy->) component of this vector in the R(2) space. + */ coordinate y; } vector2d; -extern vector2d* vector2d_scalar_add(vector2d*, coordinate); - -extern vector2d* vector2d_scalar_subtract(vector2d*, coordinate); - -extern vector2d* vector2d_scalar_multiply(vector2d*, coordinate); - -extern vector2d* vector2d_scalar_divide(vector2d*, coordinate); - -extern vector2d* vector2d_normalize(vector2d*); - +/** + * @brief Adds a scalar value to the vector components and returns a new vector. + * + * @param vector2d the initial vector in R(2) space. + * @param coordinate the value to add to that vector. + * @return a new vector2d with x and y components. + */ +extern vector2d vector2d_scalar_add(vector2d, coordinate); + +/** + * @brief Subtracts a scalar value from the vector components and returns a new vector. + * + * @param vector2d the initial vector in R(2) space. + * @param coordinate the value to subtract from that vector. + * @return a new vector2d with x and y components. + */ +extern vector2d vector2d_scalar_subtract(vector2d, coordinate); + +/** + * @brief Multiplies a scalar value with the vector components and returns a new vector. + * + * @param vector2d the initial vector in R(2) space. + * @param coordinate the value to multiply to that vector. + * @return a new vector2d with x and y components. + */ +extern vector2d vector2d_scalar_multiply(vector2d, coordinate); + +/** + * @brief Divides a scalar value by the vector components and returns a new vector. + * + * @param vector2d the initial vector in R(2) space. + * @param coordinate the value to divide by that vector. + * @return a new vector2d with x and y components. + */ +extern vector2d vector2d_scalar_divide(vector2d, coordinate); + +/** + * @brief Finds the uint vector of a vector in R(2) space which represents the direction of that vector. + * + * @param vector2d the original vector in R(2) space. + * @return a new vector2d representing the uint vector of the input vector. + */ +extern vector2d vector2d_normalize(vector2d); + +/** + * @brief Adds two vector2d components together in a R(2) space returning a new vector. + * + * @param vector2d the first vector. + * @param vector2d the second vector. + * @return a new vector2d in the R(2) space. + */ extern vector2d vector2d_add(vector2d, vector2d); +/** + * @brief Divides the first vector by the second vector in a R(2) space returning a new vector. + * + * @param vector2d the first vector. + * @param vector2d the second vector. + * @return a new vector2d in the R(2) space. + */ +extern vector2d vector2d_divide(vector2d, vector2d); + +/** + * @brief Subtracts the second vector components from first vector components in a R(2) space returning a new vector. + * + * @param vector2d the first vector. + * @param vector2d the second vector. + * @return a new vector2d in the R(2) space. + */ extern vector2d vector2d_subtract(vector2d, vector2d); -extern vector2d vector2d_lerp(vector2d, vector2d, coordinate); - +/** + * @brief Interpolates between the first vector components and the second vector components with a scale in a R(2) space. + * + * @param vector2d the first vector. + * @param vector2d the second vector. + * @return a new vector2d in the R(2) space. + */ +extern vector2d vector2d_interpolate(vector2d, vector2d, coordinate); + +/** + * @brief Extrapolates from the first vector components and the second vector components with a scale in a R(2) space. + * + * @param vector2d the first vector. + * @param vector2d the second vector. + * @return a new vector2d in the R(2) space. + */ +extern vector2d vector2d_extrapolate(vector2d, vector2d, coordinate); + +/** + * @brief Performs a matrix multiplication operation on two vectors in the R(2) space. + * + * @param vector2d the first vector. + * @param vector2d the second vector. + * @return a new vector2d in the R(2) space. + */ extern coordinate vector2d_dot_product(vector2d, vector2d); +/** + * @brief Performs a scalar multiplication operation on the first vector components using the + * second vector components in a R(2) vector-space returning a new vector. + * + * @param vector2d the first vector. + * @param vector2d the second vector. + * @return a new vector2d in the R(2) space. + */ +extern vector2d vector2d_product(vector2d, vector2d); + +/** + * @brief Finds the angle between two vectors in the R(2) space by dividing their dot product by the product of their norms. + * @note The angle is in radians by default! + * + * @param vector2d the first vector. + * @param vector2d the second vector. + * @return a new vector2d in the R(2) space. + */ extern coordinate vector2d_angle(vector2d, vector2d); +/** + * @brief Finds the length (aka. norm) of a vector in the R(2) space by using the Pythagorean theorem on its components. + * + * @param vector2d a vector in the R(2) space to find its length. + * @return a scalar value representing the length of this vector in the R(2) space. + */ extern coordinate vector2d_length(vector2d); +/** + * @brief Converts the rectangular coordinate into a polar coordinate by finding + * the inverse of the tangent of Y/X. + * @note The angle is with the postive direction of x-axis and in rads! + * + * @param vector2d a rectangular coordinate vector. + * @return the polar coordinate value in radians. + */ extern coordinate vector2d_polar(vector2d); -extern vector2d* vector2f_scalar_moduluo(vector2d*, coordinate); - +/** + * @brief Applies a moduluo (integer division) on vector components, returing the remainder + * of the integer division in a new vector2d in a R(2) space. + * + * @param vector2d a rectangular coordinate vector. + * @return the polar coordinate value in radians. + */ +extern vector2d vector2f_scalar_moduluo(vector2d, coordinate); + +/** + * @brief Finds the metric distance between two vectors in a R(2) space by calculating the + * norm of the their subtraction. + * + * @param vector2d the first vector. + * @param vector2d the second vector. + * @return the metric distance between the specified vectors. + */ extern coordinate vector2d_distance(vector2d, vector2d); -extern int vector2d_is_dependent(vector2d, vector2d); +/** + * @brief Tests whether two vectors are dependent in a R(2) vector-space. + * @note Two vectors are said to be dependent if they are multiplies of one another, + * such that, the [u = cv], where u and v are vectors and c is a scalar value not equal to zero. + * @note Linear dependent vectors are coincident vectors in a R(2) space. + * + * @param vector2d the first vector. + * @param vector2d the second vector. + * @return (1) for true if the two vectors are dependent or (0) for false otherwise. + */ +extern uint8_t vector2d_is_dependent(vector2d, vector2d); + +/** + * @brief Tests whether two vectors are perpendicular in a R(2) vector-space. + * @note Two vectors are said to be perpendicular if and only if their dot-product is zero + * because, cos(90) is zero, so u.v = |u|.|v|.cos(90) = 0. + * + * @param vector2d the first vector. + * @param vector2d the second vector. + * @return (1) for true if the two vectors are perpendicular or (0) for false otherwise. + */ +extern uint8_t vector2d_are_perpendicular(vector2d, vector2d); + +/** + * @brief Tests whether two vectors are parallel in a R(2) vector-space. + * @note Two vectors are said to be parallel if and only if their dot-product + * is equal to the product of their norms (lengths); + * because, cos(0) is 1, so u.v = |u|.|v|.cos(0) = |u|.|v|. + * + * @param vector2d the first vector. + * @param vector2d the second vector. + * @return (1) for true if the two vectors are parallel or (0) for false otherwise. + */ +extern uint8_t vector2d_are_parallel(vector2d, vector2d); #ifdef __cplusplus } diff --git a/arithmos-core/src/libvector2d/vector2d_add.c b/arithmos-core/src/libvector2d/vector2d_add.c index 80a9dd7..ef7b5ac 100644 --- a/arithmos-core/src/libvector2d/vector2d_add.c +++ b/arithmos-core/src/libvector2d/vector2d_add.c @@ -1,9 +1,8 @@ #include vector2d vector2d_add(vector2d vec0, vector2d vec1) { - vector2d summation = { + return (vector2d) { vec0.x + vec1.x, vec0.y + vec1.y }; - return summation; } \ No newline at end of file diff --git a/arithmos-core/src/libvector2d/vector2d_are_dependent.c b/arithmos-core/src/libvector2d/vector2d_are_dependent.c new file mode 100644 index 0000000..2ee3a1b --- /dev/null +++ b/arithmos-core/src/libvector2d/vector2d_are_dependent.c @@ -0,0 +1,6 @@ +#include + +uint8_t vector2d_are_dependent(vector2d vec0, vector2d vec1) { + vector2d constant = vector2d_divide(vec0, vec1); + return constant.x == constant.y != 0; +} \ No newline at end of file diff --git a/arithmos-core/src/libvector2d/vector2d_are_parallel.c b/arithmos-core/src/libvector2d/vector2d_are_parallel.c new file mode 100644 index 0000000..90ff1fb --- /dev/null +++ b/arithmos-core/src/libvector2d/vector2d_are_parallel.c @@ -0,0 +1,5 @@ +#include + +uint8_t vector2d_are_parallel(vector2d vec0, vector2d vec1) { + return vector2d_dot_product(vec0, vec1) == (vector2d_length(vec0) * vector2d_length(vec1)); +} \ No newline at end of file diff --git a/arithmos-core/src/libvector2d/vector2d_are_perpendicular.c b/arithmos-core/src/libvector2d/vector2d_are_perpendicular.c new file mode 100644 index 0000000..bea369a --- /dev/null +++ b/arithmos-core/src/libvector2d/vector2d_are_perpendicular.c @@ -0,0 +1,5 @@ +#include + +uint8_t vector2d_are_perpendicular(vector2d vec0, vector2d vec1) { + return vector2d_dot_product(vec0, vec1) == 0; +} \ No newline at end of file diff --git a/arithmos-core/src/libvector2d/vector2d_divide.c b/arithmos-core/src/libvector2d/vector2d_divide.c new file mode 100644 index 0000000..bc018a4 --- /dev/null +++ b/arithmos-core/src/libvector2d/vector2d_divide.c @@ -0,0 +1,8 @@ +#include + +vector2d vector2d_divide(vector2d vec0, vector2d vec1) { + return (vector2d) { + vec0.x / vec1.x, + vec0.y / vec1.y + }; +} \ No newline at end of file diff --git a/arithmos-core/src/libvector2d/vector2d_extrapolate.c b/arithmos-core/src/libvector2d/vector2d_extrapolate.c new file mode 100644 index 0000000..dbbb3fd --- /dev/null +++ b/arithmos-core/src/libvector2d/vector2d_extrapolate.c @@ -0,0 +1,8 @@ +#include + +vector2d vector2d_extrapolate(vector2d vec0, vector2d vec1, coordinate scale) { + return (vector2d) { + ((vec0.x + vec1.x) * scale) + vec0.x, + ((vec0.y + vec1.y) * scale) + vec0.y + }; +} \ No newline at end of file diff --git a/arithmos-core/src/libvector2d/vector2d_lerp.c b/arithmos-core/src/libvector2d/vector2d_interpolate.c similarity index 76% rename from arithmos-core/src/libvector2d/vector2d_lerp.c rename to arithmos-core/src/libvector2d/vector2d_interpolate.c index d237c1f..80b081f 100644 --- a/arithmos-core/src/libvector2d/vector2d_lerp.c +++ b/arithmos-core/src/libvector2d/vector2d_interpolate.c @@ -1,13 +1,12 @@ #include -vector2d vector2d_lerp(vector2d vec0, vector2d vec1, coordinate scale) { +vector2d vector2d_interpolate(vector2d vec0, vector2d vec1, coordinate scale) { // 1) find the absolute x_distance and y_distance coordinate x_distance = vector2d_abs(vec0.x - vec1.x); coordinate y_distance = vector2d_abs(vec0.y - vec1.y); // 2) interpolate between components with a scale starting from the first vector - vector2d lerp = { + return (vector2d) { ((x_distance) * scale) + vec0.x, ((y_distance) * scale) + vec0.y - }; - return lerp; + };; } \ No newline at end of file diff --git a/arithmos-core/src/libvector2d/vector2d_is_dependent.c b/arithmos-core/src/libvector2d/vector2d_is_dependent.c deleted file mode 100644 index 4141353..0000000 --- a/arithmos-core/src/libvector2d/vector2d_is_dependent.c +++ /dev/null @@ -1,5 +0,0 @@ -#include - -int vector2d_is_dependent(vector2d vec0, vector2d vec1) { - return 0; -} \ No newline at end of file diff --git a/arithmos-core/src/libvector2d/vector2d_normalize.c b/arithmos-core/src/libvector2d/vector2d_normalize.c index 9e271cb..64fd931 100644 --- a/arithmos-core/src/libvector2d/vector2d_normalize.c +++ b/arithmos-core/src/libvector2d/vector2d_normalize.c @@ -1,8 +1,5 @@ #include -vector2d* vector2d_normalize(vector2d* vec) { - coordinate length = { - vector2d_length(*vec) - }; - return vector2d_scalar_divide(vec, length); +vector2d vector2d_normalize(vector2d vec) { + return vector2d_scalar_divide(vec, vector2d_length(vec)); } \ No newline at end of file diff --git a/arithmos-core/src/libvector2d/vector2d_product.c b/arithmos-core/src/libvector2d/vector2d_product.c new file mode 100644 index 0000000..36c633d --- /dev/null +++ b/arithmos-core/src/libvector2d/vector2d_product.c @@ -0,0 +1,8 @@ +#include + +vector2d vector2d_product(vector2d vec0, vector2d vec1) { + return (vector2d) { + vec0.x * vec1.x, + vec0.y * vec1.y + }; +} \ No newline at end of file diff --git a/arithmos-core/src/libvector2d/vector2d_scalar_add.c b/arithmos-core/src/libvector2d/vector2d_scalar_add.c index 440c6f8..aa06a1e 100644 --- a/arithmos-core/src/libvector2d/vector2d_scalar_add.c +++ b/arithmos-core/src/libvector2d/vector2d_scalar_add.c @@ -1,7 +1,7 @@ #include -vector2d* vector2d_scalar_add(vector2d* vec, coordinate scalar) { - vec->x += scalar; - vec->y += scalar; +vector2d vector2d_scalar_add(vector2d vec, coordinate scalar) { + vec.x += scalar; + vec.y += scalar; return vec; } \ No newline at end of file diff --git a/arithmos-core/src/libvector2d/vector2d_scalar_divide.c b/arithmos-core/src/libvector2d/vector2d_scalar_divide.c index 0536821..cdcb504 100644 --- a/arithmos-core/src/libvector2d/vector2d_scalar_divide.c +++ b/arithmos-core/src/libvector2d/vector2d_scalar_divide.c @@ -1,7 +1,7 @@ #include -vector2d* vector2d_scalar_divide(vector2d* vec, coordinate scalar) { - vec->x /= scalar; - vec->y /= scalar; +vector2d vector2d_scalar_divide(vector2d vec, coordinate scalar) { + vec.x /= scalar; + vec.y /= scalar; return vec; } \ No newline at end of file diff --git a/arithmos-core/src/libvector2d/vector2d_scalar_moduluo.c b/arithmos-core/src/libvector2d/vector2d_scalar_moduluo.c index 6ddb53b..04ee9a5 100644 --- a/arithmos-core/src/libvector2d/vector2d_scalar_moduluo.c +++ b/arithmos-core/src/libvector2d/vector2d_scalar_moduluo.c @@ -1,7 +1,7 @@ #include -vector2d* vector2f_scalar_moduluo(vector2d* vec, coordinate scalar) { - vec->x = ((mod_coordinate) vec->x) % ((mod_coordinate) scalar); - vec->y = ((mod_coordinate) vec->y) % ((mod_coordinate) scalar); +vector2d vector2f_scalar_moduluo(vector2d vec, coordinate scalar) { + vec.x = ((mod_coordinate) vec.x) % ((mod_coordinate) scalar); + vec.y = ((mod_coordinate) vec.y) % ((mod_coordinate) scalar); return vec; } \ No newline at end of file diff --git a/arithmos-core/src/libvector2d/vector2d_scalar_multiply.c b/arithmos-core/src/libvector2d/vector2d_scalar_multiply.c index 561bba8..7e8ea92 100644 --- a/arithmos-core/src/libvector2d/vector2d_scalar_multiply.c +++ b/arithmos-core/src/libvector2d/vector2d_scalar_multiply.c @@ -1,7 +1,7 @@ #include -vector2d* vector2d_scalar_multiply(vector2d* vec, coordinate scalar) { - vec->x *= scalar; - vec->y *= scalar; +vector2d vector2d_scalar_multiply(vector2d vec, coordinate scalar) { + vec.x *= scalar; + vec.y *= scalar; return vec; } \ No newline at end of file diff --git a/arithmos-core/src/libvector2d/vector2d_scalar_subtract.c b/arithmos-core/src/libvector2d/vector2d_scalar_subtract.c index a9c5be6..1889426 100644 --- a/arithmos-core/src/libvector2d/vector2d_scalar_subtract.c +++ b/arithmos-core/src/libvector2d/vector2d_scalar_subtract.c @@ -1,7 +1,7 @@ #include -vector2d* vector2d_scalar_subtract(vector2d* vec, coordinate scalar) { - vec->x -= scalar; - vec->y -= scalar; +vector2d vector2d_scalar_subtract(vector2d vec, coordinate scalar) { + vec.x -= scalar; + vec.y -= scalar; return vec; } \ No newline at end of file diff --git a/arithmos-core/src/libvector2d/vector2d_subtract.c b/arithmos-core/src/libvector2d/vector2d_subtract.c index 809c699..220b0e0 100644 --- a/arithmos-core/src/libvector2d/vector2d_subtract.c +++ b/arithmos-core/src/libvector2d/vector2d_subtract.c @@ -1,9 +1,8 @@ #include vector2d vector2d_subtract(vector2d vec0, vector2d vec1) { - vector2d subtraction = { + return (vector2d) { vec0.x - vec1.x, vec0.y - vec1.y }; - return subtraction; } \ No newline at end of file From 65b9e7d33e3e1a5c324535645bf55b84e4add1e0 Mon Sep 17 00:00:00 2001 From: pavl_g Date: Mon, 15 May 2023 15:42:16 +0300 Subject: [PATCH 05/17] cmake: separate target for libvector2d --- arithmos-core/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arithmos-core/CMakeLists.txt b/arithmos-core/CMakeLists.txt index 2dfdd06..2204d7f 100644 --- a/arithmos-core/CMakeLists.txt +++ b/arithmos-core/CMakeLists.txt @@ -8,7 +8,7 @@ message(STATUS "Toolchain: ${TOOLCHAIN_HOME}") message(STATUS "Target Hardware: ${TARGET}") # Cmake variables -set(library "arithmos") +set(library "vector2d") set(CMAKE_C_COMPILER "${TOOLCHAIN_HOME}/bin/avr-gcc") set(CMAKE_CXX_COMPILER "${TOOLCHAIN_HOME}/bin/avr-g++") set(COMPILER_OPTIONS "-mmcu=${TARGET} -O3") From 81eb3b00a96c90b6236e8a45e2f6e7c8afc9fafd Mon Sep 17 00:00:00 2001 From: pavl_g Date: Tue, 16 May 2023 10:17:32 +0300 Subject: [PATCH 06/17] arithmos-core: deferred cmake abstraction to cmake-variables --- arithmos-core/CMakeLists.txt | 91 +++++++++++++++++++++--------------- 1 file changed, 54 insertions(+), 37 deletions(-) diff --git a/arithmos-core/CMakeLists.txt b/arithmos-core/CMakeLists.txt index 2204d7f..87d6444 100644 --- a/arithmos-core/CMakeLists.txt +++ b/arithmos-core/CMakeLists.txt @@ -4,47 +4,64 @@ cmake_minimum_required(VERSION 3.18.1) project(arithmos VERSION 1.0) message(STATUS "Project: arithmos") -message(STATUS "Toolchain: ${TOOLCHAIN_HOME}") -message(STATUS "Target Hardware: ${TARGET}") +message(STATUS "C compiler: ${C_COMPILER}") +message(STATUS "CXX compiler: ${CXX_COMPILER}") +message(STATUS "Toolchain headers: ${TOOLCHAIN_HEADERS}") +message(STATUS "Compiler Options: ${COMPILER_OPTIONS}") +message(STATUS "Build command: ${BUILD_COMMAND}") # Cmake variables -set(library "vector2d") -set(CMAKE_C_COMPILER "${TOOLCHAIN_HOME}/bin/avr-gcc") -set(CMAKE_CXX_COMPILER "${TOOLCHAIN_HOME}/bin/avr-g++") -set(COMPILER_OPTIONS "-mmcu=${TARGET} -O3") - -set(toolchain_headers "${TOOLCHAIN_HOME}/toolchain/include/") -set(libvector2d "${CMAKE_CURRENT_SOURCE_DIR}/src/libvector2d/vector2d_add.c" - "${CMAKE_CURRENT_SOURCE_DIR}/src/libvector2d/vector2d_angle.c" - "${CMAKE_CURRENT_SOURCE_DIR}/src/libvector2d/vector2d_dot_product.c" - "${CMAKE_CURRENT_SOURCE_DIR}/src/libvector2d/vector2d_product.c" - "${CMAKE_CURRENT_SOURCE_DIR}/src/libvector2d/vector2d_subtract.c" - "${CMAKE_CURRENT_SOURCE_DIR}/src/libvector2d/vector2d_distance.c" - "${CMAKE_CURRENT_SOURCE_DIR}/src/libvector2d/vector2d_length.c" - "${CMAKE_CURRENT_SOURCE_DIR}/src/libvector2d/vector2d_interpolate.c" - "${CMAKE_CURRENT_SOURCE_DIR}/src/libvector2d/vector2d_extrapolate.c" - "${CMAKE_CURRENT_SOURCE_DIR}/src/libvector2d/vector2d_are_parallel.c" - "${CMAKE_CURRENT_SOURCE_DIR}/src/libvector2d/vector2d_are_perpendicular.c" - "${CMAKE_CURRENT_SOURCE_DIR}/src/libvector2d/vector2d_normalize.c" - "${CMAKE_CURRENT_SOURCE_DIR}/src/libvector2d/vector2d_polar.c" - "${CMAKE_CURRENT_SOURCE_DIR}/src/libvector2d/vector2d_scalar_add.c" - "${CMAKE_CURRENT_SOURCE_DIR}/src/libvector2d/vector2d_scalar_divide.c" - "${CMAKE_CURRENT_SOURCE_DIR}/src/libvector2d/vector2d_scalar_multiply.c" - "${CMAKE_CURRENT_SOURCE_DIR}/src/libvector2d/vector2d_scalar_subtract.c" - "${CMAKE_CURRENT_SOURCE_DIR}/src/libvector2d/vector2d_scalar_moduluo.c") - -set(headers "${toolchain_headers}" +set(CMAKE_C_COMPILER "${C_COMPILER}") +set(CMAKE_CXX_COMPILER "${CXX_COMPILER}") +set(COMPILER_OPTIONS "${COMPILER_OPTIONS}") + +set(headers "${TOOLCHAIN_HEADERS}" "${CMAKE_CURRENT_SOURCE_DIR}/src/include/") -set(sources ${libvector2d}) -# add a library target -add_library(${library} STATIC ${sources}) +########################### libvector2d START ########################### +function(build_vector2d) + set(vector2d "vector2d") + set(libvector2d "${CMAKE_CURRENT_SOURCE_DIR}/src/libvector2d/vector2d_add.c" + "${CMAKE_CURRENT_SOURCE_DIR}/src/libvector2d/vector2d_angle.c" + "${CMAKE_CURRENT_SOURCE_DIR}/src/libvector2d/vector2d_dot_product.c" + "${CMAKE_CURRENT_SOURCE_DIR}/src/libvector2d/vector2d_product.c" + "${CMAKE_CURRENT_SOURCE_DIR}/src/libvector2d/vector2d_subtract.c" + "${CMAKE_CURRENT_SOURCE_DIR}/src/libvector2d/vector2d_distance.c" + "${CMAKE_CURRENT_SOURCE_DIR}/src/libvector2d/vector2d_length.c" + "${CMAKE_CURRENT_SOURCE_DIR}/src/libvector2d/vector2d_interpolate.c" + "${CMAKE_CURRENT_SOURCE_DIR}/src/libvector2d/vector2d_extrapolate.c" + "${CMAKE_CURRENT_SOURCE_DIR}/src/libvector2d/vector2d_are_parallel.c" + "${CMAKE_CURRENT_SOURCE_DIR}/src/libvector2d/vector2d_are_perpendicular.c" + "${CMAKE_CURRENT_SOURCE_DIR}/src/libvector2d/vector2d_normalize.c" + "${CMAKE_CURRENT_SOURCE_DIR}/src/libvector2d/vector2d_polar.c" + "${CMAKE_CURRENT_SOURCE_DIR}/src/libvector2d/vector2d_scalar_add.c" + "${CMAKE_CURRENT_SOURCE_DIR}/src/libvector2d/vector2d_scalar_divide.c" + "${CMAKE_CURRENT_SOURCE_DIR}/src/libvector2d/vector2d_scalar_multiply.c" + "${CMAKE_CURRENT_SOURCE_DIR}/src/libvector2d/vector2d_scalar_subtract.c" + "${CMAKE_CURRENT_SOURCE_DIR}/src/libvector2d/vector2d_scalar_moduluo.c") + + # add a library target + add_library(${vector2d} STATIC ${libvector2d}) + + # set both COMPILE_FLAGS and LINK_FLAGS to the specified binary architecture + set_target_properties(${vector2d} PROPERTIES COMPILE_FLAGS "${COMPILER_OPTIONS}" LINK_FLAGS "${COMPILER_OPTIONS}") + + # include headers for the target + target_include_directories(${vector2d} PUBLIC ${headers}) -# set both COMPILE_FLAGS and LINK_FLAGS to the specified binary architecture -set_target_properties(${library} PROPERTIES COMPILE_FLAGS "${COMPILER_OPTIONS}" LINK_FLAGS "${COMPILER_OPTIONS}") + # Start building the target + target_sources(${vector2d} PUBLIC ${libvector2d}) +endfunction() +########################### libvector2d END ########################### -# include headers for the target -target_include_directories(${library} PUBLIC ${headers}) +function(build_all) + build_vector2d() +endfunction() -# Start building the target -target_sources(${library} PUBLIC ${sources}) +########################### build process START ########################### +if(BUILD_COMMAND STREQUAL "vector2d") + build_vector2d() +else() + build_all() +endif() +########################### build process END ########################### \ No newline at end of file From 28cb9fe36099d1c831853b6df6add8f7f8ba52b5 Mon Sep 17 00:00:00 2001 From: pavl_g Date: Tue, 16 May 2023 10:18:16 +0300 Subject: [PATCH 07/17] arithmos-core/README.md: project layout --- arithmos-core/README.md | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/arithmos-core/README.md b/arithmos-core/README.md index da9f377..866f2c6 100644 --- a/arithmos-core/README.md +++ b/arithmos-core/README.md @@ -1,13 +1,9 @@ -# foobar-core +# arithmos-core -This is your core code module, it's compiled into a static library. +The Core of arithmos-native, this project consists of a couple of sub-projects: -To compile to a target mcu use the following script: -```bash -source "./helper-scripts/abstract/abstract-compile.sh" -source "./helper-scripts/project-impl/variables.sh" - -compile ${TOOLCHAIN_HOME} ${mcu_atmega32A} ${source_dir} -``` - -Edit the variables at `variables.sh` to satisfy your needs, to get more out of this, add your chip compilation script to `compile-all.sh`. \ No newline at end of file +- [x] libvector2d: A vector utility in the R(2) vector-space that provides powerful vector operations out of the box. +- [ ] libvector3d. +- [ ] libmatrix4x4. +- [ ] libgebra. +- [ ] libtrigo. \ No newline at end of file From 636b41d09d8935258fe5f2927e10f235dbd4d7bd Mon Sep 17 00:00:00 2001 From: pavl_g Date: Tue, 16 May 2023 10:19:02 +0300 Subject: [PATCH 08/17] arithmos-examples: added a working example --- arithmos-examples/CMakeLists.txt | 25 +++++++++++-------- arithmos-examples/src/hello_foobar.c | 14 ----------- arithmos-examples/src/hello_vector2d.c | 33 ++++++++++++++++++++++++++ 3 files changed, 48 insertions(+), 24 deletions(-) delete mode 100644 arithmos-examples/src/hello_foobar.c create mode 100644 arithmos-examples/src/hello_vector2d.c diff --git a/arithmos-examples/CMakeLists.txt b/arithmos-examples/CMakeLists.txt index d55784e..e709104 100644 --- a/arithmos-examples/CMakeLists.txt +++ b/arithmos-examples/CMakeLists.txt @@ -5,20 +5,22 @@ project(arithmos-examples VERSION 1.0) # display external options message(STATUS "Project: arithmos-examples") -message(STATUS "Toolchain: ${TOOLCHAIN_HOME}") -message(STATUS "Target Hardware: ${TARGET}") -message(STATUS "Included-library: ${ARITHMOS_LIB}") +message(STATUS "C compiler: ${C_COMPILER}") +message(STATUS "CXX compiler: ${CXX_COMPILER}") +message(STATUS "Toolchain headers: ${TOOLCHAIN_HEADERS}") +message(STATUS "Compiler Options: ${COMPILER_OPTIONS}") +message(STATUS "Included-library: ${STATIC_LIB_SOURCE}") message(STATUS "Runnable-example: ${EXAMPLE}") # Cmake variables set(elf "${EXAMPLE}.elf") -set(CMAKE_C_COMPILER "${TOOLCHAIN_HOME}/bin/avr-gcc") -set(CMAKE_CXX_COMPILER "${TOOLCHAIN_HOME}/bin/avr-g++") -set(COMPILER_OPTIONS "-mmcu=${TARGET}") +set(CMAKE_C_COMPILER "${C_COMPILER}") +set(CMAKE_CXX_COMPILER "${CXX_COMPILER}") +set(COMPILER_OPTIONS "${COMPILER_OPTIONS}") -set(headers "${ARITHMOS_LIB}/src/include") -set(avr_headers "${TOOLCHAIN_HOME}/include") +set(headers "${STATIC_LIB_SOURCE}/src/include") +set(avr_headers "${TOOLCHAIN_HEADERS}") # C sources set(sources "${CMAKE_CURRENT_SOURCE_DIR}/src/${EXAMPLE}") @@ -32,7 +34,10 @@ set_target_properties(${elf} PROPERTIES COMPILE_FLAGS "${COMPILER_OPTIONS}" LINK # include headers for the target target_include_directories(${elf} PUBLIC ${avr_headers} ${headers}) -target_link_libraries(${elf} "${ARITHMOS_LIB}/build/${TARGET}/libarithmos.a") +# add all arithmos libraries here +target_link_libraries(${elf} "${ARITHMOS_LIB}/build/${TARGET}/libvector2d.a") +# target_link_libraries(${elf} "${ARITHMOS_LIB}/build/${TARGET}/libvector3d.a") +# target_link_libraries(${elf} "${ARITHMOS_LIB}/build/${TARGET}/libmatrix4x4.a") # Start building the target -target_sources(${elf} PUBLIC ${sources}) +target_sources(${elf} PUBLIC ${sources}) \ No newline at end of file diff --git a/arithmos-examples/src/hello_foobar.c b/arithmos-examples/src/hello_foobar.c deleted file mode 100644 index c87bb50..0000000 --- a/arithmos-examples/src/hello_foobar.c +++ /dev/null @@ -1,14 +0,0 @@ -/** - * @brief An example showing an example :-). - * @author pavl_g. - * @copyright Unlicensed license. - */ -#include -#include - -int main() { - init_foo(); - do_foo(); - destroy_foo(); - return 0; -} diff --git a/arithmos-examples/src/hello_vector2d.c b/arithmos-examples/src/hello_vector2d.c new file mode 100644 index 0000000..3bbf082 --- /dev/null +++ b/arithmos-examples/src/hello_vector2d.c @@ -0,0 +1,33 @@ +/** + * @brief An example showing an example :-). + * @author pavl_g. + * @copyright Unlicensed license. + */ +#include +#include + +vector2d vec0 = { + 0, + 1, + 2 +}; + +vector2d vec1 = { + 2, + 3, + 4 +}; + +int main() { + printf("Summation = [%d, %d] \n", vector2d_add(vec0, vec1).x, vector2d_add(vec0, vec1).y); + printf("Subtraction = [%d, %d] \n", vector2d_subtract(vec0, vec1).x, vector2d_subtract(vec0, vec1).y); + printf("Product = [%d, %d] \n", vector2d_product(vec0, vec1).x, vector2d_product(vec0, vec1).y); + printf("Division = [%d, %d] \n", vector2d_divide(vec0, vec1).x, vector2d_divide(vec0, vec1).y); + printf("Inner Product = %d \n", vector2d_dot_product(vec0, vec1)); + printf("Inner Angle in radians = %d \n", vector2d_angle(vec0, vec1)); + printf("Are parallel = %d \n", vector2d_are_parallel(vec0, vec1)); + printf("Are perpendicular = %d \n", vector2d_are_perpendicular(vec0, vec1)); + printf("Extrapolate to 1/2 after the last vector = [%d, %d] \n", vector2d_extrapolate(vec0, vec1, 0.5).x, vector2d_extrapolate(vec0, vec1, 0.5).y); + + return 0; +} From b4e64be30bd211e6b99792f91987b709d4d577e9 Mon Sep 17 00:00:00 2001 From: pavl_g Date: Tue, 16 May 2023 10:20:04 +0300 Subject: [PATCH 09/17] helper-scripts: deferred cmake abstraction to cmake-variables --- .../abstract/abstract-compile-examples.sh | 22 +++++++++++-------- helper-scripts/abstract/abstract-compile.sh | 19 +++++++++++----- helper-scripts/abstract/abstract-upload.sh | 4 ++-- .../project-impl/compile-atmega32.sh | 8 ++++++- .../project-impl/compile-atmega328p.sh | 8 ++++++- .../project-impl/compile-examples.sh | 8 ++++++- helper-scripts/project-impl/upload-to-chip.sh | 2 +- helper-scripts/project-impl/variables.sh | 9 ++++++-- 8 files changed, 58 insertions(+), 22 deletions(-) diff --git a/helper-scripts/abstract/abstract-compile-examples.sh b/helper-scripts/abstract/abstract-compile-examples.sh index df7bec6..5f5da52 100644 --- a/helper-scripts/abstract/abstract-compile-examples.sh +++ b/helper-scripts/abstract/abstract-compile-examples.sh @@ -1,18 +1,22 @@ #!/bin/bash function compile() { - local TOOLCHAIN_HOME=${1} - local TARGET=${2} - local source_dir=${3} - local FOOBAR_LIB=${4} - local EXAMPLE=${5} + local C_COMPILER=${1} + local CXX_COMPILER=${2} + local TOOLCHAIN_HEADERS=${3} + local COMPILER_OPTIONS=${4} + local TARGET=${5} + local STATIC_LIB_SOURCE=${6} + local EXAMPLE=${7} + local source_dir=${8} local temp=$(pwd) cd ${source_dir} - - cmake "-DTOOLCHAIN_HOME=${TOOLCHAIN_HOME}" \ - "-DTARGET=${TARGET}" \ - "-DFOO_BAR=${FOOBAR_LIB}" \ + cmake "-DC_COMPILER=${C_COMPILER}" \ + "-DCXX_COMPILER=${CXX_COMPILER}" \ + "-DTOOLCHAIN_HEADERS=${TOOLCHAIN_HEADERS}" \ + "-DCOMPILER_OPTIONS=${COMPILER_OPTIONS}" \ + "-DSTATIC_LIB_SOURCE=${STATIC_LIB_SOURCE}" \ "-DEXAMPLE=${EXAMPLE}" \ -S . -B "./build/${TARGET}" diff --git a/helper-scripts/abstract/abstract-compile.sh b/helper-scripts/abstract/abstract-compile.sh index 2cfcdca..0abef52 100644 --- a/helper-scripts/abstract/abstract-compile.sh +++ b/helper-scripts/abstract/abstract-compile.sh @@ -1,16 +1,25 @@ #!/bin/bash function compile() { - local TOOLCHAIN_HOME=${1} - local TARGET=${2} - local source_dir=${3} + local C_COMPILER=${1} + local CXX_COMPILER=${2} + local TOOLCHAIN_HEADERS=${3} + local COMPILER_OPTIONS=${4} + local BUILD_COMMAND=${5} + local TARGET=${6} + local source_dir=${7} local temp=$(pwd) cd ${source_dir} - cmake "-DTOOLCHAIN_HOME=${TOOLCHAIN_HOME}" \ - "-DTARGET=${TARGET}" \ + cmake "-DC_COMPILER=${C_COMPILER}" \ + "-DCXX_COMPILER=${CXX_COMPILER}" \ + "-DTOOLCHAIN_HEADERS=${TOOLCHAIN_HEADERS}" \ + "-DCOMPILER_OPTIONS=${COMPILER_OPTIONS}" \ + "-DBUILD_COMMAND=${BUILD_COMMAND}" \ -S . -B "./build/${TARGET}" cmake --build "./build/${TARGET}" cd ${temp} + + return $? } diff --git a/helper-scripts/abstract/abstract-upload.sh b/helper-scripts/abstract/abstract-upload.sh index 8b4d55c..44be560 100644 --- a/helper-scripts/abstract/abstract-upload.sh +++ b/helper-scripts/abstract/abstract-upload.sh @@ -1,13 +1,13 @@ #!/bin/bash function convertToHex() { - local TOOLCHAIN_HOME=${1} + local objcopy=${1} local elf=${2} local directory=${3} temp=$(pwd) cd ${directory} - ${TOOLCHAIN_HOME}'/bin/avr-objcopy' -O ihex ${elf} ${elf}'.hex' + ${objcopy} -O ihex ${elf} ${elf}'.hex' cd $temp return $? } diff --git a/helper-scripts/project-impl/compile-atmega32.sh b/helper-scripts/project-impl/compile-atmega32.sh index 7f70815..5e207df 100755 --- a/helper-scripts/project-impl/compile-atmega32.sh +++ b/helper-scripts/project-impl/compile-atmega32.sh @@ -3,4 +3,10 @@ source "./helper-scripts/abstract/abstract-compile.sh" source "./helper-scripts/project-impl/variables.sh" -compile ${TOOLCHAIN_HOME} ${mcu_atmega32A} ${source_dir} +compile "${AVR_C_COMPILER}" \ + "${AVR_CXX_COMPILER}" \ + "${AVR_TOOLCHAIN_HEADERS}" \ + "-mmcu=${mcu_atmega32A} -O3" \ + "ALL" \ + "${mcu_atmega32A}" \ + ${source_dir} diff --git a/helper-scripts/project-impl/compile-atmega328p.sh b/helper-scripts/project-impl/compile-atmega328p.sh index 5fb7f03..17dda2e 100755 --- a/helper-scripts/project-impl/compile-atmega328p.sh +++ b/helper-scripts/project-impl/compile-atmega328p.sh @@ -3,4 +3,10 @@ source "./helper-scripts/abstract/abstract-compile.sh" source "./helper-scripts/project-impl/variables.sh" -compile ${TOOLCHAIN_HOME} ${mcu_atmega328p} ${source_dir} +compile "${AVR_C_COMPILER}" \ + "${AVR_CXX_COMPILER}" \ + "${AVR_TOOLCHAIN_HEADERS}" \ + "-mmcu=${mcu_atmega328p} -O3" \ + "ALL" \ + "${mcu_atmega328p}" \ + ${source_dir} diff --git a/helper-scripts/project-impl/compile-examples.sh b/helper-scripts/project-impl/compile-examples.sh index bb3697d..6c37fee 100755 --- a/helper-scripts/project-impl/compile-examples.sh +++ b/helper-scripts/project-impl/compile-examples.sh @@ -6,4 +6,10 @@ source "./helper-scripts/project-impl/variables.sh" target_mcu=${1} example=${2} -compile ${TOOLCHAIN_HOME} ${target_mcu} ${examples_dir} ${source_dir} ${example} \ No newline at end of file +compile "${AVR_C_COMPILER}" \ + "${AVR_CXX_COMPILER}" \ + "${AVR_TOOLCHAIN_HEADERS}" \ + "-mmcu=${target_mcu} -O3" \ + "${target_mcu}" \ + "${example}" \ + "${source_dir}" \ No newline at end of file diff --git a/helper-scripts/project-impl/upload-to-chip.sh b/helper-scripts/project-impl/upload-to-chip.sh index 581ead3..e1528e4 100755 --- a/helper-scripts/project-impl/upload-to-chip.sh +++ b/helper-scripts/project-impl/upload-to-chip.sh @@ -6,5 +6,5 @@ source "./helper-scripts/project-impl/variables.sh" elf=${1} directory=${2} -convertToHex ${TOOLCHAIN_HOME} ${elf} ${directory} +convertToHex ${AVR_OBJ_COPY} ${elf} ${directory} upload ${PROGRAMMER} ${BAUD_RATE} ${PORT} ${CHIP_ALIAS} ${elf} ${directory} \ No newline at end of file diff --git a/helper-scripts/project-impl/variables.sh b/helper-scripts/project-impl/variables.sh index a8b4ede..92c811c 100644 --- a/helper-scripts/project-impl/variables.sh +++ b/helper-scripts/project-impl/variables.sh @@ -1,8 +1,13 @@ #!/bin/bash project_root=$(pwd) -# home for toolchains and header files to link to sources -TOOLCHAIN_HOME="$project_root/avr8-gnu-toolchain-linux_x86_64" + +# AVR home for toolchains and header files to link to sources +AVR_TOOLCHAIN_HOME="$project_root/avr8-gnu-toolchain-linux_x86_64" +AVR_C_COMPILER="${AVR_TOOLCHAIN_HOME}/bin/avr-gcc" +AVR_CXX_COMPILER="${AVR_TOOLCHAIN_HOME}/bin/avr-g++" +AVR_OBJ_COPY="${AVR_TOOLCHAIN_HOME}/bin/avr-objcopy" +AVR_TOOLCHAIN_HEADERS="${AVR_TOOLCHAIN_HOME}/avr/include" # supported targets mcu_atmega32A="atmega32" From 12206be38a170a2c35176fdbc97e8605fc06c64f Mon Sep 17 00:00:00 2001 From: pavl_g Date: Tue, 16 May 2023 10:21:23 +0300 Subject: [PATCH 10/17] workflows/build-arithmos.yml: arithmos-native basic workflow --- .../workflows/{build-foobar.yml => build-arithmos.yml} | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) rename .github/workflows/{build-foobar.yml => build-arithmos.yml} (79%) diff --git a/.github/workflows/build-foobar.yml b/.github/workflows/build-arithmos.yml similarity index 79% rename from .github/workflows/build-foobar.yml rename to .github/workflows/build-arithmos.yml index 9da853f..dd6498b 100644 --- a/.github/workflows/build-foobar.yml +++ b/.github/workflows/build-arithmos.yml @@ -1,4 +1,4 @@ -name: Build libfoobar +name: Build arithmos-native on: push: @@ -16,12 +16,12 @@ jobs: - name: setup-toolchain run: chmod +rwx ./launch-sandbox-setup.sh && ./launch-sandbox-setup.sh - - name: compile-link-assemble libfoobar + - name: compile-link-assemble libarithmos run: chmod +rwx ./helper-scripts/project-impl/compile-all.sh && ./helper-scripts/project-impl/compile-all.sh - - name: compile-link-assemble hello_foobar.c + - name: compile-link-assemble hello_vector2d.c run: | chmod +rwx ./helper-scripts/project-impl/compile-examples.sh - ./helper-scripts/project-impl/compile-examples.sh atmega32 hello_foobar.c - ./helper-scripts/project-impl/compile-examples.sh atmega328p hello_foobar.c + ./helper-scripts/project-impl/compile-examples.sh atmega32 hello_vector2d.c + ./helper-scripts/project-impl/compile-examples.sh atmega328p hello_vector2d.c From e383b0505ec0bd80f355e33acf793a1ea0a2ecdd Mon Sep 17 00:00:00 2001 From: pavl_g Date: Tue, 16 May 2023 10:26:36 +0300 Subject: [PATCH 11/17] helper-scripts: fixed compile-examples source-dir --- helper-scripts/project-impl/compile-examples.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/helper-scripts/project-impl/compile-examples.sh b/helper-scripts/project-impl/compile-examples.sh index 6c37fee..add4257 100755 --- a/helper-scripts/project-impl/compile-examples.sh +++ b/helper-scripts/project-impl/compile-examples.sh @@ -12,4 +12,4 @@ compile "${AVR_C_COMPILER}" \ "-mmcu=${target_mcu} -O3" \ "${target_mcu}" \ "${example}" \ - "${source_dir}" \ No newline at end of file + "${examples_dir}" \ No newline at end of file From b8ccd71d7b40e8be57b304e728271a90b87a1e5e Mon Sep 17 00:00:00 2001 From: pavl_g Date: Tue, 16 May 2023 10:54:51 +0300 Subject: [PATCH 12/17] project: arithmos license and readme --- LICENSE | 43 +++++++++++++++++++++++-------------------- README.md | 12 +++++------- 2 files changed, 28 insertions(+), 27 deletions(-) diff --git a/LICENSE b/LICENSE index fdddb29..5221018 100644 --- a/LICENSE +++ b/LICENSE @@ -1,24 +1,27 @@ -This is free and unencumbered software released into the public domain. +Copyright (c) 2022, Arithmos Project, arithmos-native +All rights reserved. -Anyone is free to copy, modify, publish, use, compile, sell, or -distribute this software, either in source code form or as a compiled -binary, for any purpose, commercial or non-commercial, and by any -means. +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: -In jurisdictions that recognize copyright laws, the author or authors -of this software dedicate any and all copyright interest in the -software to the public domain. We make this dedication for the benefit -of the public at large and to the detriment of our heirs and -successors. We intend this dedication to be an overt act of -relinquishment in perpetuity of all present and future rights to this -software under copyright law. +1. Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR -OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, -ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR -OTHER DEALINGS IN THE SOFTWARE. +2. Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. -For more information, please refer to +3. Neither the name of the copyright holder nor the names of its + contributors may be used to endorse or promote products derived from + this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. \ No newline at end of file diff --git a/README.md b/README.md index a7db450..16f8052 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,7 @@ -# cmake-template +# arithmos-native -A template for embedded C libraries development. +The native portion for arithmos, a high performance maths algorithmic library written purely in C. -This template consists of the following modules: -1) foobar-core: for core code, this module gets compiled to a static library. -2) foobar-examples: for library examples (or your final runnable target). - -This template uses the avr toolchain, though you could edit it to use other toolchains, through editing the sandbox environment scripts. \ No newline at end of file +## This project has 2 modules: +- [x] arithmos-core: for core API header and source files. +- [x] arithmos-examples: for examples and techdemos. \ No newline at end of file From b1e4edf8ca0058f26fb045507a676b6323bba8da Mon Sep 17 00:00:00 2001 From: pavl_g Date: Tue, 16 May 2023 10:56:43 +0300 Subject: [PATCH 13/17] helper-scripts: attempt to fix example build --- helper-scripts/project-impl/compile-examples.sh | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/helper-scripts/project-impl/compile-examples.sh b/helper-scripts/project-impl/compile-examples.sh index add4257..d84aba4 100755 --- a/helper-scripts/project-impl/compile-examples.sh +++ b/helper-scripts/project-impl/compile-examples.sh @@ -6,10 +6,16 @@ source "./helper-scripts/project-impl/variables.sh" target_mcu=${1} example=${2} +temp=$(pwd) +cd "${examples_dir}" + compile "${AVR_C_COMPILER}" \ "${AVR_CXX_COMPILER}" \ "${AVR_TOOLCHAIN_HEADERS}" \ "-mmcu=${target_mcu} -O3" \ "${target_mcu}" \ - "${example}" \ - "${examples_dir}" \ No newline at end of file + "${example}" + "" + +cd ${temp} + \ No newline at end of file From 982bbe0a3c54a81e56a0020613f2df8ad864c410 Mon Sep 17 00:00:00 2001 From: pavl_g Date: Tue, 16 May 2023 11:12:09 +0300 Subject: [PATCH 14/17] helper-scripts: added STATIC_LIB directory for compiling script --- helper-scripts/project-impl/compile-examples.sh | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/helper-scripts/project-impl/compile-examples.sh b/helper-scripts/project-impl/compile-examples.sh index d84aba4..bac4546 100755 --- a/helper-scripts/project-impl/compile-examples.sh +++ b/helper-scripts/project-impl/compile-examples.sh @@ -6,16 +6,11 @@ source "./helper-scripts/project-impl/variables.sh" target_mcu=${1} example=${2} -temp=$(pwd) -cd "${examples_dir}" - compile "${AVR_C_COMPILER}" \ "${AVR_CXX_COMPILER}" \ "${AVR_TOOLCHAIN_HEADERS}" \ "-mmcu=${target_mcu} -O3" \ + "${source_dir}" \ "${target_mcu}" \ - "${example}" - "" - -cd ${temp} - \ No newline at end of file + "${example}" \ + "${examples_dir}" \ No newline at end of file From 6e69e9209013c813a27417263c96c234e96a1332 Mon Sep 17 00:00:00 2001 From: pavl_g Date: Tue, 16 May 2023 11:16:16 +0300 Subject: [PATCH 15/17] build: refactored STATIC_LIB_SOURCE to STATIC_LIB_DIR --- arithmos-examples/CMakeLists.txt | 8 ++++---- helper-scripts/abstract/abstract-compile-examples.sh | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/arithmos-examples/CMakeLists.txt b/arithmos-examples/CMakeLists.txt index e709104..4865b3a 100644 --- a/arithmos-examples/CMakeLists.txt +++ b/arithmos-examples/CMakeLists.txt @@ -9,7 +9,7 @@ message(STATUS "C compiler: ${C_COMPILER}") message(STATUS "CXX compiler: ${CXX_COMPILER}") message(STATUS "Toolchain headers: ${TOOLCHAIN_HEADERS}") message(STATUS "Compiler Options: ${COMPILER_OPTIONS}") -message(STATUS "Included-library: ${STATIC_LIB_SOURCE}") +message(STATUS "Included-library: ${STATIC_LIB_DIR}") message(STATUS "Runnable-example: ${EXAMPLE}") # Cmake variables @@ -19,8 +19,8 @@ set(CMAKE_C_COMPILER "${C_COMPILER}") set(CMAKE_CXX_COMPILER "${CXX_COMPILER}") set(COMPILER_OPTIONS "${COMPILER_OPTIONS}") -set(headers "${STATIC_LIB_SOURCE}/src/include") -set(avr_headers "${TOOLCHAIN_HEADERS}") +set(headers "${STATIC_LIB_DIR}/src/include/") +set(toolchain_headers "${TOOLCHAIN_HEADERS}") # C sources set(sources "${CMAKE_CURRENT_SOURCE_DIR}/src/${EXAMPLE}") @@ -32,7 +32,7 @@ add_executable(${elf}) set_target_properties(${elf} PROPERTIES COMPILE_FLAGS "${COMPILER_OPTIONS}" LINK_FLAGS "${COMPILER_OPTIONS}") # include headers for the target -target_include_directories(${elf} PUBLIC ${avr_headers} ${headers}) +target_include_directories(${elf} PUBLIC ${toolchain_headers} ${headers}) # add all arithmos libraries here target_link_libraries(${elf} "${ARITHMOS_LIB}/build/${TARGET}/libvector2d.a") diff --git a/helper-scripts/abstract/abstract-compile-examples.sh b/helper-scripts/abstract/abstract-compile-examples.sh index 5f5da52..f496df1 100644 --- a/helper-scripts/abstract/abstract-compile-examples.sh +++ b/helper-scripts/abstract/abstract-compile-examples.sh @@ -6,7 +6,7 @@ function compile() { local TOOLCHAIN_HEADERS=${3} local COMPILER_OPTIONS=${4} local TARGET=${5} - local STATIC_LIB_SOURCE=${6} + local STATIC_LIB_DIR=${6} local EXAMPLE=${7} local source_dir=${8} @@ -16,7 +16,7 @@ function compile() { "-DCXX_COMPILER=${CXX_COMPILER}" \ "-DTOOLCHAIN_HEADERS=${TOOLCHAIN_HEADERS}" \ "-DCOMPILER_OPTIONS=${COMPILER_OPTIONS}" \ - "-DSTATIC_LIB_SOURCE=${STATIC_LIB_SOURCE}" \ + "-DSTATIC_LIB_DIR=${STATIC_LIB_DIR}" \ "-DEXAMPLE=${EXAMPLE}" \ -S . -B "./build/${TARGET}" From 40c70f6dc2ec6734f3c5cd2dc810bd2fdff00092 Mon Sep 17 00:00:00 2001 From: pavl_g Date: Tue, 16 May 2023 11:23:25 +0300 Subject: [PATCH 16/17] helper-scripts: fixed compile example parameters --- helper-scripts/project-impl/compile-examples.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/helper-scripts/project-impl/compile-examples.sh b/helper-scripts/project-impl/compile-examples.sh index bac4546..86b74f1 100755 --- a/helper-scripts/project-impl/compile-examples.sh +++ b/helper-scripts/project-impl/compile-examples.sh @@ -10,7 +10,7 @@ compile "${AVR_C_COMPILER}" \ "${AVR_CXX_COMPILER}" \ "${AVR_TOOLCHAIN_HEADERS}" \ "-mmcu=${target_mcu} -O3" \ - "${source_dir}" \ "${target_mcu}" \ + "${source_dir}" \ "${example}" \ "${examples_dir}" \ No newline at end of file From 747528b03bd7a98ffd9ac7e70b2d370f53038f3b Mon Sep 17 00:00:00 2001 From: pavl_g Date: Tue, 16 May 2023 11:31:16 +0300 Subject: [PATCH 17/17] hello_vector2d: fixed vector2d objects --- arithmos-examples/src/hello_vector2d.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/arithmos-examples/src/hello_vector2d.c b/arithmos-examples/src/hello_vector2d.c index 3bbf082..da9cac9 100644 --- a/arithmos-examples/src/hello_vector2d.c +++ b/arithmos-examples/src/hello_vector2d.c @@ -8,14 +8,12 @@ vector2d vec0 = { 0, - 1, - 2 + 1 }; vector2d vec1 = { 2, - 3, - 4 + 3 }; int main() {