Compare commits

...

12 Commits

Author SHA1 Message Date
Simon Bruder 194d7bb135 u03/terrain: Make helpers call-by-reference 2023-05-20 12:30:16 +02:00
Simon Bruder ec7fe4ea6d CMake: Enable warnings
Not every exercise has the same levels,
but they now have at least some warnings.
2023-05-20 12:30:16 +02:00
Simon Bruder bd651ee6db u03: Fix warnings by -Wextra
This does not fix one instance of -Wdeprecated-copy, because I don’t
know how to resolve it.

The only other warnings still existing are for the unimplemented tool.
2023-05-20 12:30:16 +02:00
Simon Bruder ca84db9089 u03/cube_system: Actually use specified size 2023-05-20 12:07:53 +02:00
Simon Bruder 58806ba093 u03/tiny_vec: Avoid unsequenced modification and access 2023-05-20 12:01:29 +02:00
Simon Bruder c41d0cb09b u02: Fix warnings by -Wextra
The only warnings still existing are for the unimplemented tool.
2023-05-20 11:55:58 +02:00
Simon Bruder 1bd2d3a2a5 u02: Fix warnings by -Wall
This actually found one logic bug.
2023-05-20 11:39:26 +02:00
Simon Bruder f46e54a156 u01: Remove unused arguments from main 2023-05-20 11:29:04 +02:00
Simon Bruder 34ef7609bf u03/terrain: Fix wrong function call
clang found this and emitted a warning in its default configuration.
2023-05-20 11:21:19 +02:00
Simon Bruder f52bb96d91 flake: Add clang variant 2023-05-20 11:20:43 +02:00
Simon Bruder 7dacccdbd0 flake: Make building variants easier 2023-05-20 11:20:03 +02:00
Simon Bruder c263958d3b CMake: Disable compiler specific extensions 2023-05-20 10:49:52 +02:00
7 changed files with 79 additions and 57 deletions

View File

@ -6,58 +6,67 @@
outputs = { self, nixpkgs, flake-utils }: flake-utils.lib.eachDefaultSystem (system:
let
inherit (nixpkgs) lib;
pkgs = import nixpkgs { inherit system; };
mkNocheck = drv: drv.overrideAttrs (o: {
doCheck = false;
checkInputs = [ ];
});
mkClang = drv: drv.override (o: {
stdenv = pkgs.clangStdenv;
});
in
{
packages = rec {
u01 = pkgs.callPackage
({ stdenv, catch2_3, cmake }: stdenv.mkDerivation {
name = "ecg-u01";
src = ./u01;
nativeBuildInputs = [ cmake ];
checkInputs = [ catch2_3 ];
doCheck = true;
packages = lib.foldAttrs lib.const { }
(lib.flatten (lib.mapAttrsToList
(name: v: {
"${name}" = v;
"${name}-nocheck" = mkNocheck v;
"${name}-clang" = mkClang v;
"${name}-nocheck-clang" = mkClang (mkNocheck v);
})
{ };
rec {
u01 = pkgs.callPackage
({ stdenv, catch2_3, cmake }: stdenv.mkDerivation {
name = "ecg-u01";
u02 = pkgs.callPackage
({ stdenv, catch2_3, cmake, freeglut, libGL, libGLU }: stdenv.mkDerivation {
name = "ecg-u02";
src = ./u01;
src = ./u02;
nativeBuildInputs = [ cmake ];
checkInputs = [ catch2_3 ];
nativeBuildInputs = [ cmake ];
buildInputs = [ freeglut libGL libGLU ];
checkInputs = [ catch2_3 ];
doCheck = true;
})
{ };
doCheck = true;
})
{ };
u02 = pkgs.callPackage
({ stdenv, catch2_3, cmake, freeglut, libGL, libGLU }: stdenv.mkDerivation {
name = "ecg-u02";
u03 = pkgs.callPackage
({ stdenv, cmake, freeglut, libGL, libGLU }: stdenv.mkDerivation {
name = "ecg-u03";
src = ./u02;
src = ./u03;
nativeBuildInputs = [ cmake ];
buildInputs = [ freeglut libGL libGLU ];
checkInputs = [ catch2_3 ];
nativeBuildInputs = [ cmake ];
buildInputs = [ freeglut libGL libGLU ];
})
{ };
doCheck = true;
})
{ };
u01-nocheck = mkNocheck u01;
u02-nocheck = mkNocheck u02;
};
u03 = pkgs.callPackage
({ stdenv, cmake, freeglut, libGL, libGLU }: stdenv.mkDerivation {
name = "ecg-u03";
src = ./u03;
nativeBuildInputs = [ cmake ];
buildInputs = [ freeglut libGL libGLU ];
})
{ };
}));
devShells.default = pkgs.mkShell {
nativeBuildInputs = with pkgs; [ catch2_3 cmake freeglut libGL libGLU reuse ];
nativeBuildInputs = with pkgs; [ catch2_3 clang cmake freeglut libGL libGLU reuse ];
};
});
}

View File

@ -2,6 +2,16 @@
cmake_minimum_required(VERSION 3.20)
project(ecg_tree)
set(CMAKE_CXX_STANDARD 17)
# Disable compiler specific extensions
# On GNU this has the effect of passing -std=c++11 instead of -std=gnu++11
set(CMAKE_CXX_EXTENSIONS no)
# Enable all compiler warnings (and make them errors) on GNU/Clang platforms
if(CMAKE_CXX_COMPILER_ID MATCHES "^(GNU|Clang)$")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wpedantic -Werror")
endif()
add_library(tree node.cpp)
add_executable(main main.cpp)
target_link_libraries(main tree)

View File

@ -3,7 +3,7 @@
#include "node.h"
int main(int argc, char **argv) {
int main() {
node *t = create_complete_tree(2, 4);
std::cout << *t;
delete t;

View File

@ -56,7 +56,7 @@ void star_tool::draw(int x0, int y0, int x1, int y1) {
const std::vector<std::pair<float, float>> points =
star(spikes, radius_factor * r, r, x0, y0, angle);
for (int i = 1; i <= points.size(); i++) {
for (size_t i = 1; i <= points.size(); i++) {
blt->draw(round(points[i - 1].first), round(points[i - 1].second),
round(points[i % points.size()].first),
round(points[i % points.size()].second));

View File

@ -41,24 +41,26 @@ void sweep_line_tool::draw_interval(int b1, int b2, int y) {
void sweep_line_tool::draw() { draw(10, 10, 90, 30, 30, 90); }
void sweep_line_tool::draw(int _x, int _y) { draw(); }
void sweep_line_tool::draw(int, int) { draw(); }
void sweep_line_tool::draw(int x0, int y0, int x1, int y1, int x2, int y2) {
// Terminology:
//
// (x0, y0)
// +
// | \
// | \ m_1
// |first\
// | pass \
// m_shared |---------+ (x1, y1)
// |second /
// |pass /
// | / m_2
// | /
// +
// (x2, y2)
/*
* Terminology:
*
* (x0, y0)
* +
* | \
* | \ m_1
* |first\
* | pass \
* m_shared |---------+ (x1, y1)
* |second /
* |pass /
* | / m_2
* | /
* +
* (x2, y2)
*/
// Sort triangle points (in place) so that y0 < y1 < y2
sort_triangle_points(x0, y0, x1, y1, x2, y2);

View File

@ -128,6 +128,7 @@ TEST_CASE("Bresenham/DDA line tool (prop: for every row/column, only one pixel "
const int tool_idx = GENERATE(0, 1);
switch (tool_idx) {
case 0:
default: // required to make static compiler warnings happy
tool = tool_bresenham;
break;
case 1:
@ -192,7 +193,6 @@ TEST_CASE("Bresenham/DDA line tool (prop: for every row/column, only one pixel "
TEST_CASE("Fill (recursive and non recursive) test shape") {
canvas_buffer *canvas = new canvas_buffer(100, 100);
bresenham_line_tool *tool_line = new bresenham_line_tool(*canvas);
recursive_fill_tool *tool_fill_recursive = new recursive_fill_tool(*canvas);
non_recursive_fill_tool *tool_fill_non_recursive =
new non_recursive_fill_tool(*canvas);
@ -201,6 +201,7 @@ TEST_CASE("Fill (recursive and non recursive) test shape") {
const int tool_fill_idx = GENERATE(0, 1);
switch (tool_fill_idx) {
case 0:
default: // required to make static compiler warnings happy
tool_fill = tool_fill_recursive;
break;
case 1:

View File

@ -427,7 +427,7 @@ void BMP_GetPixelRGB( BMP* bmp, UINT x, UINT y, UCHAR* r, UCHAR* g, UCHAR* b )
UINT bytes_per_row;
UCHAR bytes_per_pixel;
if ( bmp == NULL || x < 0 || x >= bmp->Header.Width || y < 0 || y >= bmp->Header.Height )
if ( bmp == NULL || x >= bmp->Header.Width || y >= bmp->Header.Height )
{
BMP_LAST_ERROR_CODE = BMP_INVALID_ARGUMENT;
}
@ -467,7 +467,7 @@ void BMP_SetPixelRGB( BMP* bmp, UINT x, UINT y, UCHAR r, UCHAR g, UCHAR b )
UINT bytes_per_row;
UCHAR bytes_per_pixel;
if ( bmp == NULL || x < 0 || x >= bmp->Header.Width || y < 0 || y >= bmp->Header.Height )
if ( bmp == NULL || x >= bmp->Header.Width || y >= bmp->Header.Height )
{
BMP_LAST_ERROR_CODE = BMP_INVALID_ARGUMENT;
}
@ -505,7 +505,7 @@ void BMP_GetPixelIndex( BMP* bmp, UINT x, UINT y, UCHAR* val )
UCHAR* pixel;
UINT bytes_per_row;
if ( bmp == NULL || x < 0 || x >= bmp->Header.Width || y < 0 || y >= bmp->Header.Height )
if ( bmp == NULL || x >= bmp->Header.Width || y >= bmp->Header.Height )
{
BMP_LAST_ERROR_CODE = BMP_INVALID_ARGUMENT;
}
@ -539,7 +539,7 @@ void BMP_SetPixelIndex( BMP* bmp, UINT x, UINT y, UCHAR val )
UCHAR* pixel;
UINT bytes_per_row;
if ( bmp == NULL || x < 0 || x >= bmp->Header.Width || y < 0 || y >= bmp->Header.Height )
if ( bmp == NULL || x >= bmp->Header.Width || y >= bmp->Header.Height )
{
BMP_LAST_ERROR_CODE = BMP_INVALID_ARGUMENT;
}