u02: Make star preview more variable

filtered
Simon Bruder 2023-05-16 16:45:07 +02:00
parent 18da3567cc
commit e64cbfdcf2
3 changed files with 25 additions and 6 deletions

View File

@ -28,7 +28,8 @@ class star_tool : public tool_base {
public:
// Initialize a new star tool.
// It can draw stars with arbitrary number of spikes (however, at least 2).
// The preview is hard coded to 5 spikes.
// The preview only supports spikes from 3 to 6 and falls back to 5
// if a spike outside of that range is given.
star_tool(canvas_buffer &canvas, int spikes = 5);
void draw(int x0, int y0, int x1, int y1);

View File

@ -53,9 +53,10 @@ jedoch erst ab 3 eine Art Stern vorliegt).
In dem Beispielprogramm kann jedoch aus Komplexitätsgründen nur aus bestimmten Zackenanzahlen gewählt werden,
was jedoch per Kontextmenü möglich ist und damit der Aufgabenstellung entspricht.
Darüber hinaus wurde rudimentär eine Vorschau der Sternform hinzugefügt,
was jedoch nur für eine feste Zackenanzahl (hier: 5) möglich ist,
ohne die Architektur der Applikation zu ändern.
Darüber hinaus wurde rudimentär eine Vorschau der Sternform hinzugefügt.
Da die vorgegebene Architektur keine Spezialisierungen der Formen eines Tools erlaubt,
und C++ (anders als bspw. Rust) keine Tuple/Struct enums zulässt,
wurden hier nur die über die Benutzerschnittstelle verfügbaren Zackenanzahlen fest implementiert.
### Sweepline-Algorithmus

View File

@ -42,7 +42,6 @@ std::vector<std::pair<float, float>> star(int n, float r1, float r2, int x,
}
star_tool::star_tool(canvas_buffer &canvas, int spikes) : tool_base(canvas) {
shape = TS_STAR;
set_spikes(spikes);
}
@ -68,7 +67,25 @@ void star_tool::set_text(std::stringstream &stream) {
stream << "Tool: Star (" << spikes << " spikes)";
}
void star_tool::set_spikes(int spikes) { this->spikes = spikes; }
void star_tool::set_spikes(int spikes) {
this->spikes = spikes;
switch (spikes) {
case 3:
shape = TS_STAR_3;
break;
case 4:
shape = TS_STAR_4;
break;
// 5 is default, handled at the end
case 6:
shape = TS_STAR_6;
break;
case 5:
default:
shape = TS_STAR_5;
break;
}
}
void star_tool::set_radius_factor(int radius_factor) {
this->radius_factor = radius_factor;