2023-01-15 17:01:27 +00:00
|
|
|
#include "Line.h"
|
|
|
|
|
2024-01-07 16:37:22 +00:00
|
|
|
Line::Line(double x1, double y1, double x2, double y2) : x1(x1), y1(y1), z1(0), x2(x2), y2(y2), z2(0) {}
|
|
|
|
|
|
|
|
Line::Line(double x1, double y1, double z1, double x2, double y2, double z2) : x1(x1), y1(y1), z1(z1), x2(x2), y2(y2), z2(z2) {}
|
2023-01-15 17:01:27 +00:00
|
|
|
|
2024-01-07 16:17:20 +00:00
|
|
|
Point Line::nextVector(double drawingProgress) {
|
|
|
|
return Point(
|
2023-01-15 17:01:27 +00:00
|
|
|
x1 + (x2 - x1) * drawingProgress,
|
2024-01-07 16:37:22 +00:00
|
|
|
y1 + (y2 - y1) * drawingProgress,
|
|
|
|
z1 + (z2 - z1) * drawingProgress
|
2023-01-15 17:01:27 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Line::scale(double x, double y) {
|
|
|
|
x1 *= x;
|
|
|
|
y1 *= y;
|
|
|
|
x2 *= x;
|
|
|
|
y2 *= y;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Line::translate(double x, double y) {
|
|
|
|
x1 += x;
|
|
|
|
y1 += y;
|
|
|
|
x2 += x;
|
|
|
|
y2 += y;
|
|
|
|
}
|
|
|
|
|
2023-12-21 14:14:33 +00:00
|
|
|
double Line::length(double x1, double y1, double x2, double y2) {
|
|
|
|
// Euclidean distance approximation based on octagonal boundary
|
|
|
|
double dx = std::abs(x2 - x1);
|
|
|
|
double dy = std::abs(y2 - y1);
|
|
|
|
|
|
|
|
return 0.41 * std::min(dx, dy) + 0.941246 * std::max(dx, dy);
|
|
|
|
}
|
|
|
|
|
2023-01-15 22:34:02 +00:00
|
|
|
double inline Line::length() {
|
2023-01-15 17:01:27 +00:00
|
|
|
if (len < 0) {
|
|
|
|
// Euclidean distance approximation based on octagonal boundary
|
|
|
|
double dx = std::abs(x2 - x1);
|
|
|
|
double dy = std::abs(y2 - y1);
|
|
|
|
|
|
|
|
len = 0.41 * std::min(dx, dy) + 0.941246 * std::max(dx, dy);
|
|
|
|
}
|
|
|
|
return len;
|
|
|
|
}
|
2023-02-05 00:43:57 +00:00
|
|
|
|
|
|
|
std::unique_ptr<Shape> Line::clone() {
|
|
|
|
return std::make_unique<Line>(x1, y1, x2, y2);
|
|
|
|
}
|
2023-02-05 17:39:02 +00:00
|
|
|
|
|
|
|
std::string Line::type() {
|
|
|
|
return std::string("Line");
|
|
|
|
}
|