From 14c13358812c238a51e731d4935ac1c5bb2bece7 Mon Sep 17 00:00:00 2001 From: Shaohua Tong Date: Wed, 11 Dec 2019 11:55:00 +0100 Subject: [PATCH] utils add --- src/utils.cpp | 25 +++++++++++++++++++++++++ src/utils.hpp | 21 +++++++++++++++++++++ 2 files changed, 46 insertions(+) create mode 100644 src/utils.cpp create mode 100644 src/utils.hpp diff --git a/src/utils.cpp b/src/utils.cpp new file mode 100644 index 0000000..9fb3201 --- /dev/null +++ b/src/utils.cpp @@ -0,0 +1,25 @@ +// +// Created by shaohuatong on 06.12.19. +// + +#include "utils.hpp" + +int utils::squareOfDistance(vkvm::Coordinates x, vkvm::Coordinates y) { + return (x.x - y.x) * (x.x - y.x) + (x.y - y.y) * (x.y - y.y); +} + +int utils::getDistance(vkvm::Coordinates x, vkvm::Coordinates y) { + return (int)floor(sqrt(squareOfDistance(x, y))); +} + +int utils::min(int x, int y) { + if(x <= y) + return x; + return y; +} + +int utils::max(int x, int y) { + if(x<=y) + return y; + return x; +} \ No newline at end of file diff --git a/src/utils.hpp b/src/utils.hpp new file mode 100644 index 0000000..c208db5 --- /dev/null +++ b/src/utils.hpp @@ -0,0 +1,21 @@ +// +// Created by shaohuatong on 06.12.19. +// + +#ifndef SIMPLE_DRAW_UTILS_HPP +#define SIMPLE_DRAW_UTILS_HPP + +#include "vkvm.hpp" +#include "internal.hpp" +#include "math.h" + +class utils { +public: + static int squareOfDistance(vkvm::Coordinates x, vkvm::Coordinates y); + static int getDistance(vkvm::Coordinates x, vkvm::Coordinates y); + static int min(int x, int y); + static int max(int x, int y); +}; + + +#endif //SIMPLE_DRAW_UTILS_H