utils add

This commit is contained in:
Shaohua Tong 2019-12-11 11:55:00 +01:00
parent d053170cf5
commit 14c1335881
2 changed files with 46 additions and 0 deletions

25
src/utils.cpp Normal file
View File

@ -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;
}

21
src/utils.hpp Normal file
View File

@ -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