add cli main

This commit is contained in:
Fabien Freling 2022-02-11 20:06:26 +01:00
parent 09ddfccadc
commit 2e24f0314b
4 changed files with 48 additions and 0 deletions

1
.gitignore vendored
View file

@ -1,2 +1,3 @@
*.zip *.zip
packing packing
build.sh

View file

@ -9,3 +9,24 @@ The subject is available here: [Test Algo](./test_algo.pdf)
### Question 1 ### Question 1
### Question 2 ### Question 2
### Question 3 ### Question 3
## PNG support
I chose to support PNG files through the stb files:
[github.com/nothings/stb](https://github.com/nothings/stb).
I could have implemented basic image support with the PNM format but I think it
is nicer to support common image formats with a simple library.
stb also implements a 2D rectangle packer:
[stb_rect_pack.h](https://github.com/nothings/stb/blob/master/stb_rect_pack.h)
I added this file in the project in order to compare my implementation to
another one.
## 3rd party libraries
I use 2 external libraries for better visualization:
- stb files (for PNG)
- raylib (for GUI)
I don't rely on them for the algorithm implementation and the core of the
exercise doesn't rely on external libraries.

View file

@ -9,6 +9,8 @@ run: build
{{exe}} {{exe}}
generate-build: generate-build:
git clean -xf src/
rm --force {{exe}}
tup generate {{build_sh}} tup generate {{build_sh}}
debug: build debug: build

24
src/main_cli.cpp Normal file
View file

@ -0,0 +1,24 @@
#include <filesystem>
#include <iostream>
namespace fs = std::filesystem;
int main(int argc, const char* argv[]) {
// We take an image path and a list of points (grouped by 4 to define
// bounding boxes).
if (argc < 6 or (argc - 2) % 4 != 0) {
std::cerr
<< "Usage: " << argv[0] << " path/to/image"
<< " x1 y1 x2 y2 [...]\n"
<< "x/y points must be grouped by 4 to define bounding boxes\n";
return 1;
}
const fs::path input(argv[1]);
if (!fs::exists(input)) {
std::cerr << "Input file " << input << " does not exist.\n";
return 1;
}
return 0;
}