Compare commits

..

13 Commits

Author SHA1 Message Date
Simon Bruder e64cbfdcf2 u02: Make star preview more variable 2023-05-16 16:49:59 +02:00
Simon Bruder 18da3567cc u02/star_tool: Allow setting spikes in ctor 2023-05-16 16:49:23 +02:00
Simon Bruder f482d0a951 flake: Use correct input types for dependencies 2023-05-16 16:49:23 +02:00
Simon Bruder 1aae98c18b u02: Add readme 2023-05-16 16:49:23 +02:00
Simon Bruder 2290a6314d u02/tests: Fix inverted logic in comment 2023-05-16 16:49:22 +02:00
Simon Bruder c5289609e5 flake: Build variants without tests
Tests set the C++ version to 17, however only up to 11 is allowed in the
other files.
2023-05-16 16:49:22 +02:00
Simon Bruder 085b8fcdb9 u02/tests: Fix edge case for invalid points 2023-05-16 16:49:22 +02:00
Simon Bruder 8f784ccf3e u02/tests: Fix skipping behaviour
When the test runner only tests one case, it exits with a non-zero exit
code should that test invoke a skip (even if there are 1000+ successful
iterations).

This fixes this by falling back to a cheap message to stderr.
2023-05-16 16:49:22 +02:00
Simon Bruder ad02a06db4 u02/tests: Fix floating point comparison
I didn’t really understand what WithinRel and WithinAbs do. Now I know
that for this use case WithinAbs is the better choice.

This also increases the allowed deviance for the average point of all
points of a star, because this would now fail for larger values.
2023-05-16 16:49:22 +02:00
Simon Bruder d4794e1544 u02/tests: Add average point test for star 2023-05-16 16:49:22 +02:00
Simon Bruder 583f2ecd3e u02: Implement preview for star
It is fixed to a star with 5 spikes, but better than a circle.
2023-05-16 16:49:22 +02:00
Simon Bruder 85e38a358d u02/tests: Use floats for r/d in circle prop test
It does not improve the test’s accuracy, but it seems weird to first
convert the radius to an int and then save the distance as a double.
2023-05-16 16:49:22 +02:00
Simon Bruder 2226fb32af u02: Implement star tool 2023-05-16 16:49:22 +02:00
4 changed files with 38 additions and 12 deletions

View File

@ -9,7 +9,7 @@
pkgs = import nixpkgs { inherit system; };
mkNocheck = drv: drv.overrideAttrs (o: {
doCheck = false;
nativeBuildInputs = pkgs.lib.filter (p: p != pkgs.catch2_3) o.nativeBuildInputs;
checkInputs = [ ];
});
in
{
@ -20,7 +20,8 @@
src = ./u01;
nativeBuildInputs = [ catch2_3 cmake ];
nativeBuildInputs = [ cmake ];
checkInputs = [ catch2_3 ];
doCheck = true;
})
@ -32,7 +33,9 @@
src = ./u02;
nativeBuildInputs = [ catch2_3 cmake freeglut libGL libGLU ];
nativeBuildInputs = [ cmake ];
buildInputs = [ freeglut libGL libGLU ];
checkInputs = [ catch2_3 ];
doCheck = true;
})

View File

@ -22,11 +22,15 @@ regular_polygon_mod(int n, std::function<float(int)> rf, int x = 0, int y = 0,
// and the centre (x, y),
// rotated by base_angle.
std::vector<std::pair<float, float>> star(int n, float r1, float r2, int x = 0,
int y = 0, float base_angle = 0);
int y = 0, float base_angle = 0);
class star_tool : public tool_base {
public:
star_tool(canvas_buffer &canvas);
// Initialize a new star tool.
// It can draw stars with arbitrary number of spikes (however, at least 2).
// 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);
@ -37,6 +41,6 @@ public:
void set_radius_factor(int radius_factor);
private:
int spikes = 5;
int spikes;
float radius_factor = 1.0 / 3.0;
};

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

@ -41,8 +41,8 @@ std::vector<std::pair<float, float>> star(int n, float r1, float r2, int x,
base_angle);
}
star_tool::star_tool(canvas_buffer &canvas) : tool_base(canvas) {
shape = TS_STAR;
star_tool::star_tool(canvas_buffer &canvas, int spikes) : tool_base(canvas) {
set_spikes(spikes);
}
void star_tool::draw(int x0, int y0, int x1, int y1) {
@ -67,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;