add cli main
This commit is contained in:
parent
09ddfccadc
commit
2e24f0314b
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -1,2 +1,3 @@
|
|||
*.zip
|
||||
packing
|
||||
build.sh
|
||||
|
|
21
README.md
21
README.md
|
@ -9,3 +9,24 @@ The subject is available here: [Test Algo](./test_algo.pdf)
|
|||
### Question 1
|
||||
### Question 2
|
||||
### 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.
|
||||
|
|
2
justfile
2
justfile
|
@ -9,6 +9,8 @@ run: build
|
|||
{{exe}}
|
||||
|
||||
generate-build:
|
||||
git clean -xf src/
|
||||
rm --force {{exe}}
|
||||
tup generate {{build_sh}}
|
||||
|
||||
debug: build
|
||||
|
|
24
src/main_cli.cpp
Normal file
24
src/main_cli.cpp
Normal 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;
|
||||
}
|
Loading…
Reference in a new issue