Compare commits

..

10 commits

Author SHA1 Message Date
Simon Bruder 4f3c184519 u02: Add readme 2023-05-13 22:58:56 +02:00
Simon Bruder 9239c2904a u02/tests: Fix inverted logic in comment 2023-05-13 22:55:17 +02:00
Simon Bruder 9871b11bfe 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-13 22:20:43 +02:00
Simon Bruder f330960b78 u02/tests: Fix edge case for invalid points 2023-05-13 22:08:02 +02:00
Simon Bruder 2657f6c2a4 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-13 22:08:02 +02:00
Simon Bruder 1dcdf09b2a 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-13 22:08:00 +02:00
Simon Bruder e16df7e565 u02/tests: Add average point test for star 2023-05-10 22:01:15 +02:00
Simon Bruder 7a0852b4a3 u02: Implement preview for star
It is fixed to a star with 5 spikes, but better than a circle.
2023-05-10 21:09:18 +02:00
Simon Bruder 0d327e7362 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-10 21:09:18 +02:00
Simon Bruder 1595ec7ea7 u02: Implement star tool 2023-05-10 21:09:18 +02:00
4 changed files with 12 additions and 38 deletions

View file

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

View file

@ -22,15 +22,11 @@ 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:
// 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);
star_tool(canvas_buffer &canvas);
void draw(int x0, int y0, int x1, int y1);
@ -41,6 +37,6 @@ public:
void set_radius_factor(int radius_factor);
private:
int spikes;
int spikes = 5;
float radius_factor = 1.0 / 3.0;
};

View file

@ -53,10 +53,9 @@ 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.
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.
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.
### 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, int spikes) : tool_base(canvas) {
set_spikes(spikes);
star_tool::star_tool(canvas_buffer &canvas) : tool_base(canvas) {
shape = TS_STAR;
}
void star_tool::draw(int x0, int y0, int x1, int y1) {
@ -67,25 +67,7 @@ void star_tool::set_text(std::stringstream &stream) {
stream << "Tool: Star (" << 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_spikes(int spikes) { this->spikes = spikes; }
void star_tool::set_radius_factor(int radius_factor) {
this->radius_factor = radius_factor;