2023-04-04 15:17:37 +00:00
|
|
|
#include "CircleArc.h"
|
2023-02-05 17:39:02 +00:00
|
|
|
#include <numbers>
|
|
|
|
#include "Line.h"
|
|
|
|
|
2023-04-04 15:17:37 +00:00
|
|
|
CircleArc::CircleArc(double x, double y, double radiusX, double radiusY, double startAngle, double endAngle) : x(x), y(y), radiusX(radiusX), radiusY(radiusY), startAngle(startAngle), endAngle(endAngle) {}
|
2023-02-05 17:39:02 +00:00
|
|
|
|
2024-01-07 16:17:20 +00:00
|
|
|
Point CircleArc::nextVector(double drawingProgress) {
|
2023-02-05 17:39:02 +00:00
|
|
|
// scale between start and end angle in the positive direction
|
|
|
|
double angle = startAngle + endAngle * drawingProgress;
|
2024-01-07 16:17:20 +00:00
|
|
|
return Point(
|
2023-02-05 17:39:02 +00:00
|
|
|
x + radiusX * std::cos(angle),
|
|
|
|
y + radiusY * std::sin(angle)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2024-01-07 19:48:02 +00:00
|
|
|
void CircleArc::scale(double x, double y, double z) {
|
2023-02-05 17:39:02 +00:00
|
|
|
this->x *= x;
|
|
|
|
this->y *= y;
|
|
|
|
this->radiusX *= x;
|
|
|
|
this->radiusY *= y;
|
|
|
|
}
|
|
|
|
|
2024-01-07 19:48:02 +00:00
|
|
|
void CircleArc::translate(double x, double y, double z) {
|
2023-02-05 17:39:02 +00:00
|
|
|
this->x += x;
|
|
|
|
this->y += y;
|
|
|
|
}
|
|
|
|
|
2023-04-04 15:17:37 +00:00
|
|
|
double CircleArc::length() {
|
2023-02-05 17:39:02 +00:00
|
|
|
if (len < 0) {
|
|
|
|
len = 0;
|
2023-09-07 21:04:08 +00:00
|
|
|
// TODO: Replace this, it's stupid. Do a real approximation.
|
2023-09-05 21:57:29 +00:00
|
|
|
int segments = 5;
|
2024-01-07 16:17:20 +00:00
|
|
|
Point start;
|
|
|
|
Point end = nextVector(0);
|
2023-09-05 21:57:29 +00:00
|
|
|
for (int i = 0; i < segments; i++) {
|
2023-12-21 14:14:33 +00:00
|
|
|
start = end;
|
|
|
|
end = nextVector((i + 1) / (double) segments);
|
2024-01-07 19:48:02 +00:00
|
|
|
len += Line::length(start.x, start.y, start.z, end.x, end.y, end.z);
|
2023-02-05 17:39:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return len;
|
|
|
|
}
|
|
|
|
|
2023-04-04 15:17:37 +00:00
|
|
|
std::unique_ptr<Shape> CircleArc::clone() {
|
|
|
|
return std::make_unique<CircleArc>(x, y, radiusX, radiusY, startAngle, endAngle);
|
2023-02-05 17:39:02 +00:00
|
|
|
}
|
|
|
|
|
2023-04-04 15:17:37 +00:00
|
|
|
std::string CircleArc::type() {
|
2023-02-05 17:39:02 +00:00
|
|
|
return std::string("Arc");
|
|
|
|
}
|