Compare commits

..

No commits in common. "194d7bb13509630a65f155e3ec12ae97a290f96c" and "f068939e3557d0cc808b954a493a1993eb4e95f1" have entirely different histories.

7 changed files with 57 additions and 79 deletions

View file

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

View file

@ -2,16 +2,6 @@
cmake_minimum_required(VERSION 3.20) cmake_minimum_required(VERSION 3.20)
project(ecg_tree) 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_library(tree node.cpp)
add_executable(main main.cpp) add_executable(main main.cpp)
target_link_libraries(main tree) target_link_libraries(main tree)

View file

@ -3,7 +3,7 @@
#include "node.h" #include "node.h"
int main() { int main(int argc, char **argv) {
node *t = create_complete_tree(2, 4); node *t = create_complete_tree(2, 4);
std::cout << *t; std::cout << *t;
delete 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 = const std::vector<std::pair<float, float>> points =
star(spikes, radius_factor * r, r, x0, y0, angle); star(spikes, radius_factor * r, r, x0, y0, angle);
for (size_t i = 1; i <= points.size(); i++) { for (int i = 1; i <= points.size(); i++) {
blt->draw(round(points[i - 1].first), round(points[i - 1].second), blt->draw(round(points[i - 1].first), round(points[i - 1].second),
round(points[i % points.size()].first), round(points[i % points.size()].first),
round(points[i % points.size()].second)); round(points[i % points.size()].second));

View file

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

View file

@ -128,7 +128,6 @@ TEST_CASE("Bresenham/DDA line tool (prop: for every row/column, only one pixel "
const int tool_idx = GENERATE(0, 1); const int tool_idx = GENERATE(0, 1);
switch (tool_idx) { switch (tool_idx) {
case 0: case 0:
default: // required to make static compiler warnings happy
tool = tool_bresenham; tool = tool_bresenham;
break; break;
case 1: case 1:
@ -193,6 +192,7 @@ TEST_CASE("Bresenham/DDA line tool (prop: for every row/column, only one pixel "
TEST_CASE("Fill (recursive and non recursive) test shape") { TEST_CASE("Fill (recursive and non recursive) test shape") {
canvas_buffer *canvas = new canvas_buffer(100, 100); 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); recursive_fill_tool *tool_fill_recursive = new recursive_fill_tool(*canvas);
non_recursive_fill_tool *tool_fill_non_recursive = non_recursive_fill_tool *tool_fill_non_recursive =
new non_recursive_fill_tool(*canvas); new non_recursive_fill_tool(*canvas);
@ -201,7 +201,6 @@ TEST_CASE("Fill (recursive and non recursive) test shape") {
const int tool_fill_idx = GENERATE(0, 1); const int tool_fill_idx = GENERATE(0, 1);
switch (tool_fill_idx) { switch (tool_fill_idx) {
case 0: case 0:
default: // required to make static compiler warnings happy
tool_fill = tool_fill_recursive; tool_fill = tool_fill_recursive;
break; break;
case 1: 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; UINT bytes_per_row;
UCHAR bytes_per_pixel; UCHAR bytes_per_pixel;
if ( bmp == NULL || x >= bmp->Header.Width || y >= bmp->Header.Height ) if ( bmp == NULL || x < 0 || x >= bmp->Header.Width || y < 0 || y >= bmp->Header.Height )
{ {
BMP_LAST_ERROR_CODE = BMP_INVALID_ARGUMENT; 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; UINT bytes_per_row;
UCHAR bytes_per_pixel; UCHAR bytes_per_pixel;
if ( bmp == NULL || x >= bmp->Header.Width || y >= bmp->Header.Height ) if ( bmp == NULL || x < 0 || x >= bmp->Header.Width || y < 0 || y >= bmp->Header.Height )
{ {
BMP_LAST_ERROR_CODE = BMP_INVALID_ARGUMENT; BMP_LAST_ERROR_CODE = BMP_INVALID_ARGUMENT;
} }
@ -505,7 +505,7 @@ void BMP_GetPixelIndex( BMP* bmp, UINT x, UINT y, UCHAR* val )
UCHAR* pixel; UCHAR* pixel;
UINT bytes_per_row; UINT bytes_per_row;
if ( bmp == NULL || x >= bmp->Header.Width || y >= bmp->Header.Height ) if ( bmp == NULL || x < 0 || x >= bmp->Header.Width || y < 0 || y >= bmp->Header.Height )
{ {
BMP_LAST_ERROR_CODE = BMP_INVALID_ARGUMENT; BMP_LAST_ERROR_CODE = BMP_INVALID_ARGUMENT;
} }
@ -539,7 +539,7 @@ void BMP_SetPixelIndex( BMP* bmp, UINT x, UINT y, UCHAR val )
UCHAR* pixel; UCHAR* pixel;
UINT bytes_per_row; UINT bytes_per_row;
if ( bmp == NULL || x >= bmp->Header.Width || y >= bmp->Header.Height ) if ( bmp == NULL || x < 0 || x >= bmp->Header.Width || y < 0 || y >= bmp->Header.Height )
{ {
BMP_LAST_ERROR_CODE = BMP_INVALID_ARGUMENT; BMP_LAST_ERROR_CODE = BMP_INVALID_ARGUMENT;
} }