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
Branches
No related tags found
No related merge requests found
......@@ -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;
}
......@@ -8,7 +8,7 @@
#ifndef SRC_DWYER_H_
#define SRC_DWYER_H_
#include "delaunay.h"
#include "helper.h"
dwyer(char, vertex*, int);
......
......@@ -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
}
......@@ -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
......
......@@ -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) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment