From e64cbfdcf2f6c56c394bae85968881c35a6a258a Mon Sep 17 00:00:00 2001 From: Simon Bruder Date: Tue, 16 May 2023 16:45:07 +0200 Subject: [PATCH] u02: Make star preview more variable --- u02/include/star_tool.h | 3 ++- u02/readme.txt | 7 ++++--- u02/src/star_tool.cpp | 21 +++++++++++++++++++-- 3 files changed, 25 insertions(+), 6 deletions(-) diff --git a/u02/include/star_tool.h b/u02/include/star_tool.h index eb1160f..bbd9669 100644 --- a/u02/include/star_tool.h +++ b/u02/include/star_tool.h @@ -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); diff --git a/u02/readme.txt b/u02/readme.txt index 8440771..b8dfa2d 100644 --- a/u02/readme.txt +++ b/u02/readme.txt @@ -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 diff --git a/u02/src/star_tool.cpp b/u02/src/star_tool.cpp index fb9bd72..b4fdb5b 100644 --- a/u02/src/star_tool.cpp +++ b/u02/src/star_tool.cpp @@ -42,7 +42,6 @@ std::vector> 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;