utils add
This commit is contained in:
parent
d053170cf5
commit
14c1335881
25
src/utils.cpp
Normal file
25
src/utils.cpp
Normal 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
21
src/utils.hpp
Normal 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
|
Loading…
Reference in New Issue
Block a user