diff --git a/src/delaunay.c b/src/delaunay.c index d66adb16971be4e212848d9268b1041513506d95..939e2f8e12f45119ea37752d74445bfabcc85d97 100644 --- a/src/delaunay.c +++ b/src/delaunay.c @@ -292,8 +292,8 @@ void delaunayCws(vertex* S, int size) { //https://stackoverflow.com/questions/29762048/c-structure-to-string char* vertexToString(vertex v) { int len = 0; - len = snprintf(NULL, len, "%f,%f", v.x*W, v.y*H); + len = snprintf(NULL, len, "%f,%f", v.x, v.y); char* str = malloc(sizeof(char) * len + 1); - snprintf(str, sizeof(str), "%f,%f", v.x*W, v.y*H); + snprintf(str, sizeof(str), "%f,%f", v.x, v.y); return str; } diff --git a/src/dwyer.h b/src/dwyer.h index 20d27caa2e2cc9875e4b2b0029b72d6a50846ebd..0758667ce231477a236c930800cd4486ca4b669d 100644 --- a/src/dwyer.h +++ b/src/dwyer.h @@ -8,7 +8,7 @@ #ifndef SRC_DWYER_H_ #define SRC_DWYER_H_ -#include "delaunay.h" +#include "helper.h" dwyer(char, vertex*, int); diff --git a/src/helper.c b/src/helper.c index 60470b17b9a6795bd37fefb2a6dd79630e5aa12b..e596ae8911cf9b26bb418f99230fe64d7d514288 100644 --- a/src/helper.c +++ b/src/helper.c @@ -11,31 +11,31 @@ void svgDrawLine(vertex a, vertex b) { #ifdef OUTPUTFILE - fprintf(out, "<line x1=\"%f\" y1=\"%f\" x2=\"%f\" y2=\"%f\" style=\"stroke:red;stroke-width:1\" />\n", a.x*W, a.y*H, b.x*W, b.y*H); + fprintf(out, "<line vector-effect=\"non-scaling-stroke\" x1=\"%f\" y1=\"%f\" x2=\"%f\" y2=\"%f\" style=\"stroke:red;stroke-width:1\" />\n", a.x, a.y, b.x, b.y); #endif } void svgDrawCircle(circle c) { #ifdef OUTPUTFILE - fprintf(out, "<circle cx=\"%f\" cy=\"%f\" r=\"%f\" stroke=\"green\" stroke-width=\"1\" fill=\"none\" />", c.center.x*W, c.center.y*H, c.radius*W); + fprintf(out, "<circle vector-effect=\"non-scaling-stroke\" cx=\"%f\" cy=\"%f\" r=\"%f\" stroke=\"green\" stroke-width=\"1\" fill=\"none\" />\n", c.center.x, c.center.y, c.radius); #endif } void svgDrawTriangle(vertex a, vertex b, vertex c) { #ifdef OUTPUTFILE - fprintf(out, "<polygon points=\"%f,%f %f,%f %f,%f\" style=\"fill:none;stroke:purple;stroke-width:1\" />", a.x*W, a.y*H, b.x*W, b.y*H, c.x*W, c.y*H); + fprintf(out, "<polygon vector-effect=\"non-scaling-stroke\" points=\"%f,%f %f,%f %f,%f\" style=\"fill:none;stroke:purple;stroke-width:1\" />\n", a.x, a.y, b.x, b.y, c.x, c.y); #endif } void svgDrawSite(vertex v) { #ifdef OUTPUTFILE - fprintf(out, "<circle cx=\"%lf\" cy=\"%lf\" r=\"%lf\" stroke=\"black\" stroke-width=\"1\" fill=\"black\" />", v.x*W, v.y*H, 2.0); + fprintf(out, "<circle vector-effect=\"non-scaling-stroke\" cx=\"%lf\" cy=\"%lf\" r=\"%lf%%\" stroke=\"black\" stroke-width=\"1\" fill=\"black\" />\n", v.x, v.y, R); #endif } void writeSvgStart () { #ifdef OUTPUTFILE - fprintf (out, "<!DOCTYPE html>\n<html>\n<body>\n<svg width=\"%d\" height=\"%d\">\n", W, H); + fprintf (out, "<!DOCTYPE html>\n<html>\n<body>\n<svg width=\"%d\" viewBox=\"%f %f %f %f\">\n", W, viewboxMinX, viewboxMinY, viewboxMaxX-viewboxMinX, viewboxMaxY-viewboxMinY); #endif } @@ -51,6 +51,7 @@ void drawSites(vertex *v, int n){ for(int i = 0; i < n; i++) { svgDrawSite(v[i]); } + fflush(out); #endif } diff --git a/src/helper.h b/src/helper.h index 867de7226a59760d520e9534ffa6c99ff7b8a0a6..85135460ee8dbed7bf76b8439bf253707ac64d42 100644 --- a/src/helper.h +++ b/src/helper.h @@ -12,11 +12,15 @@ #include <stdio.h> -#define W 1500 -#define H 1500 #ifdef OUTPUTFILE FILE *out; +double viewboxMinX; +double viewboxMinY; +double viewboxMaxX; +double viewboxMaxY; +#define W 1000 +#define R .2 #endif diff --git a/src/main.c b/src/main.c index 89934b3c81963ad231447faf75a973bf1613c118..672244153fed30e6a7e117f1921487e3ad66d7cc 100644 --- a/src/main.c +++ b/src/main.c @@ -36,6 +36,10 @@ int main(int argc, char *argv[]) { size = atoi(argv[3]); points = malloc(size * sizeof(vertex)); generatePoints(points, size); + viewboxMinX = 0; + viewboxMinY = 0; + viewboxMaxX = 1; + viewboxMaxY = 1; } executions = atoi(argv[4]); @@ -116,45 +120,28 @@ void readFile(char *file, vertex **v, int *size){ *v = malloc(*size * sizeof(vertex)); printf("Number of Points: %d\n", *size); int i; - double smallestx = .0; - double smallesty = .0; - double biggestx = 1.0; - double biggesty = 1.0; + viewboxMinX = (*v)[0].x; + viewboxMinY = (*v)[0].y; + viewboxMaxX = (*v)[0].x; + viewboxMaxY = (*v)[0].y; for(i = 0; i < *size && fscanf(f, "%lf, %lf\n", &(*v)[i].x, &(*v)[i].y) == 2; i++) { - if((*v)[i].x < smallestx) { - smallestx = (*v)[i].x; - } else if ((*v)[i].x > biggestx){ - biggestx = (*v)[i].x; + if(i == 0){ + viewboxMinX = (*v)[0].x; + viewboxMinY = (*v)[0].y; + viewboxMaxX = (*v)[0].x; + viewboxMaxY = (*v)[0].y; } - if((*v)[i].y < smallesty) { - smallesty = (*v)[i].y; - } else if((*v)[i].y > biggesty) { - biggesty = (*v)[i].y; + if((*v)[i].x < viewboxMinX) { + viewboxMinX = (*v)[i].x; + } else if ((*v)[i].x > viewboxMaxX){ + viewboxMaxX = (*v)[i].x; } - } - if(smallestx < .0 || biggestx > 1.0 || smallesty > .0 || biggesty > 1.0) { - biggestx = biggestx - smallestx; - biggesty = biggesty - smallesty; - double biggest; - if(biggestx >= biggesty) { - biggest = biggestx; - } else { - biggest = biggesty; - } - for(int j = 0; j < *size; j++){ - if(smallestx < .0) { - (*v)[j].x = (*v)[j].x - smallestx; - } - if(smallesty < .0) { - (*v)[j].y = (*v)[j].y - smallesty; - } - if(biggest > 1.0){ - (*v)[j].x /= biggest; - (*v)[j].y /= biggest; - } - printf("%lf[^, \t\n\f\r\v]%lf\n", (*v)[j].x, (*v)[j].y); + if((*v)[i].y < viewboxMinY) { + viewboxMinY = (*v)[i].y; + } else if((*v)[i].y > viewboxMaxY) { + viewboxMaxY = (*v)[i].y; } - + printf("%f\n", viewboxMinX); } if(i != *size) {