Skip to content
Snippets Groups Projects
Commit e12f96a7 authored by mika's avatar mika
Browse files

input sites can now have any size, without it affecting the output

parent e7a51b82
No related branches found
No related tags found
No related merge requests found
...@@ -292,8 +292,8 @@ void delaunayCws(vertex* S, int size) { ...@@ -292,8 +292,8 @@ void delaunayCws(vertex* S, int size) {
//https://stackoverflow.com/questions/29762048/c-structure-to-string //https://stackoverflow.com/questions/29762048/c-structure-to-string
char* vertexToString(vertex v) { char* vertexToString(vertex v) {
int len = 0; 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); 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; return str;
} }
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
#ifndef SRC_DWYER_H_ #ifndef SRC_DWYER_H_
#define SRC_DWYER_H_ #define SRC_DWYER_H_
#include "delaunay.h" #include "helper.h"
dwyer(char, vertex*, int); dwyer(char, vertex*, int);
......
...@@ -11,31 +11,31 @@ ...@@ -11,31 +11,31 @@
void svgDrawLine(vertex a, vertex b) { void svgDrawLine(vertex a, vertex b) {
#ifdef OUTPUTFILE #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 #endif
} }
void svgDrawCircle(circle c) { void svgDrawCircle(circle c) {
#ifdef OUTPUTFILE #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 #endif
} }
void svgDrawTriangle(vertex a, vertex b, vertex c) { void svgDrawTriangle(vertex a, vertex b, vertex c) {
#ifdef OUTPUTFILE #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 #endif
} }
void svgDrawSite(vertex v) { void svgDrawSite(vertex v) {
#ifdef OUTPUTFILE #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 #endif
} }
void writeSvgStart () { void writeSvgStart () {
#ifdef OUTPUTFILE #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 #endif
} }
...@@ -51,6 +51,7 @@ void drawSites(vertex *v, int n){ ...@@ -51,6 +51,7 @@ void drawSites(vertex *v, int n){
for(int i = 0; i < n; i++) { for(int i = 0; i < n; i++) {
svgDrawSite(v[i]); svgDrawSite(v[i]);
} }
fflush(out);
#endif #endif
} }
...@@ -12,11 +12,15 @@ ...@@ -12,11 +12,15 @@
#include <stdio.h> #include <stdio.h>
#define W 1500
#define H 1500
#ifdef OUTPUTFILE #ifdef OUTPUTFILE
FILE *out; FILE *out;
double viewboxMinX;
double viewboxMinY;
double viewboxMaxX;
double viewboxMaxY;
#define W 1000
#define R .2
#endif #endif
......
...@@ -36,6 +36,10 @@ int main(int argc, char *argv[]) { ...@@ -36,6 +36,10 @@ int main(int argc, char *argv[]) {
size = atoi(argv[3]); size = atoi(argv[3]);
points = malloc(size * sizeof(vertex)); points = malloc(size * sizeof(vertex));
generatePoints(points, size); generatePoints(points, size);
viewboxMinX = 0;
viewboxMinY = 0;
viewboxMaxX = 1;
viewboxMaxY = 1;
} }
executions = atoi(argv[4]); executions = atoi(argv[4]);
...@@ -116,45 +120,28 @@ void readFile(char *file, vertex **v, int *size){ ...@@ -116,45 +120,28 @@ void readFile(char *file, vertex **v, int *size){
*v = malloc(*size * sizeof(vertex)); *v = malloc(*size * sizeof(vertex));
printf("Number of Points: %d\n", *size); printf("Number of Points: %d\n", *size);
int i; int i;
double smallestx = .0; viewboxMinX = (*v)[0].x;
double smallesty = .0; viewboxMinY = (*v)[0].y;
double biggestx = 1.0; viewboxMaxX = (*v)[0].x;
double biggesty = 1.0; viewboxMaxY = (*v)[0].y;
for(i = 0; i < *size && fscanf(f, "%lf, %lf\n", &(*v)[i].x, &(*v)[i].y) == 2; i++) { for(i = 0; i < *size && fscanf(f, "%lf, %lf\n", &(*v)[i].x, &(*v)[i].y) == 2; i++) {
if((*v)[i].x < smallestx) { if(i == 0){
smallestx = (*v)[i].x; viewboxMinX = (*v)[0].x;
} else if ((*v)[i].x > biggestx){ viewboxMinY = (*v)[0].y;
biggestx = (*v)[i].x; viewboxMaxX = (*v)[0].x;
viewboxMaxY = (*v)[0].y;
} }
if((*v)[i].y < smallesty) { if((*v)[i].x < viewboxMinX) {
smallesty = (*v)[i].y; viewboxMinX = (*v)[i].x;
} else if((*v)[i].y > biggesty) { } else if ((*v)[i].x > viewboxMaxX){
biggesty = (*v)[i].y; viewboxMaxX = (*v)[i].x;
} }
} if((*v)[i].y < viewboxMinY) {
if(smallestx < .0 || biggestx > 1.0 || smallesty > .0 || biggesty > 1.0) { viewboxMinY = (*v)[i].y;
biggestx = biggestx - smallestx; } else if((*v)[i].y > viewboxMaxY) {
biggesty = biggesty - smallesty; viewboxMaxY = (*v)[i].y;
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);
} }
printf("%f\n", viewboxMinX);
} }
if(i != *size) { if(i != *size) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment