types.c 568 B

123456789101112131415161718192021222324252627282930313233
  1. #include "types.h"
  2. /*template <class T>
  3. inline T sq(T value) {
  4. return value * value;
  5. }*/
  6. double sq(double val) {
  7. return val * val;
  8. }
  9. //extern "C"
  10. Coords create_coords(double x, double y) {
  11. Coords cord;
  12. cord.x = x;
  13. cord.y = y;
  14. return cord;
  15. }
  16. //extern "C"
  17. uint8_t coords_distance(Coords* a, Coords* b) {
  18. return sqrt(sq(a->x - b->x) + sq(a->y - b->y)) * 20;
  19. }
  20. //extern "C"
  21. UID create_uid(uint8_t type, uint8_t x, uint8_t y) {
  22. return ((y << 6) | x) << 4 | type;
  23. }
  24. //extern "C"
  25. uint8_t uid_get_type(UID uid) {
  26. return uid & 0x0F;
  27. }