This repository has been archived on 2025-10-24. You can view files and clone it, but cannot push or open issues or pull requests.
Files
MemMAPR-MKR/src/Primitives.cpp

78 lines
2.3 KiB
C++

#include "Primitives.hpp"
Rectangle::Rectangle(double _x, double _y, double _h_x, double _h_y, bool _excluded, int _btype) : x(_x), y(_y), h_x(_h_x), h_y(_h_y) {
excluded = _excluded;
bound_type = _btype;
}
std::pair<double, double> Rectangle::missX(double _y) {
return { 0.5 / h_x + x, -0.5 / h_x + x };
}
std::pair<double, double> Rectangle::missY(double _x) {
return { 0.5 / h_y + y, -0.5 / h_y + y };
}
std::pair<double, double> Rectangle::size() {
return { 1 / h_x, 1 / h_y };
}
double Rectangle::Function(double _x, double _y) {
return std::max(h_x * std::abs(_x - x), h_y * std::abs(_y - y));
}
bool Rectangle::Inhere(double x, double y) {
return Function(x, y) <= EPS_RECTANGLE;
}
Circle::Circle(double _x, double _y, double _h_x, double _h_y, bool _excluded, int _btype) : x(_x), y(_y), h_x(_h_x), h_y(_h_y) {
excluded = _excluded;
bound_type = _btype;
}
std::pair<double, double> Circle::missY(double _x) {
return { std::sqrt(1 - pow((h_x * (_x - x)), 2)) / h_y + y, -std::sqrt(1 - pow((h_x * (_x - x)), 2)) / h_y + y };
}
std::pair<double, double> Circle::missX(double _y) {
return { std::sqrt(1 - pow((h_y * (_y - y)), 2)) / h_x + x, -std::sqrt(1 - pow((h_y * (_y - y)), 2)) / h_x + x };
}
double Circle::Function(double _x, double _y) {
return pow(h_x * (_x - x), 2) + pow(h_y * (_y - y), 2);
}
std::pair<double, double> Circle::size() {
return { 1 / h_x, 1 / h_y };
}
bool Circle::Inhere(double x, double y) {
return Function(x, y) <= EPS_CIRCLE;
}
Arc::Arc(double _x, double _y, double _h_x, double _h_y, bool _excluded, int _btype) : x(_x), y(_y), h_x(_h_x), h_y(_h_y) {
excluded = _excluded;
bound_type = _btype;
}
std::pair<double, double> Arc::missY(double _x) {
return { std::sqrt(1 - pow((h_x * (_x - x)), 2)) / h_y + y, std::sqrt(1 - pow((h_x * (_x - x)), 2)) / h_y + y };
}
std::pair<double, double> Arc::missX(double _y) {
return { std::sqrt(1 - pow((h_y * (_y - y)), 2)) / h_x + x, std::sqrt(1 - pow((h_y * (_y - y)), 2)) / h_x + x };
}
double Arc::Function(double _x, double _y) {
if (_x >= x && _y >= y) {
return pow(h_x * (_x - x), 2) + pow(h_y * (_y - y), 2);
}
return -1.0;
}
std::pair<double, double> Arc::size() {
return { 1 / h_x, 1 / h_y };
}
bool Arc::Inhere(double x, double y) {
return Function(x, y) >= 1;
}