From 7fbcadc73f8fa3978468d91549f8ca4cad002097 Mon Sep 17 00:00:00 2001 From: mika <mika@mika-ideacentre-Y710-Cube-15ISH> Date: Wed, 5 Dec 2018 02:42:01 +0100 Subject: [PATCH] dwyer uses svg + code cleanup --- src/dwyer.c | 18 +++++++++++++++--- src/helper.c | 8 +++++--- src/helper.h | 19 +++++++++++++------ src/main.c | 13 ++++--------- src/main.h | 16 ++++++++++++++++ src/voronoi.c | 13 ++++++------- src/voronoi.h | 3 ++- 7 files changed, 61 insertions(+), 29 deletions(-) create mode 100644 src/main.h diff --git a/src/dwyer.c b/src/dwyer.c index 9cdc0e4..17d244d 100644 --- a/src/dwyer.c +++ b/src/dwyer.c @@ -55,9 +55,9 @@ typedef int EDGE_PTR; typedef unsigned short VERTEX_PTR; -struct VEC2 { +/*struct VEC2 { double x,y; -}; +};*/ struct VERTEX { struct VEC2 v; @@ -533,8 +533,11 @@ else { /* Quicksort */ /* plots a site on your favorite device. */ plot_site(v) VERTEX_PTR v; { +#ifdef POSTSCRIPT + printf("p%d drawsite\n", v); +#endif #ifdef OUTPUTFILE - fprintf(out, "p%d drawsite\n", v); + svgDrawSite(va[v].v); #endif } @@ -545,6 +548,9 @@ plot_dt_edge(e) #ifdef POSTSCRIPT printf("p%d p%d drawseg\n", orig(e), dest(e)); #endif +#ifdef OUTPUTFILE + svgDrawLine(va[orig(e)].v, va[dest(e)].v); +#endif } BOOLEAN forward(e, base) @@ -727,6 +733,9 @@ struct VEC2 v1, v2; #ifdef POSTSCRIPT printf("%f %f %f %f drawline\n", v1.x, v1.y, v2.x, v2.y); #endif +#ifdef OUTPUTFILE + svgDrawLine(v1, v2); +#endif } plot_infinite_vd_edge(e) @@ -1114,6 +1123,9 @@ EDGE_PTR e; #ifdef POSTSCRIPT printf("p%d p%d drawseg\n", orig(e), dest(e)); #endif +#ifdef OUTPUTFILE + svgDrawLine(va[orig(e)].v, va[dest(e)].v); +#endif } dumpedge(e) EDGE_PTR e; diff --git a/src/helper.c b/src/helper.c index cfbf2ad..86e2cc1 100644 --- a/src/helper.c +++ b/src/helper.c @@ -7,9 +7,11 @@ #include "helper.h" -void svgDrawLine(edge l, char *color) { + + +void svgDrawLine(vertex a, vertex b) { #ifdef OUTPUTFILE - fprintf(out, "<line x1=\"%f\" y1=\"%f\" x2=\"%f\" y2=\"%f\" style=\"stroke:rgb(%s);stroke-width:1\" />\n", l.a.x*W, l.a.y*H, l.b.x*W, l.b.y*H, color); + fprintf(out, "<line x1=\"%f\" y1=\"%f\" x2=\"%f\" y2=\"%f\" style=\"stroke:purple;stroke-width:1\" />\n", a.x*W, a.y*H, b.x*W, b.y*H); #endif } @@ -27,7 +29,7 @@ void svgDrawTriangle(vertex a, vertex b, vertex c) { void svgDrawSite(vertex v) { #ifdef OUTPUTFILE - fprintf(out, "<circle cx=\"%f\" cy=\"%f\" r=\"%f\" stroke=\"black\" stroke-width=\"1\" fill=\"black\" />", v.x*W, v.y*H, 2); + fprintf(out, "<circle cx=\"%f\" cy=\"%f\" r=\"%f\" stroke=\"black\" stroke-width=\"1\" fill=\"black\" />", v.x*W, v.y*H, 2.0); #endif } diff --git a/src/helper.h b/src/helper.h index 581f2f9..18a9046 100644 --- a/src/helper.h +++ b/src/helper.h @@ -8,13 +8,19 @@ #ifndef HELPER_H_ #define HELPER_H_ +#define OUTPUTFILE "output.html" + #include <stdio.h> -#define W 1000 -#define H 1000 -#define M 255 +#define W 2000 +#define H 2000 -typedef struct { +#ifdef OUTPUTFILE +FILE *out; +#endif + + +typedef struct VEC2{ double x, y; } vertex; @@ -22,7 +28,7 @@ typedef struct { vertex a; vertex b; vertex c; -}; +} blub; typedef struct { vertex center; @@ -36,8 +42,9 @@ typedef struct { void writeSvgStart (); void writeSvgEnd (); -void svgDrawLine(edge, char *); +void svgDrawLine(vertex, vertex); void svgDrawCircle(circle); void svgDrawTriangle(vertex, vertex, vertex); +void svgDrawSite(vertex); #endif /* HELPER_H_ */ diff --git a/src/main.c b/src/main.c index 28982b3..324d289 100644 --- a/src/main.c +++ b/src/main.c @@ -5,21 +5,16 @@ * Author: Mika */ -#define OUTPUTFILE "output.html" +#include "main.h" -#include "delaunay.h" -#include "voronoi.h" -#ifdef OUTPUTFILE -FILE *out; -#endif int main(int argc, char *argv[]) { //input: 1. function 0=cws_delaunay 2. # of points, 3. # of executions //create_image(); //write_ppm ( "sine.ppm" ); - int numberOfPoints = 10000; - int function = 0; + int numberOfPoints = 20; + int function = 2; int executions = 1; if(argc > 0) { //printf("%s\n", argv[0]); @@ -33,7 +28,7 @@ int main(int argc, char *argv[]) { vertex points[numberOfPoints]; generatePoints(points, numberOfPoints); - printf("%u\n", sizeof(points)); + printf("%lu\n", sizeof(points)); fflush(stdout); //drawPoints(points, numberOfPoints); diff --git a/src/main.h b/src/main.h new file mode 100644 index 0000000..f05d20a --- /dev/null +++ b/src/main.h @@ -0,0 +1,16 @@ +/* + * main.h + * + * Created on: Dec 5, 2018 + * Author: mika + */ + +#ifndef MAIN_H_ +#define MAIN_H_ + +#include "delaunay.h" +#include "voronoi.h" +#include "helper.h" + + +#endif /* MAIN_H_ */ diff --git a/src/voronoi.c b/src/voronoi.c index 8d867b5..338bf89 100644 --- a/src/voronoi.c +++ b/src/voronoi.c @@ -13,11 +13,10 @@ circle center(vertexCircle vc) { circle c = circleFrom3Points(vc.a, vc.b, vc.c); return c; } -int reportEdge(edge l) { +int reportEdge(vertex a, vertex b) { //svgDrawCircle(a,out); //svgDrawCircle(b,out); - char *color = "0,0,255"; - svgDrawLine(l, color); + svgDrawLine(a, b); return 0; } @@ -91,12 +90,12 @@ void voronoiCws(vertex* S, int size) { } else { if(!outOfBorder(currentV)) { #ifdef OUTPUTFILE - reportEdge((edge){currentV, lastV}, out); + reportEdge(currentV, lastV); #endif } if(k == j0) { #ifdef OUTPUTFILE - reportEdge((edge){currentV, firstV}); + reportEdge(currentV, firstV); #endif } } @@ -110,14 +109,14 @@ void voronoiCws(vertex* S, int size) { } else { if(!outOfBorder(lastV)) { #ifdef OUTPUTFILE - reportEdge((edge){currentV, lastV}, out); + reportEdge(currentV, lastV); #endif } } currentV = findBorderVertex(S[i], S[k]); if(k == j0) { if(!outOfBorder(firstV)) { - reportEdge((edge){currentV, firstV}); + reportEdge(currentV, firstV); } } } diff --git a/src/voronoi.h b/src/voronoi.h index 4723923..5f8a6a1 100644 --- a/src/voronoi.h +++ b/src/voronoi.h @@ -9,6 +9,7 @@ #define SRC_VORONOI_H_ #include "delaunay.h" +#include "helper.h" /** @@ -50,7 +51,7 @@ edgeCircle clockwiseNextVoronoiEdge(edgeCircle e); */ edgeCircle nextVoronoiEdgeOnBoudary(edgeCircle e); -int reportEdge(edge l); +int reportEdge(vertex, vertex); void voronoiCws(vertex* S, int size); -- GitLab