Skip to content

Commit d1fdb3e

Browse files
authored
Merge pull request #89 from Electrostat-Lab/physics-engine
Arithmos Infrastructure for the Physics Engine (Delta-Engine)
2 parents 5cb8a7e + 600d9fa commit d1fdb3e

File tree

95 files changed

+4138
-384
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

95 files changed

+4138
-384
lines changed

electrostatic-sandbox-framework/electrostatic-core/src/include/electrostatic/electronetsoft/algorithm/arithmos/README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
# Arithmos _αριθμός_
22

3-
Arithmos is a set of APIs that target different taxonomies of algorithms to solve problems through providing _algorithm generic utilities_, and several implementations for the common _abstract data types (adt)_ commonly encountered during solving problems while building commericial applications or participating in problem solving contests.
3+
Arithmos is a set of APIs that target different taxonomies of algorithms to solve problems through providing _algorithm generic utilities_, and several implementations for the common _abstract data types (adt)_ commonly encountered during solving problems while building commercial applications or participating in problem solving contests.
44

55
Arithmos is essentially composed of the following:
66
- [x] Vector2d Library (Finished).
7-
- [ ] Vector3d Library.
8-
- [ ] MatrixNd Library.
7+
- [x] Vector3d Library (Partially Finished).
8+
- [x] MatrixNd Library (Partially Finished).
99
- [ ] Discrete Sets Operations (Conjunctive, Disjunctive, Subtraction, Powersets, De'Morgans formulas).
1010
- [ ] Physics Simulation Library (Collision detection - Force Control - Objects interactions).
11-
- [ ] Statistics Algoritms Library (Present in Java - WIP to port).
11+
- [ ] Statistics Algorithms Library (Present in Java - WIP to port).
1212
- [ ] Differential and Integral Calculus Library.
1313
- [ ] Generic Algorithms Utilities Library.
1414
- [ ] Linear Algorithms Library.
@@ -52,7 +52,7 @@ Most of these libraries rely on the _Generic Algorithms Utilities Library_; this
5252
- Hashing Algorithms.
5353
- [ ] Modular Arithmetics.
5454
- Un-hashing Algorithms.
55-
- Switching Algebra ALgorithms.
55+
- Switching Algebra Algorithms.
5656
- [ ] Elementary Bit switching.
5757
- [ ] Elementary Bit shifting.
5858
- [ ] Elementary Byte switching.

electrostatic-sandbox-framework/electrostatic-core/src/include/electrostatic/electronetsoft/algorithm/arithmos/vectorspaces/coordinate.h

Lines changed: 0 additions & 77 deletions
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
#ifndef _MAT_ND_H_
2+
#define _MAT_ND_H_
3+
4+
#include <math.h>
5+
#include <electrostatic/electronetsoft/util/types.h>
6+
#include <electrostatic/electronetsoft/util/caller_graphs.h>
7+
#include <electrostatic/electronetsoft/util/utilities.h>
8+
#include <electrostatic/electronetsoft/algorithm/arithmos/vectorspaces/vector2d/vector2d.h>
9+
#include <electrostatic/electronetsoft/algorithm/arithmos/vectorspaces/vector3d/vector3d.h>
10+
11+
#ifdef __cplusplus
12+
extern "C" {
13+
#endif
14+
15+
struct matrix {
16+
vec_component **element;
17+
uint64_t m;
18+
uint64_t n;
19+
};
20+
21+
struct mat_processors {
22+
status_code (*on_entry_iterated)(mat_proc_sig);
23+
status_code (*on_row_iterated)(mat_proc_sig);
24+
status_code (*on_column_iterated)(mat_proc_sig);
25+
status_code (*on_binary_op_preprocessor)(mat_binary_op_sig);
26+
status_code (*on_binary_op_postprocessor)(mat_binary_op_sig);
27+
status_code (*on_unary_op_preprocessor)(mat_proc_sig);
28+
status_code (*on_elementary_op_postprocessor)(mat_proc_sig);
29+
void (*on_op_success)(mat_proc_sig);
30+
void (*on_op_failure)(mat_proc_sig, status_code);
31+
caller_graph *root;
32+
void *metadata;
33+
};
34+
35+
struct mat_binary_op_sig {
36+
matrix m0;
37+
matrix m1;
38+
uint64_t row_index;
39+
uint64_t col_index;
40+
mat_processors proc;
41+
void *metadata;
42+
};
43+
44+
struct mat_proc_sig {
45+
matrix mat;
46+
uint64_t row_index;
47+
uint64_t col_index;
48+
mat_processors proc;
49+
caller_graph caller;
50+
void *metadata;
51+
};
52+
53+
static inline status_code is_last_column(matrix mat, uint64_t index) {
54+
return index != 0 // the last column is never at the first index!
55+
&& (index % (mat.n - 1) == 0)
56+
&& ASSERTION_SUCCESS;
57+
}
58+
59+
static inline status_code is_last_row(matrix mat, uint64_t index) {
60+
return index != 0 // the last row is never at the first index!
61+
&& (index % (mat.m - 1) == 0)
62+
&& ASSERTION_SUCCESS;
63+
}
64+
65+
status_code mat_add(matrix, matrix, matrix *, mat_processors);
66+
status_code mat_subtract(matrix, matrix, matrix *, mat_processors);
67+
status_code mat_product(matrix, matrix, matrix *, mat_processors);
68+
status_code mat_scalar_prod(matrix, vec_component, matrix *, mat_processors);
69+
status_code mat_scalar_divide(matrix, vec_component, matrix *, mat_processors);
70+
status_code mat_create_rotator_matrix(vec_component, matrix *, mat_processors *);
71+
status_code mat_create_from_vector2d(vector2d, matrix *, mat_processors);
72+
status_code mat_create_from_vector3d(vector3d, matrix *, mat_processors);
73+
status_code mat_iterate_rows(matrix, mat_processors);
74+
status_code mat_iterate_columns(matrix, mat_processors);
75+
status_code mat_iterate_elements(matrix, mat_iterator, mat_processors);
76+
77+
#ifdef __cplusplus
78+
};
79+
#endif
80+
81+
#endif
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
#if !(defined __VECTOR_2D_H_ || defined __VECTOR_3D_H_)
2+
# error "Use vector2d or vector3d instead of this!"
3+
#endif
4+
5+
#ifndef __VEC_COMPONENT_H_
6+
#define __VEC_COMPONENT_H_
7+
8+
#include <math.h>
9+
#include <inttypes.h>
10+
11+
#if defined (_VECTOR2D_USE_UINT8_)
12+
# define vec_component uint8_t
13+
# define mod_vec_component vec_component
14+
# define vector2d_pow(v, p) ((uint8_t) powf(v, p))
15+
# define vector2d_atan2(y, x) ((uint8_t) atan2f(y, x))
16+
# define vector2d_acos(v) ((uint8_t) acosf(v))
17+
# define vector2d_cos(v) ((uint8_t) cosf(v))
18+
#elif defined (_VECTOR2D_USE_INT8_)
19+
# define vec_component int8_t
20+
# define mod_vec_component vec_component
21+
# define vector2d_pow(v, p) ((int8_t) powf(v, p))
22+
# define vector2d_atan2(y, x) ((int8_t) atan2f(y, x))
23+
# define vector2d_acos(v) ((int8_t) acosf(v))
24+
# define vector2d_cos(v) ((int8_t) cosf(v))
25+
#elif defined (_VECTOR2D_USE_UINT16_)
26+
# define vec_component uint16_t
27+
# define mod_vec_component vec_component
28+
# define vector2d_pow(v, p) ((uint16_t) powf(v, p))
29+
# define vector2d_atan2(y, x) ((uint16_t) atan2f(y, x))
30+
# define vector2d_acos(v) ((uint16_t) acosf(v))
31+
# define vector2d_cos(v) ((uint16_t) cosf(v))
32+
#elif defined (_VECTOR2D_USE_INT16_)
33+
# define vec_component int16_t
34+
# define mod_vec_component vec_component
35+
# define vector2d_pow(v, p) ((int16_t) powf(v, p))
36+
# define vector2d_atan2(y, x) ((int16_t) atan2f(y, x))
37+
# define vector2d_acos(v) ((int16_t) acosf(v))
38+
# define vector2d_cos(v) ((int16_t) cosf(v))
39+
#elif defined (_VECTOR2D_USE_UINT32_)
40+
# define vec_component uint32_t
41+
# define mod_vec_component vec_component
42+
# define vector2d_pow(v, p) ((uint32_t) powf(v, p))
43+
# define vector2d_atan2(y, x) ((uint32_t) atan2f(y, x))
44+
# define vector2d_acos(v) ((uint32_t) acosf(v))
45+
# define vector2d_cos(v) ((uint32_t) cosf(v))
46+
#elif defined (_VECTOR2D_USE_INT32_)
47+
# define vec_component int32_t
48+
# define mod_vec_component vec_component
49+
# define vector2d_pow(v, p) ((int32_t) powf(v, p))
50+
# define vector2d_atan2(y, x) ((int32_t) atan2f(y, x))
51+
# define vector2d_acos(v) ((int32_t) acosf(v))
52+
# define vector2d_cos(v) ((int32_t) cosf(v))
53+
#elif defined (_VECTOR2D_USE_UINT64_)
54+
# define vec_component uint64_t
55+
# define mod_vec_component vec_component
56+
# define vector2d_pow(v, p) ((uint64_t) powl(v, p))
57+
# define vector2d_atan2(y, x) ((uint64_t) atan2l(y, x))
58+
# define vector2d_acos(v) ((uint64_t) acosl(v))
59+
# define vector2d_cos(v) ((uint64_t) cosf(v))
60+
#elif defined (_VECTOR2D_USE_INT64_)
61+
# define vec_component int64_t
62+
# define mod_vec_component vec_component
63+
# define vector2d_pow(v, p) ((int64_t) powl(v, p))
64+
# define vector2d_atan2(y, x) ((int64_t) atan2l(y, x))
65+
# define vector2d_acos(v) ((int64_t) acosl(v))
66+
# define vector2d_cos(v) ((int64_t) cosf(v))
67+
#elif defined (_VECTOR2D_USE_DOUBLE_)
68+
# define vec_component double
69+
# define mod_vec_component int64_t
70+
# define vector2d_pow(v, p) ((double) powl(v, p))
71+
# define vector2d_atan2(y, x) ((double) atan2l(y, x))
72+
# define vector2d_acos(v) ((double) acosl(v))
73+
# define vector2d_cos(v) ((double) cosf(v))
74+
#else
75+
// default program flow
76+
typedef float vec_component;
77+
typedef int32_t mod_vec_component;
78+
# define vector2d_pow(v, p) ((float) pow(v, p))
79+
# define vector2d_atan2(y, x) ((float) atan2f(y, x))
80+
# define vector2d_acos(v) ((float) acosf(v))
81+
# define vector2d_cos(v) ((float) cosf(v))
82+
# define vector2d_sin(v) ((float) sinf(v))
83+
#endif
84+
85+
#define vector2d_sqrt(v) vector2d_pow(v, 0.5)
86+
#define vector2d_abs(v) ((vec_component) vector2d_sqrt(vector2d_pow(v, 2)))
87+
88+
#endif // __VEC_COMPONENT_H_

0 commit comments

Comments
 (0)