Skip to content

Commit

Permalink
Added bounding box to jcv_diagram_generate() function (#8)
Browse files Browse the repository at this point in the history
* CI tests

* Added bounding box to jcv_diagram_generate()
Input points are now culled against the bounding box
Added .csv support to test program

* Added missing file

* Windown compile fixes

* Added missing include for linux
  • Loading branch information
JCash authored Apr 20, 2017
1 parent 28f6f91 commit 87c0ab2
Show file tree
Hide file tree
Showing 12 changed files with 416 additions and 173 deletions.
4 changes: 4 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ language: cpp
compiler:
- clang

os:
- linux
- osx

script:
- ./compile_clang.sh
- cd test
Expand Down
19 changes: 13 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@

|Branch |Linux |Windows |
|------------|---------|---------|
|Branch |OSX/Linux |Windows |
|------------|----------|----------|
|master | [![Build Status](https://travis-ci.org/JCash/voronoi.svg?branch=master)](https://travis-ci.org/JCash/voronoi?branch=master) | [![Build status](https://ci.appveyor.com/api/projects/status/fay5br9xdd92nlkv/branch/master?svg=true)](https://ci.appveyor.com/project/JCash/voronoi/branch/master) |
|dev | [![Build Status](https://travis-ci.org/JCash/voronoi.svg?branch=dev)](https://travis-ci.org/JCash/voronoi?branch=dev) | [![Build status](https://ci.appveyor.com/api/projects/status/fay5br9xdd92nlkv/branch/dev?svg=true)](https://ci.appveyor.com/project/JCash/voronoi/branch/dev) |


# jc_voronoi
A fast C implementation for creating 2D Voronoi diagrams from a point set
A fast C/C++ header only implementation for creating 2D Voronoi diagrams from a point set

Uses [Fortune's sweep algorithm.](https://en.wikipedia.org/wiki/Fortune%27s_algorithm)

Expand Down Expand Up @@ -55,14 +55,21 @@ Usage
The api is very small

```C
void jcv_diagram_generate( int num_points, const jcv_point* points, int img_width, int img_height, jcv_diagram* diagram );
void jcv_diagram_generate_useralloc( int num_points, const jcv_point* points, int img_width, int img_height, void* userallocctx, FJCVAllocFn allocfn, FJCVFreeFn freefn, jcv_diagram* diagram );
void jcv_diagram_generate( int num_points, const jcv_point* points, const jcv_rect* rect, jcv_diagram* diagram );
void jcv_diagram_generate_useralloc( int num_points, const jcv_point* points, const jcv_rect* rect, void* userallocctx, FJCVAllocFn allocfn, FJCVFreeFn freefn, jcv_diagram* diagram );
void jcv_diagram_free( jcv_diagram* diagram );

const jcv_site* jcv_diagram_get_sites( const jcv_diagram* diagram );
const jcv_edge* jcv_diagram_get_edges( const jcv_diagram* diagram );
```
The input points are pruned if
* There are duplicates points
* The input points are outside of the bounding box
The input bounding box is optional
Example implementation (see main.c for actual code)
```C
Expand All @@ -80,7 +87,7 @@ void generate_and_draw(int numpoints, const jcv_point* points, int imagewidth, i
{
jcv_diagram diagram;
memset(&diagram, 0, sizeof(jcv_diagram));
jcv_diagram_generate(count, points, imagewidth, imageheight, &diagram );
jcv_diagram_generate(count, points, 0, &diagram );
draw_edges(diagram);
draw_cells(diagram);
Expand Down
2 changes: 1 addition & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ build_script:
- cd ..

test_script:
- dir
- build\main.exe -?
- build\main.exe -w 512 -h 512 -n 100 -o citest.png
- build\test.exe
3 changes: 2 additions & 1 deletion compile_cl.bat
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ if NOT DEFINED VCINSTALLDIR (

mkdir build

cl.exe /O2 /D_CRT_SECURE_NO_WARNINGS /W4 /Isrc src/main.c /link /out:.\build\main.exe
cl.exe /nologo /O2 /D_CRT_SECURE_NO_WARNINGS /c -Fobuild/stb_wrapper.obj src/stb_wrapper.c
cl.exe /nologo /O2 /D_CRT_SECURE_NO_WARNINGS /W4 build/stb_wrapper.obj src\main.c /link /out:build/main.exe

del *.obj

4 changes: 3 additions & 1 deletion compile_clang.sh
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
mkdir -p build
clang -o build/main -g -O0 -m64 -std=c99 -Wall -Weverything -Wno-float-equal -pedantic -lm src/main.c

clang -c src/stb_wrapper.c -o build/stb_wrapper.o
clang -o build/main -g -O2 -m64 -std=c99 -Wall -Weverything -Wno-float-equal -pedantic -lm build/stb_wrapper.o src/main.c
Loading

0 comments on commit 87c0ab2

Please sign in to comment.